import { Check, Eye, Info, Minus, RotateCcw, Wallet } from 'lucide-react';

import { Container, Section, SectionHeading } from '@/components/layout/container';
import { FaqSection } from '@/components/marketing/faq-section';
import { FinalCta } from '@/components/marketing/final-cta';
import { PricingPlayground } from '@/components/marketing/pricing-playground';
import { Reveal } from '@/components/motion/reveal';
import { Card } from '@/components/ui/card';
import { site } from '@/lib/marketing';
import { pageMetadata } from '@/lib/seo';

export const metadata = pageMetadata('Pricing', '/pricing', 'Pay the courier rate plus any platform fee, shown as one total when you compare rates.');

const steps = [
  { title: 'You see the full price up front', text: 'Every rate already includes the courier charge and the platform fee.', icon: Eye },
  { title: 'Your wallet is charged when you buy a label', text: 'Nothing is billed later. The debit matches the total you confirmed.', icon: Wallet },
  { title: 'Cancel eligible labels and get refunded', text: 'While a shipment is still cancellable, the wallet is credited once.', icon: RotateCcw },
];

type Mark = 'check' | 'dash' | 'info';

const comparison: ReadonlyArray<{ label: string; note?: string; you: Mark; courier: Mark; platform: Mark }> = [
  { label: 'Courier rate', you: 'check', courier: 'check', platform: 'dash', note: 'Paid by you, passed to the courier' },
  { label: 'Duties and taxes if chosen', you: 'check', courier: 'info', platform: 'dash', note: 'Depends on destination and service' },
  { label: 'Platform fee', you: 'check', courier: 'dash', platform: 'check', note: 'Already included in the total' },
  { label: 'Insurance if chosen', you: 'check', courier: 'info', platform: 'dash', note: 'Optional, added before you buy' },
];

const markLabel: Record<Mark, string> = { check: 'Yes', dash: 'No', info: 'Depends' };

function Cell({ value }: { value: Mark }) {
  return (
    <span className="mx-auto grid h-7 w-7 place-items-center rounded-full" title={markLabel[value]}>
      {value === 'check' ? <Check className="h-4 w-4 text-success" strokeWidth={3} aria-hidden="true" /> : null}
      {value === 'info' ? <Info className="h-4 w-4 text-info" aria-hidden="true" /> : null}
      {value === 'dash' ? <Minus className="h-4 w-4 text-subtle-foreground" aria-hidden="true" /> : null}
      <span className="sr-only">{markLabel[value]}</span>
    </span>
  );
}

export default function PricingPage() {
  return (
    <>
      <section className="relative overflow-hidden pb-14 pt-32 md:pb-20 md:pt-40">
        <div className="pointer-events-none absolute inset-0 bg-mesh" aria-hidden="true" />
        <Container className="relative">
          <Reveal>
            {/* Placeholder: confirm "no monthly fees" with the owner before launch. */}
            <SectionHeading
              as="h1"
              eyebrow="Pricing"
              title="Pay only when you ship"
              text="No monthly fees and no contracts. Top up a prepaid wallet and spend it on labels at the total shown on each rate."
            />
          </Reveal>
        </Container>
      </section>

      <Section muted>
        <Container>
          <Reveal>
            <SectionHeading eyebrow="How pricing works" title="Clear pricing in three moments" />
          </Reveal>
          <div className="mt-12 grid gap-4 md:grid-cols-3 md:gap-6">
            {steps.map((step, index) => {
              const Icon = step.icon;
              return (
                <Reveal key={step.title} index={index}>
                  <Card className="h-full p-6">
                    <div className="flex items-start justify-between">
                      <div className="grid h-11 w-11 place-items-center rounded-xl bg-primary-soft text-primary">
                        <Icon className="h-5 w-5" aria-hidden="true" />
                      </div>
                      <span className="font-display text-[3rem] font-extrabold leading-none text-transparent [-webkit-text-stroke:1.5px_rgb(var(--primary)/0.4)]" aria-hidden="true">
                        {String(index + 1).padStart(2, '0')}
                      </span>
                    </div>
                    <h3 className="mt-5 font-display text-h3 font-bold">{step.title}</h3>
                    <p className="mt-1.5 text-body text-muted-foreground">{step.text}</p>
                  </Card>
                </Reveal>
              );
            })}
          </div>
        </Container>
      </Section>

      <Section>
        <Container className="grid items-start gap-10 lg:grid-cols-2 lg:gap-12">
          <Reveal>
            <PricingPlayground />
          </Reveal>
          <Reveal index={1}>
            <p className="inline-flex rounded-pill bg-primary-soft px-3 py-1 text-caption font-semibold uppercase tracking-[0.14em] text-primary">Transparency</p>
            <h2 className="mt-4 font-display text-[1.75rem] font-extrabold leading-9 tracking-[-0.02em] md:text-[2.25rem] md:leading-[2.75rem]">Who pays what</h2>
            <p className="mt-3 max-w-md text-body text-muted-foreground">Everything you pay is part of the one total you see before you buy a label.</p>
            <div className="mt-6 overflow-x-auto rounded-lg border border-border bg-surface shadow-xs">
              <table className="w-full min-w-[460px] text-left text-small">
                <caption className="sr-only">Which party each cost goes to</caption>
                <thead className="bg-surface-muted text-caption uppercase tracking-[0.1em] text-muted-foreground">
                  <tr>
                    <th scope="col" className="h-11 px-4 font-semibold">Item</th>
                    <th scope="col" className="h-11 px-3 text-center font-semibold">You</th>
                    <th scope="col" className="h-11 px-3 text-center font-semibold">Courier</th>
                    <th scope="col" className="h-11 px-3 text-center font-semibold">{site.name}</th>
                  </tr>
                </thead>
                <tbody>
                  {comparison.map((row) => (
                    <tr key={row.label} className="border-t border-border transition-colors hover:bg-surface-muted/60">
                      <th scope="row" className="px-4 py-3 font-normal">
                        <span className="block font-semibold text-foreground">{row.label}</span>
                        {row.note === undefined ? null : <span className="block text-caption text-muted-foreground">{row.note}</span>}
                      </th>
                      <td className="px-3 py-3 text-center"><Cell value={row.you} /></td>
                      <td className="px-3 py-3 text-center"><Cell value={row.courier} /></td>
                      <td className="px-3 py-3 text-center"><Cell value={row.platform} /></td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>
            <p className="mt-3 inline-flex items-center gap-4 text-caption text-muted-foreground">
              <span className="inline-flex items-center gap-1"><Check className="h-3.5 w-3.5 text-success" aria-hidden="true" /> Yes</span>
              <span className="inline-flex items-center gap-1"><Info className="h-3.5 w-3.5 text-info" aria-hidden="true" /> Depends</span>
              <span className="inline-flex items-center gap-1"><Minus className="h-3.5 w-3.5 text-subtle-foreground" aria-hidden="true" /> No</span>
            </p>
          </Reveal>
        </Container>
      </Section>

      <FaqSection muted />

      <FinalCta />
    </>
  );
}
