import { Badge } from '@/Components/ui/badge';
import { Card, CardContent } from '@/Components/ui/card';
import WebLayout from '@/Layouts/Web/WebLayout';
import { Head, Link } from '@inertiajs/react';
import { motion, useReducedMotion } from 'framer-motion';
import {
    ArrowRight,
    CheckCircle2,
    ChevronRight,
    CreditCard,
    Printer,
    ShoppingCart,
    Smartphone,
    Wifi,
} from 'lucide-react';

// ─── glass shorthand ───────────────────────────────────────────────────────────

const G =
    'border border-white/20 bg-white/[0.07] backdrop-blur-xl dark:border-white/[0.07] dark:bg-white/[0.04]';
const GS =
    'border border-white/80 bg-white/75 backdrop-blur-xl dark:border-white/[0.08] dark:bg-white/[0.05]';

// ─── data ──────────────────────────────────────────────────────────────────────

const POS_FEATURES = [
    'Touch-optimised interface for cashier speed',
    'Barcode scanning via camera or USB scanner',
    'Quick-add product favourites per cashier',
    'Cart management — hold, resume, split orders',
    'Multi-item discounts and promotions engine',
    'Shift open/close with cash float reconciliation',
    'Thermal receipt printing (Bluetooth & USB)',
    'Offline mode — transactions queue and auto-sync',
];

const PAYMENT_FEATURES = [
    'M-Pesa STK Push — Kenya',
    'Airtel Money — KE, TZ, UG',
    'MTN Mobile Money — Uganda',
    'Cash with automatic change calculation',
    'Split payments across multiple methods',
    'Card payments via connected terminal',
    'Real-time payment confirmation screen',
    'Failed payment retry and reconciliation',
];

const HOW_IT_WORKS = [
    {
        step: '01',
        title: 'Scan or search',
        icon: ShoppingCart,
        desc: 'Cashier scans barcode or types product name. Item added to cart instantly.',
    },
    {
        step: '02',
        title: 'Choose payment',
        icon: CreditCard,
        desc: 'Customer pays by cash, M-Pesa STK Push, Airtel Money, or card. All confirmed in real time.',
    },
    {
        step: '03',
        title: 'Print or send',
        icon: Printer,
        desc: 'Thermal receipt prints automatically, or SMS receipt sent to customer. Shift totals update.',
    },
];

const COUNTRIES = [
    { code: 'KE', name: 'Kenya', networks: 'M-Pesa · Airtel Money' },
    { code: 'TZ', name: 'Tanzania', networks: 'Airtel Money' },
    { code: 'UG', name: 'Uganda', networks: 'Airtel Money · MTN MoMo' },
    { code: 'RW', name: 'Rwanda', networks: 'MoMo MTN' },
];

// ─── animation helper ─────────────────────────────────────────────────────────

function reveal(delay = 0, reduced = false) {
    return {
        initial: reduced ? {} : { opacity: 0, y: 22 },
        whileInView: { opacity: 1, y: 0 },
        viewport: { once: true, amount: 0.12 },
        transition: {
            duration: 0.58,
            ease: [0.25, 0.1, 0.25, 1],
            delay,
        },
    };
}

// ─── page ─────────────────────────────────────────────────────────────────────

