import type { Metadata } from 'next'
import { Legal } from '@/components/Legal'
import { Shell } from '@/components/Shell'
import { publicConfig } from '@/lib/config'
import { pageMeta } from '@/lib/meta'
import { type Locale, loadPage, loadSite } from '@/lib/site'

type Props = { params: Promise<{ locale: Locale }> }

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { locale } = await params
  const p = await loadPage('privacy', locale)
  return pageMeta(locale, '/privacy', p.seo?.title, p.seo?.description)
}

/** «سياسة الخصوصية»: what the academy knows about a student, why, and what they may ask of us. */
export default async function PrivacyPage({ params }: Props) {
  const { locale } = await params
  const [{ settings: s, courses }, p] = await Promise.all([loadSite(locale), loadPage('privacy', locale)])

  return (
    <Shell locale={locale} path="/privacy" settings={s} courses={courses} config={publicConfig()}>
      <div className="container pagehead">
        <h1>{p.h1}</h1>
        {p.updated ? <p className="tk-legal-updated">{p.updated}</p> : null}
      </div>
      <Legal lead={p.lead} sections={p.sections} closing={p.closing} />
    </Shell>
  )
}
