import type { Metadata } from 'next'
import type { BackendSiteAgreement } from '@/lib/backend'
import { serverFetchJson } from '@/lib/server-api'

export const metadata: Metadata = { title: '注册协议' }

const fallbackAgreement: BackendSiteAgreement = {
  id: 'registration-terms',
  title: '注册协议',
  summary: '账号注册、资料真实性、登录凭证和基础服务开通规则。',
  content: [
    '用户注册或登录平台时，应提交真实、准确、完整的手机号、微信号、姓名、机构、职务等必要资料。',
    '用户应妥善保管登录凭证，不得将账号转让、出租、出借给他人使用。',
    '平台可基于账号识别、服务开通、订单履约、活动核销、专家预约和安全审计等目的处理用户资料。',
    '用户不得利用平台发布违法违规内容、冒用他人身份、干扰平台运行或实施其他损害平台及第三方权益的行为。',
    '平台可根据法律法规、业务安全和服务管理需要，对注册协议进行更新，并在页面展示最新版本。',
  ].join('\n'),
  status: 'published',
  updatedBy: '',
  createdAt: '',
  updatedAt: '',
}

async function getRegistrationTerms() {
  return await serverFetchJson<BackendSiteAgreement>('/site/agreements/registration-terms') || fallbackAgreement
}

export default async function RegistrationTermsPage() {
  const agreement = await getRegistrationTerms()

  return (
    <main className="bg-bg py-12">
      <section className="mx-auto max-w-[860px] rounded-[4px] border border-line bg-white px-7 py-8 shadow-[0_12px_34px_rgba(15,23,42,0.05)]">
        <h1 className="text-3xl font-extrabold text-ink">{agreement.title}</h1>
        {agreement.summary && <p className="mt-3 text-sm font-bold leading-7 text-muted">{agreement.summary}</p>}
        <div className="mt-7 whitespace-pre-line text-sm leading-8 text-muted">{agreement.content}</div>
      </section>
    </main>
  )
}
