import { LegalPage, Section, LegalContact } from "@/components/marketing/legal"
import { LEGAL } from "@/lib/legal"

export const metadata = {
  title: "Cookie Policy",
  description:
    "How we use cookies and similar technologies, what we deliberately avoid, and how to manage them in your browser.",
  alternates: { canonical: "/cookie-policy" },
}

const COOKIE_ROWS: { name: string; type: string; purpose: string; expires: string }[] = [
  {
    name: "session",
    type: "Strictly necessary",
    purpose: "Keeps you signed in and maintains your authenticated session",
    expires: "On sign-out or after inactivity",
  },
  {
    name: "preferences (localStorage)",
    type: "Preference",
    purpose: "Stores interface preferences such as layout and theme in your browser",
    expires: "Persistent until cleared",
  },
  {
    name: "__stripe_*",
    type: "Strictly necessary (Stripe)",
    purpose: "Set by Stripe to prevent payment fraud during checkout",
    expires: "Session or up to one year",
  },
]

export default function Page() {
  return (
    <LegalPage
      title="Cookie Policy"
      subtitle="This policy explains how we use cookies and similar technologies within the Service."
    >
      <Section heading="What are cookies">
        <p>
          Cookies are small text files that a website stores on your device through your browser.
          Similar technologies, such as browser <strong>localStorage</strong>, allow a site to store
          data locally in a comparable way. These technologies help a website keep you signed in,
          remember your preferences, and operate securely. This policy describes how{" "}
          <strong>{LEGAL.entity}</strong> uses them within <strong>{LEGAL.service}</strong> (the{" "}
          <strong>Service</strong>).
        </p>
      </Section>

      <Section heading="Cookies and similar technologies we use">
        <p>We use only the following limited set of technologies:</p>
        <ul>
          <li>
            <strong>Strictly necessary authentication and session cookies</strong>&mdash;required to
            sign you in and to maintain your secure session. The Service cannot function without
            these.
          </li>
          <li>
            <strong>Preference storage in browser localStorage</strong>&mdash;used to remember
            interface preferences, such as layout and theme, on your device.
          </li>
          <li>
            <strong>Stripe cookies</strong>&mdash;set by Stripe during payment to help prevent fraud
            and to support secure checkout.
          </li>
          <li>
            <strong>Cloudflare Turnstile challenge cookie</strong>&mdash;a challenge cookie that may
            be set on authentication pages to distinguish genuine users from automated bots.
          </li>
        </ul>
      </Section>

      <Section heading="What we do not use">
        <p>
          We do <strong>not</strong> use advertising, retargeting, or cross-site tracking cookies, and
          we do <strong>not</strong> use third-party analytics cookies. We do not build advertising
          profiles or share cookie data with advertising networks.
        </p>
      </Section>

      <Section heading="Managing cookies">
        <p>
          Most browsers allow you to view, block, or delete cookies through their settings. Because
          our authentication and session cookies are <strong>strictly necessary</strong>, blocking
          them will prevent you from signing in to and using the Service. You can adjust your browser
          settings at any time to control non-essential storage.
        </p>
      </Section>

      <Section heading="Retention">
        <p>
          <strong>Session</strong> cookies are temporary and are cleared when your session ends, while{" "}
          <strong>persistent</strong> storage remains on your device until it expires or you remove
          it. Authentication sessions expire after a period of inactivity, after which you will be
          asked to sign in again.
        </p>
      </Section>

      <Section heading="Changes">
        <p>
          We may update this Cookie Policy as the Service evolves. When we make material changes, we
          will update the date shown above. Please review this page periodically to stay informed.
        </p>
      </Section>

      <LegalContact email={LEGAL.privacyEmail} />

      <div className="rounded-2xl border border-white/[0.06] bg-[#111118] overflow-hidden">
        <div className="px-5 py-3.5 border-b border-white/[0.04]">
          <p className="text-xs font-semibold uppercase tracking-wider text-white/30">
            Cookie summary
          </p>
        </div>
        {COOKIE_ROWS.map((row, i, arr) => (
          <div
            key={row.name}
            className={`grid grid-cols-1 gap-1 px-5 py-3.5 text-xs sm:grid-cols-4 sm:gap-4 ${
              i !== arr.length - 1 ? "border-b border-white/[0.04]" : ""
            }`}
          >
            <code className="font-mono text-indigo-300">{row.name}</code>
            <span className="text-white/60">{row.type}</span>
            <span className="text-white/40 sm:col-span-1">{row.purpose}</span>
            <span className="text-white/40">{row.expires}</span>
          </div>
        ))}
      </div>
    </LegalPage>
  )
}
