"use client";

import type { ReactNode } from "react";
import Link from "next/link";
import { HelpCircle, ShieldCheck, ScrollText, ArrowUpRight } from "lucide-react";
import { useTranslation } from "react-i18next";

export type InfoPageKind = "faq" | "privacy" | "terms";
const pages = [
  { kind: "faq", href: "/faq", title: "COMMON.FAQs", icon: HelpCircle },
  { kind: "privacy", href: "/privacy-policy", title: "PRIVACY.TITLE", icon: ShieldCheck },
  { kind: "terms", href: "/termsofuse", title: "TERMS.TITLE", icon: ScrollText },
] as const;

/** Shared reading surface for help and policy pages, including CMS content. */
export default function InfoPageLayout({ kind, title, children }: {
  kind: InfoPageKind;
  title: string;
  children: ReactNode;
}) {
  const { t } = useTranslation();
  const Icon = pages.find(page => page.kind === kind)!.icon;
  return (
    <div className="info-page">
      <header className="info-page-hero">
        <div className="info-page-width">
          <span className="info-page-eyebrow">{t("INFO.CENTER")}</span>
          <div className="info-page-title-row">
            <span className="info-page-icon"><Icon size={28} aria-hidden="true" /></span>
            <h1>{title.replace(/^\s*[:：]|[:：]\s*$/g, "").trim()}</h1>
          </div>
          <p>{t(`INFO.INTRO_${kind.toUpperCase()}`)}</p>
        </div>
      </header>
      <div className="info-page-width info-page-grid">
        <aside className="info-page-sidebar">
          <nav aria-label={t("INFO.NAVIGATION")}>
            {pages.map(page => <Link key={page.kind} href={page.href} aria-current={kind === page.kind ? "page" : undefined}>
              <page.icon size={20} aria-hidden="true" /><span>{t(`INFO.NAV_${page.kind.toUpperCase()}`)}</span>
            </Link>)}
          </nav>
          <div className="info-page-help">
            <h2>{t("INFO.NEED_HELP")}</h2>
            <p>{t("INFO.HELP_DESCRIPTION")}</p>
            <Link href="/contact-us">{t("COMMON.CONTACTUS")}<ArrowUpRight size={18} aria-hidden="true" /></Link>
          </div>
        </aside>
        <div className={`info-page-main ${kind === "faq" ? "info-page-faq" : "info-page-document"}`}>{children}</div>
      </div>
    </div>
  );
}
