import Link from 'next/link';
import { headers } from 'next/headers';
import { ArrowLeft, ShieldCheck } from 'lucide-react';
import PrivacySection from '@/components/algebra1/legal/PrivacySection';
import RefundSection from '@/components/algebra1/legal/RefundSection';
import TermsSection from '@/components/algebra1/legal/TermsSection';
import { SERIF } from '@/components/algebra1/legal/LegalShared';
import { getMetadataForRequest, getRequestMetadataInput } from '@/lib/siteSeo';

const title = 'Privacy Policy, Refund Policy & Terms of Service | Cambridge Veritas Algebra I';
const description =
  'Cambridge Veritas Privacy Policy, Refund & Cancellation Policy, and Terms of Service for the live Algebra I program for Texas Grades 8 & 9.';
const canonical = 'https://cambridgeveritas.com/algebra-privacy';

const fallbackMetadata = {
  title,
  description,
  alternates: { canonical },
  openGraph: {
    title,
    description,
    url: canonical,
    type: 'website',
  },
  twitter: {
    card: 'summary',
    title,
    description,
  },
};

export async function generateMetadata() {
  try {
    return await getMetadataForRequest(
      getRequestMetadataInput(await headers(), {
        pathname: '/algebra-privacy',
        lookupKeyOverrides: ['algebra-privacy'],
      })
    );
  } catch {
    return fallbackMetadata;
  }
}

const SYMBOLS = ['x²', '√x', '∑', 'π', '÷'];
const POLICY_LINKS = [
  ['privacy', 'Privacy Policy'],
  ['refund', 'Refund & Cancellation'],
  ['terms', 'Terms of Service'],
];

const COMPANY_DETAILS = [
  ['Registered office', '1/3064 Janta Block, Ram Nagar, Delhi 110032, India'],
  ['Corporate Identity Number', 'U85499DL2024PTC438179'],
  ['Email', 'contact@cambridgeveritas.com'],
  ['Telephone', '+91 80682 12576'],
];

export default function AlgebraPrivacyPolicy() {
  return (
    <div
      className="min-h-screen overflow-x-hidden"
      style={{
        background: '#FAF6EF',
        fontFamily: 'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
      }}
    >
      <section
        className="relative overflow-hidden px-5 py-14 lg:py-16"
        style={{ background: 'linear-gradient(135deg, #4A1429, #8B2252)' }}
      >
        {SYMBOLS.map((symbol, index) => (
          <span
            key={symbol}
            aria-hidden="true"
            className="pointer-events-none absolute hidden select-none font-extrabold italic sm:block"
            style={{
              color: 'rgba(212,175,56,0.1)',
              fontFamily: SERIF,
              fontSize: `${2.5 + index * 0.7}rem`,
              top: `${8 + index * 17}%`,
              left: index % 2 ? undefined : `${4 + index * 9}%`,
              right: index % 2 ? `${5 + index * 8}%` : undefined,
              transform: `rotate(${index % 2 ? 8 : -8}deg)`,
            }}
          >
            {symbol}
          </span>
        ))}

        <div className="relative mx-auto max-w-4xl text-center">
          <span
            className="mb-5 inline-flex items-center gap-2 rounded-full px-3 py-1 text-[10px] font-bold uppercase tracking-[0.18em]"
            style={{ border: '1px solid rgba(212,175,56,0.5)', color: '#D4AF37' }}
          >
            <ShieldCheck className="h-3.5 w-3.5" /> Cambridge Veritas · Legal &amp; Policies
          </span>
          <h1 className="mb-4 text-3xl font-extrabold leading-tight text-white sm:text-4xl" style={{ fontFamily: SERIF }}>
            Privacy Policy, Refunds &amp; Terms of Service
          </h1>
          <p className="mx-auto mb-5 max-w-2xl text-sm font-medium leading-relaxed sm:text-base" style={{ color: 'rgba(255,255,255,0.8)' }}>
            One page, plain English. What we collect and how we protect it, exactly how billing and refunds work, and the agreement behind the program.
          </p>
          <p className="text-xs font-semibold" style={{ color: 'rgba(255,255,255,0.6)' }}>
            Effective date: September 8, 2026 · Last updated: September 8, 2026
          </p>
        </div>
      </section>

      <nav
        aria-label="Policy sections"
        className="sticky top-0 z-40 border-t px-5 py-3 backdrop-blur-md"
        style={{ background: 'rgba(250,246,239,0.95)', borderColor: 'rgba(212,175,56,0.4)' }}
      >
        <div className="mx-auto flex max-w-4xl flex-wrap items-center justify-center gap-2">
          {POLICY_LINKS.map(([id, label]) => (
            <a
              key={id}
              href={`#${id}`}
              className="rounded-full px-3.5 py-1.5 text-xs font-bold transition-colors"
              style={{ color: '#2D0A18', border: '1px solid rgba(212,175,56,0.45)' }}
            >
              {label}
            </a>
          ))}
        </div>
      </nav>

      <main>
        <PrivacySection />
        <RefundSection />
        <TermsSection />

        <section className="px-5 py-14" style={{ background: '#F3EBDD' }}>
          <div className="mx-auto max-w-3xl">
            <div className="rounded-2xl p-6 sm:p-8" style={{ background: '#FFFFFF', border: '1px solid rgba(212,175,56,0.4)' }}>
              <p className="mb-2 text-[10px] font-bold uppercase tracking-[0.22em]" style={{ color: '#B8912E' }}>
                The company behind the program
              </p>
              <h2 className="mb-4 text-xl font-extrabold" style={{ color: '#2D0A18', fontFamily: SERIF }}>
                Cambridge Veritas is operated by VERITASBRIDGE LEARN PRIVATE LIMITED
              </h2>
              <dl className="mb-5 space-y-1.5">
                {COMPANY_DETAILS.map(([key, value]) => (
                  <div key={key} className="flex gap-2 text-[13px] font-medium leading-relaxed">
                    <dt className="w-44 flex-shrink-0 font-bold" style={{ color: '#2D0A18' }}>{key}</dt>
                    <dd style={{ color: '#4A3A30' }}>{value}</dd>
                  </div>
                ))}
              </dl>
              <p className="text-[11px] font-medium leading-relaxed" style={{ color: '#6B5B4E' }}>
                Cambridge Veritas is an independent supplemental tutoring provider. It is not a school and does not award academic credit. It is not affiliated with, sponsored by, or endorsed by the University of Cambridge, Cambridge University Press &amp; Assessment, the Texas Education Agency, or any school district. References to Texas standards or STAAR are descriptive only.
              </p>
            </div>

            <div className="mt-8 text-center">
              <Link
                href="/online-algebra-1-tutoring"
                className="inline-flex items-center gap-2 text-xs font-bold transition-opacity hover:opacity-80"
                style={{ color: '#8B4E78' }}
              >
                <ArrowLeft className="h-4 w-4" style={{ color: '#B8912E' }} /> Back to the Algebra I course
              </Link>
            </div>
          </div>
        </section>
      </main>
    </div>
  );
}
