import Link from "@/components/common/versioned-link"
import { LEGAL_DOCS, LegalSlug } from "@/content/legal"

const OTHERS: { slug: LegalSlug; label: string }[] = [
  { slug: "terms", label: "قوانین و شرایط" },
  { slug: "privacy", label: "حریم خصوصی" },
  { slug: "refund", label: "بازگشت وجه" },
]

/** A legal page, readable without logging in. */
export default function LegalView({ slug }: { slug: LegalSlug }) {
  const doc = LEGAL_DOCS[slug]

  return (
    <article className="w-full max-w-2xl mx-auto px-5 py-6 text-right">
      <h1 className="text-title-1 font-extrabold text-ink">{doc.title}</h1>
      <p className="text-caption text-ink-soft mt-1">آخرین به‌روزرسانی: {doc.updated}</p>
      <p className="text-body leading-8 text-ink/90 mt-4">{doc.intro}</p>

      {doc.sections.map((section) => (
        <section key={section.heading} className="mt-6">
          <h2 className="text-title-3 font-extrabold text-ink mb-2">{section.heading}</h2>
          {section.paragraphs.map((p, i) => (
            <p key={i} className="text-body leading-8 text-ink/85 mb-2">{p}</p>
          ))}
        </section>
      ))}

      <nav aria-label="صفحه‌های قانونی" className="flex flex-wrap gap-2 mt-8 pt-5 border-t border-line">
        {OTHERS.filter((o) => o.slug !== slug).map((o) => (
          <Link key={o.slug} href={`/legal/${o.slug}`} className="h-9 px-4 rounded-full border border-line bg-canvas text-body-sm font-bold text-ink-soft grid place-items-center">
            {o.label}
          </Link>
        ))}
      </nav>
    </article>
  )
}
