import { createFileRoute } from "@tanstack/react-router";
import { LegalPage, LegalSection } from "@/components/legal/LegalPage";
import { legal } from "@/lib/legal";

export const Route = createFileRoute("/legal/licenses")({
  head: () => ({
    meta: [
      { title: "Licenses — PRUDENTIA" },
      { name: "description", content: "Open-source software and third-party services used to build PRUDENTIA, with their licenses." },
      { property: "og:title", content: "Licenses — PRUDENTIA" },
      { property: "og:description", content: "Open-source acknowledgements for the libraries powering PRUDENTIA." },
      { property: "og:type", content: "article" },
      { name: "twitter:card", content: "summary" },
    ],
  }),
  component: LicensesPage,
});

const LIBS: { name: string; license: string; use: string }[] = [
  { name: "React", license: "MIT", use: "User interface runtime" },
  { name: "TanStack Router / Start", license: "MIT", use: "Routing and server functions" },
  { name: "TanStack Query", license: "MIT", use: "Data fetching and caching" },
  { name: "Tailwind CSS", license: "MIT", use: "Styling system" },
  { name: "Radix UI", license: "MIT", use: "Accessible UI primitives" },
  { name: "shadcn/ui", license: "MIT", use: "Component patterns" },
  { name: "lucide-react", license: "ISC", use: "Iconography" },
  { name: "Recharts", license: "MIT", use: "Charts and visualisations" },
  { name: "date-fns", license: "MIT", use: "Date maths" },
  { name: "Zod", license: "MIT", use: "Input validation" },
  { name: "react-hook-form", license: "MIT", use: "Forms" },
  { name: "react-markdown", license: "MIT", use: "Rendering AI responses" },
  { name: "sonner", license: "MIT", use: "Toast notifications" },
  { name: "embla-carousel", license: "MIT", use: "Carousels" },
  { name: "cmdk", license: "MIT", use: "Command palette primitives" },
  { name: "supabase-js", license: "MIT", use: "Backend, auth and storage client" },
  { name: "Vite", license: "MIT", use: "Build tooling" },
];

function LicensesPage() {
  return (
    <LegalPage
      eyebrow="Legal"
      title="Licenses"
      intro="PRUDENTIA is built on open-source software. We are grateful to the maintainers of these projects."
    >
      <LegalSection title="Open-source libraries">
        <ul className="divide-y divide-white/5">
          {LIBS.map((l) => (
            <li key={l.name} className="flex items-start justify-between gap-3 py-2.5">
              <div className="min-w-0">
                <p className="text-[13px] font-medium text-foreground">{l.name}</p>
                <p className="text-[11px] text-muted-foreground">{l.use}</p>
              </div>
              <span className="text-[11px] text-muted-foreground shrink-0 pt-0.5">{l.license}</span>
            </li>
          ))}
        </ul>
        <p className="pt-2">Each library remains under its own license, held by its respective copyright holders. Full license texts are distributed with the corresponding packages.</p>
      </LegalSection>

      <LegalSection title="Fonts and assets">
        <p>Typography uses open web fonts licensed under the SIL Open Font License. Merchant logos, where shown, are the trademarks of their respective owners and are used only to help you recognise your own transactions.</p>
      </LegalSection>

      <LegalSection title="Attribution requests">
        <p>If you maintain a project listed here and would like the attribution corrected or removed, contact {legal.contact()}.</p>
      </LegalSection>
    </LegalPage>
  );
}