export default function PosPage() {
    const reduced = useReducedMotion();
    const rv = (d = 0) => reveal(d, !!reduced);

    return (
        <WebLayout>
            <Head title="POS & Payments — Upepo POS" />

            {/* ── HERO ─────────────────────────────────── */}
            <section className="mx-auto max-w-7xl px-4 pt-36 pb-16 sm:px-6 lg:pt-48">
                <motion.div {...rv(0)} className="flex justify-center">
                    <Badge
                        variant="brand"
                        className="rounded-full px-3.5 py-1.5 text-[11px] tracking-[0.14em] uppercase"
                    >
                        Point of Sale · Payments
                    </Badge>
                </motion.div>

                <motion.h1
                    {...rv(0.07)}
                    className="uf-display mx-auto mt-6 max-w-3xl text-center text-[2.55rem] leading-[1.07] font-extrabold tracking-tight text-foreground sm:text-5xl lg:text-[3.3rem]"
                >
                    The POS that{' '}
                    <span className="text-primary">never lets you down.</span>
                </motion.h1>

                <motion.p
                    {...rv(0.13)}
                    className="mx-auto mt-6 max-w-xl text-center text-[1.04rem] leading-relaxed text-muted-foreground dark:text-white/50"
                >
                    Built for East African realities — Upepo POS keeps selling
                    whether the internet is up or down, and settles every payment
                    via M-Pesa, Airtel Money, or card the moment connectivity
                    returns.
                </motion.p>

                <motion.div
                    {...rv(0.19)}
                    className="mt-8 flex flex-wrap justify-center gap-3"
                >
                    {['Works offline', 'M-Pesa + Airtel', 'Any device'].map(
                        (chip) => (
                            <span
                                key={chip}
                                className={`${GS} rounded-full px-4 py-1.5 text-sm font-medium text-foreground`}
                            >
                                {chip}
                            </span>
                        ),
                    )}
                </motion.div>
            </section>

            {/* ── FEATURE DEEP-DIVE ────────────────────── */}
            <section className="mx-auto max-w-7xl px-4 py-16 sm:px-6">
                <div className="grid gap-6 lg:grid-cols-2">
                    {/* POS column */}
                    <motion.div {...rv(0)}>
                        <Card className={`${G} h-full rounded-2xl`}>
                            <CardContent className="p-8">
                                <div className="mb-2 flex items-center gap-2">
                                    <ShoppingCart
                                        size={20}
                                        className="text-primary"
                                    />
                                    <h2 className="uf-display text-xl font-bold text-foreground">
                                        Point of Sale
                                    </h2>
                                </div>
                                <p className="mb-6 text-sm text-muted-foreground">
                                    A cashier experience built for speed and
                                    resilience — on any device, anywhere.
                                </p>
                                <ul className="space-y-3">
                                    {POS_FEATURES.map((item) => (
                                        <li
                                            key={item}
                                            className="flex items-start gap-3 text-sm text-foreground/80"
                                        >
                                            <CheckCircle2
                                                size={16}
                                                className="mt-0.5 shrink-0 text-primary"
                                            />
                                            {item}
                                        </li>
                                    ))}
                                </ul>
                            </CardContent>
                        </Card>
                    </motion.div>

                    {/* Payments column */}
                    <motion.div {...rv(0.08)}>
                        <Card className={`${G} h-full rounded-2xl`}>
                            <CardContent className="p-8">
                                <div className="mb-2 flex items-center gap-2">
                                    <Smartphone
                                        size={20}
                                        className="text-primary"
                                    />
                                    <h2 className="uf-display text-xl font-bold text-foreground">
                                        Mobile Payments
                                    </h2>
                                </div>
                                <p className="mb-6 text-sm text-muted-foreground">
                                    Every payment rail East Africa uses —
                                    integrated natively, no middleware required.
                                </p>
                                <ul className="space-y-3">
                                    {PAYMENT_FEATURES.map((item) => (
                                        <li
                                            key={item}
                                            className="flex items-start gap-3 text-sm text-foreground/80"
                                        >
                                            <CheckCircle2
                                                size={16}
                                                className="mt-0.5 shrink-0 text-primary"
                                            />
                                            {item}
                                        </li>
                                    ))}
                                </ul>
                            </CardContent>
                        </Card>
                    </motion.div>
                </div>
            </section>

            {/* ── HOW IT WORKS ─────────────────────────── */}
            <section className="mx-auto max-w-7xl px-4 py-16 sm:px-6">
                <motion.div {...rv(0)} className="mb-10 text-center">
                    <Badge
                        variant="lime"
                        className="rounded-full px-3.5 py-1.5 text-[11px] tracking-[0.14em] uppercase"
                    >
                        How it works
                    </Badge>
                    <h2 className="uf-display mt-4 text-2xl font-extrabold tracking-tight text-foreground sm:text-3xl">
                        Three steps to every sale
                    </h2>
                </motion.div>

                <div className="grid gap-6 sm:grid-cols-3">
                    {HOW_IT_WORKS.map(({ step, title, icon: Icon, desc }, i) => (
                        <motion.div key={step} {...rv(i * 0.08)}>
                            <Card className={`${G} h-full rounded-2xl`}>
                                <CardContent className="p-8">
                                    <span className="uf-display text-4xl font-extrabold text-primary/30">
                                        {step}
                                    </span>
                                    <div className="mt-4 flex items-center gap-2">
                                        <Icon
                                            size={18}
                                            className="text-primary"
                                        />
                                        <h3 className="font-semibold text-foreground">
                                            {title}
                                        </h3>
                                    </div>
                                    <p className="mt-3 text-sm leading-relaxed text-muted-foreground">
                                        {desc}
                                    </p>
                                </CardContent>
                            </Card>
                        </motion.div>
                    ))}
                </div>
            </section>

            {/* ── PAYMENT NETWORKS ─────────────────────── */}
            <section className="mx-auto max-w-7xl px-4 py-16 sm:px-6">
                <motion.div {...rv(0)} className="mb-10 text-center">
                    <Badge
                        variant="lime"
                        className="rounded-full px-3.5 py-1.5 text-[11px] tracking-[0.14em] uppercase"
                    >
                        Supported networks
                    </Badge>
                    <h2 className="uf-display mt-4 text-2xl font-extrabold tracking-tight text-foreground sm:text-3xl">
                        4 countries. 3 payment rails. Zero middleware.
                    </h2>
                </motion.div>

                <div className="grid gap-4 sm:grid-cols-2 md:grid-cols-4">
                    {COUNTRIES.map(({ code, name, networks }, i) => (
                        <motion.div key={code} {...rv(i * 0.07)}>
                            <Card className={`${G} rounded-2xl`}>
                                <CardContent className="p-6">
                                    <Badge
                                        variant="brand"
                                        className="uf-display rounded-md px-2.5 py-0.5 text-base font-extrabold"
                                    >
                                        {code}
                                    </Badge>
                                    <p className="mt-3 font-semibold text-foreground">
                                        {name}
                                    </p>
                                    <p className="mt-1.5 text-sm leading-snug text-muted-foreground">
                                        {networks}
                                    </p>
                                </CardContent>
                            </Card>
                        </motion.div>
                    ))}
                </div>
            </section>

            {/* ── CTA ──────────────────────────────────── */}
            <section className="mx-auto max-w-7xl px-4 pb-24 sm:px-6">
                <motion.div
                    {...rv()}
                    className="relative overflow-hidden rounded-3xl bg-panel p-10 text-center sm:p-16"
                >
                    <div className="pointer-events-none absolute -top-24 -left-24 h-72 w-72 rounded-full bg-primary/20 blur-3xl" />
                    <div className="pointer-events-none absolute -right-24 -bottom-24 h-72 w-72 rounded-full bg-accent/14 blur-3xl" />

                    <div className="relative">
                        <Badge
                            variant="brand"
                            className="rounded-full px-3.5 py-1.5 text-[11px] tracking-[0.14em] uppercase"
                        >
                            30-day free trial · No card required
                        </Badge>
                        <h2 className="uf-display mx-auto mt-5 max-w-2xl text-3xl font-extrabold tracking-tight text-white sm:text-4xl">
                            Ready to sell without limits?
                        </h2>
                        <p className="mx-auto mt-4 max-w-lg text-base text-white/45">
                            Get full POS and mobile payments live in minutes.
                            Offline-first, no extra hardware required to start.
                        </p>
                        <div className="mt-8 flex flex-wrap items-center justify-center gap-3">
                            <Link
                                href="/pricing"
                                className="inline-flex items-center gap-2 rounded-xl bg-primary px-6 py-3 text-sm font-semibold text-white shadow-xl shadow-primary/30 transition hover:bg-primary/90"
                            >
                                Start free trial <ArrowRight size={15} />
                            </Link>
                            <Link
                                href="/features"
                                className="inline-flex items-center gap-2 rounded-xl border border-white/14 bg-white/[0.07] px-6 py-3 text-sm font-semibold text-white/80 transition hover:bg-white/[0.12] hover:text-white"
                            >
                                All platform features{' '}
                                <ChevronRight size={15} />
                            </Link>
                        </div>
                    </div>
                </motion.div>
            </section>
        </WebLayout>
    );
}
