import { Head, Link, usePage } from '@inertiajs/react';
import { motion, AnimatePresence } from 'framer-motion';
import {
    TrendingUp,
    Layers,
    ShieldCheck,
    Cpu,
    Coins,
    Users,
    ArrowRight,
    Sparkles,
    AlertCircle,
    CheckCircle2,
    LineChart,
    Sun,
    Moon,
    Monitor,
    Menu,
} from 'lucide-react';
import { useState } from 'react';
import AppLogoIcon from '@/components/app-logo-icon';
import { LanguageSwitcher } from '@/components/language-switcher';
import { Button } from '@/components/ui/button';
import {
    Sheet,
    SheetContent,
    SheetTitle,
    SheetTrigger,
} from '@/components/ui/sheet';
import { Toaster } from '@/components/ui/sonner';
import { useAppearance } from '@/hooks/use-appearance';
import { useTranslation } from '@/hooks/use-translation';
import { dashboard, login } from '@/routes';

export default function Welcome() {
    const { auth } = usePage().props;
    const { t } = useTranslation();
    const [activeSandboxTab, setActiveSandboxTab] = useState<
        'profit' | 'vendors' | 'products'
    >('profit');
    const { appearance, updateAppearance } = useAppearance();

    const toLocalDigits = (val: string | number) => {
        const str = String(val);

        if (t('common.locale') !== 'bn') {
            return str;
        }

        const bnDigits = ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'];

        return str.replace(/[0-9]/g, (w) => bnDigits[parseInt(w)]);
    };

    const scrollToSection = (
        e: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>,
        id: string,
    ) => {
        e.preventDefault();
        const element = document.getElementById(id);

        if (element) {
            element.scrollIntoView({ behavior: 'smooth' });
        }
    };

    // Dashboard Mockup Data
    const mockVendors = [
        {
            name: 'Apex Electronics',
            dues: '৳1,240.00',
            status: 'Pending',
            color: 'text-amber-400 bg-amber-500/10 border-amber-500/20',
        },
        {
            name: 'Sleek Wear Ltd',
            dues: '৳450.00',
            status: 'Pending',
            color: 'text-amber-400 bg-amber-500/10 border-amber-500/20',
        },
        {
            name: 'Prime Goods',
            dues: '৳0.00',
            status: 'Settled',
            color: 'text-emerald-400 bg-emerald-500/10 border-emerald-500/20',
        },
    ];

    const mockProducts = [
        {
            name: 'Smartwatch Series X',
            margin: '42%',
            revenue: '৳8,420.00',
            stock: 124,
        },
        {
            name: 'Audio Pods Pro',
            margin: '51%',
            revenue: '৳12,050.00',
            stock: 89,
        },
        {
            name: 'MagSafe Dock Max',
            margin: '38%',
            revenue: '৳4,100.00',
            stock: 15,
        },
    ];

    return (
        <div className="relative flex min-h-screen flex-col overflow-x-hidden bg-slate-50 font-sans text-zinc-800 transition-colors duration-300 selection:bg-indigo-500/30 dark:bg-zinc-950 dark:text-zinc-100">
            <Head title="Command Your Reseller Profits" />

            {/* Background elements */}
            <div className="pointer-events-none absolute inset-0 z-0 overflow-hidden">
                <div className="bg-grid-black/[0.02] dark:bg-grid-white/[0.015] absolute inset-0 bg-[size:30px]" />
                <div className="absolute top-[-10%] left-[-10%] h-[50%] w-[50%] rounded-full bg-gradient-to-tr from-violet-600/5 to-indigo-600/5 blur-[150px] dark:from-violet-600/10 dark:to-indigo-600/10" />
                <div className="absolute right-[-10%] bottom-[-10%] h-[50%] w-[50%] rounded-full bg-gradient-to-tr from-cyan-500/5 to-indigo-500/5 blur-[150px] dark:from-cyan-500/10 dark:to-indigo-500/10" />
            </div>

            {/* Navigation Header */}
            <header className="sticky top-0 z-40 border-b border-slate-200 bg-white/70 backdrop-blur-md transition-colors duration-300 dark:border-zinc-900/80 dark:bg-zinc-950/70">
                <div className="mx-auto flex h-20 max-w-7xl items-center justify-between px-4 sm:px-6 lg:px-8">
                    <Link href="/" className="group flex items-center gap-3">
                        <AppLogoIcon className="h-14 w-14 shrink-0 transition-all duration-300 group-hover:scale-105" />
                        <div className="flex flex-col">
                            <span className="font-display text-2xl font-bold tracking-tight text-zinc-900 transition-colors dark:text-white">
                                <span className="font-black text-zinc-900 dark:text-white">
                                    Profit
                                </span>
                                <span className="font-extrabold text-blue-500 dark:text-blue-400">
                                    ly
                                </span>
                            </span>
                            <span className="mt-0.5 text-[10px] leading-none font-semibold tracking-widest text-zinc-400 uppercase dark:text-zinc-500">
                                {t('welcome.tagline')}
                            </span>
                        </div>
                    </Link>

                    {/* Nav Links - Desktop */}
                    <nav className="hidden items-center gap-8 text-sm font-medium text-zinc-500 md:flex dark:text-zinc-400">
                        <button
                            onClick={(e) => scrollToSection(e, 'features')}
                            className="cursor-pointer border-0 bg-transparent p-0 font-medium transition-colors hover:text-zinc-950 dark:hover:text-white"
                        >
                            {t('welcome.features')}
                        </button>
                        <button
                            onClick={(e) =>
                                scrollToSection(e, 'dashboard-preview')
                            }
                            className="cursor-pointer border-0 bg-transparent p-0 font-medium transition-colors hover:text-zinc-950 dark:hover:text-white"
                        >
                            {t('welcome.platform')}
                        </button>
                        {auth.user && (
                            <Link
                                href={dashboard().url}
                                className="font-medium transition-colors hover:text-zinc-950 dark:hover:text-white"
                            >
                                {t('welcome.admin_panel')}
                            </Link>
                        )}
                    </nav>

                    {/* CTA Actions - Desktop */}
                    <div className="hidden items-center gap-4 md:flex">
                        {/* One-click Theme Switcher */}
                        <button
                            onClick={() => {
                                if (appearance === 'light') {
                                    updateAppearance('dark');
                                } else if (appearance === 'dark') {
                                    updateAppearance('system');
                                } else {
                                    updateAppearance('light');
                                }
                            }}
                            className="dark:hover:bg-zinc-850/80 cursor-pointer rounded-xl border border-slate-200 bg-white p-2 text-zinc-500 shadow-sm transition-colors hover:bg-slate-100 hover:text-zinc-800 dark:border-zinc-800/80 dark:bg-zinc-900/60 dark:text-zinc-400 dark:hover:text-white"
                            title={`Current: ${appearance.toUpperCase()}. Click to cycle.`}
                        >
                            {appearance === 'light' && (
                                <Sun className="h-4 w-4 text-amber-500" />
                            )}
                            {appearance === 'dark' && (
                                <Moon className="h-4 w-4 text-violet-400" />
                            )}
                            {appearance === 'system' && (
                                <Monitor className="h-4 w-4 text-cyan-500" />
                            )}
                        </button>
                        <LanguageSwitcher variant="compact" />

                        {auth.user ? (
                            <Link
                                href={dashboard().url}
                                className="rounded-xl bg-zinc-900 px-5 py-2.5 text-xs font-semibold text-white shadow-lg shadow-black/5 transition-all hover:bg-zinc-800 dark:bg-white dark:text-zinc-950 dark:shadow-white/5 dark:hover:bg-zinc-200"
                            >
                                {t('welcome.admin_panel')}
                            </Link>
                        ) : (
                            <Link
                                href={login().url}
                                className="rounded-xl bg-gradient-to-r from-violet-600 via-indigo-600 to-cyan-500 px-5 py-2.5 text-xs font-semibold text-white shadow-md shadow-indigo-600/10 transition-all hover:from-violet-500 hover:to-cyan-400 hover:shadow-cyan-500/10"
                            >
                                {t('welcome.access_platform')}
                            </Link>
                        )}
                    </div>

                    {/* Mobile Menu Trigger & Actions */}
                    <div className="flex items-center gap-2 md:hidden">
                        {/* Theme switcher */}
                        <button
                            onClick={() => {
                                if (appearance === 'light') {
                                    updateAppearance('dark');
                                } else if (appearance === 'dark') {
                                    updateAppearance('system');
                                } else {
                                    updateAppearance('light');
                                }
                            }}
                            className="dark:hover:bg-zinc-850/80 cursor-pointer rounded-xl border border-slate-200 bg-white p-2 text-zinc-500 shadow-sm transition-colors hover:bg-slate-100 hover:text-zinc-800 dark:border-zinc-800/80 dark:bg-zinc-900/60 dark:text-zinc-400 dark:hover:text-white"
                            title={`Current: ${appearance.toUpperCase()}. Click to cycle.`}
                        >
                            {appearance === 'light' && (
                                <Sun className="h-4 w-4 text-amber-500" />
                            )}
                            {appearance === 'dark' && (
                                <Moon className="h-4 w-4 text-violet-400" />
                            )}
                            {appearance === 'system' && (
                                <Monitor className="h-4 w-4 text-cyan-500" />
                            )}
                        </button>
                        <LanguageSwitcher variant="flag-only" />

                        <Sheet>
                            <SheetTrigger asChild>
                                <Button
                                    variant="ghost"
                                    size="icon"
                                    className="h-9 w-9 rounded-xl border border-slate-200 bg-white/50 dark:border-zinc-800 dark:bg-zinc-900/50"
                                >
                                    <Menu className="text-zinc-650 dark:text-zinc-350 h-5 w-5" />
                                </Button>
                            </SheetTrigger>
                            <SheetContent
                                side="right"
                                className="flex h-full w-64 flex-col justify-between border-l border-slate-200 bg-white p-6 dark:border-zinc-900 dark:bg-zinc-950"
                            >
                                <SheetTitle className="sr-only">
                                    Navigation Menu
                                </SheetTitle>
                                <div className="mt-4 flex w-full flex-col items-center gap-8">
                                    <div className="flex flex-col items-center gap-2">
                                        <AppLogoIcon className="h-10 w-10 text-violet-600 dark:text-violet-400" />
                                        <span className="font-display text-xl font-bold tracking-tight text-zinc-900 dark:text-white">
                                            Profitly
                                        </span>
                                    </div>
                                    <nav className="text-zinc-550 flex w-full flex-col items-center gap-5 text-lg font-medium dark:text-zinc-400">
                                        <button
                                            onClick={(e) => {
                                                scrollToSection(e, 'features');
                                            }}
                                            className="w-full cursor-pointer border-0 bg-transparent p-0 py-2 text-center font-medium transition-colors hover:text-zinc-950 dark:hover:text-white"
                                        >
                                            {t('welcome.features')}
                                        </button>
                                        <button
                                            onClick={(e) => {
                                                scrollToSection(
                                                    e,
                                                    'dashboard-preview',
                                                );
                                            }}
                                            className="w-full cursor-pointer border-0 bg-transparent p-0 py-2 text-center font-medium transition-colors hover:text-zinc-950 dark:hover:text-white"
                                        >
                                            {t('welcome.platform')}
                                        </button>
                                    </nav>
                                </div>
                                <div className="flex w-full justify-center pb-8">
                                    {auth.user ? (
                                        <Link
                                            href={dashboard().url}
                                            className="flex w-full justify-center rounded-xl bg-zinc-900 px-5 py-3 text-center text-sm font-semibold text-white shadow-md transition-all hover:bg-zinc-800 dark:bg-white dark:text-zinc-950 dark:hover:bg-zinc-200"
                                        >
                                            {t('welcome.admin_panel')}
                                        </Link>
                                    ) : (
                                        <Link
                                            href={login().url}
                                            className="flex w-full justify-center rounded-xl bg-gradient-to-r from-violet-600 via-indigo-600 to-cyan-500 px-5 py-3 text-center text-sm font-semibold text-white shadow-md transition-all hover:from-violet-500 hover:to-cyan-400"
                                        >
                                            {t('welcome.access_platform')}
                                        </Link>
                                    )}
                                </div>
                            </SheetContent>
                        </Sheet>
                    </div>
                </div>
            </header>

            {/* Hero Section */}
            <section className="relative pt-20 pb-16 md:pt-32 md:pb-24">
                <div className="relative z-10 mx-auto max-w-7xl px-4 text-center sm:px-6 lg:px-8">
                    <motion.div
                        initial={{ opacity: 0, y: 20 }}
                        animate={{ opacity: 1, y: 0 }}
                        transition={{ duration: 0.6 }}
                        className="space-y-6"
                    >
                        <span className="inline-flex items-center gap-2 rounded-full border border-cyan-200 bg-cyan-50/50 px-4 py-1.5 text-xs font-semibold tracking-widest text-cyan-600 uppercase dark:border-cyan-800/30 dark:bg-cyan-950/40 dark:text-cyan-400">
                            <Sparkles className="h-3.5 w-3.5" />
                            {t('welcome.next_gen_bi')}
                        </span>

                        <h1 className="mx-auto max-w-5xl font-display text-4xl leading-tight font-extrabold tracking-tight text-zinc-900 sm:text-6xl md:text-7xl dark:text-white">
                            {t('welcome.hero_title_1')} <br />
                            <span className="bg-gradient-to-r from-violet-500 via-indigo-500 to-cyan-500 bg-clip-text text-transparent dark:from-violet-400 dark:via-indigo-400 dark:to-cyan-400">
                                {t('welcome.hero_title_2')}
                            </span>
                        </h1>

                        <p className="mx-auto max-w-3xl text-lg leading-relaxed font-light text-zinc-600 sm:text-xl dark:text-zinc-400">
                            {t('welcome.hero_desc')}
                        </p>

                        <div className="flex flex-col items-center justify-center gap-4 pt-4 sm:flex-row">
                            <Link
                                href={auth.user ? dashboard().url : login().url}
                                className="flex w-full items-center justify-center gap-2 rounded-xl bg-zinc-900 px-8 py-4 font-semibold text-white shadow-xl shadow-black/5 transition-all hover:bg-zinc-800 sm:w-auto dark:bg-white dark:text-zinc-950 dark:shadow-white/5 dark:hover:bg-zinc-200"
                            >
                                {t('welcome.get_started_free')}
                                <ArrowRight className="h-4 w-4" />
                            </Link>
                        </div>

                        {/* Social proof metric pills */}
                        <div className="dark:text-zinc-550 flex flex-wrap items-center justify-center gap-6 pt-12 text-xs font-medium tracking-wider text-zinc-500 uppercase">
                            <div className="flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-2 dark:border-zinc-800/50 dark:bg-zinc-900/40">
                                <span className="h-2 w-2 rounded-full bg-violet-500" />
                                {t('welcome.tx_tracked', {
                                    amount:
                                        t('common.locale') === 'bn'
                                            ? '৳৪.২ কোটি+'
                                            : '$42M+',
                                })}
                            </div>
                            <div className="flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-2 dark:border-zinc-800/50 dark:bg-zinc-900/40">
                                <span className="h-2 w-2 rounded-full bg-cyan-500" />
                                {t('welcome.uptime')}
                            </div>
                            <div className="flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-2 dark:border-zinc-800/50 dark:bg-zinc-900/40">
                                <span className="h-2 w-2 rounded-full bg-indigo-500" />
                                {t('welcome.vendors_integrated')}
                            </div>
                        </div>
                    </motion.div>
                </div>
            </section>

            {/* Interactive Mockup Sandbox */}
            <section
                id="dashboard-preview"
                className="relative overflow-hidden border-y border-slate-200 bg-slate-100 py-16 transition-colors duration-300 dark:border-zinc-900 dark:bg-zinc-950"
            >
                <div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
                    <div className="mx-auto mb-16 max-w-3xl text-center">
                        <h2 className="text-3xl font-bold tracking-tight text-zinc-900 sm:text-4xl dark:text-white">
                            {t('welcome.cockpit_title')}
                        </h2>
                        <p className="mt-4 font-light text-zinc-600 dark:text-zinc-400">
                            {t('welcome.cockpit_desc')}
                        </p>
                    </div>

                    {/* Interactive Tab Switchers */}
                    <div className="border-slate-350 mx-auto mb-8 flex max-w-sm justify-center gap-1 rounded-2xl border bg-slate-200/60 p-1 transition-colors duration-300 sm:max-w-md dark:border-zinc-800 dark:bg-zinc-900">
                        {[
                            {
                                id: 'profit',
                                label: t('welcome.profit_analytics'),
                                shortLabel: t('welcome.profit_short'),
                                icon: LineChart,
                            },
                            {
                                id: 'vendors',
                                label: t('welcome.vendor_dues'),
                                shortLabel: t('welcome.vendor_short'),
                                icon: Coins,
                            },
                            {
                                id: 'products',
                                label: t('welcome.product_margin'),
                                shortLabel: t('welcome.product_short'),
                                icon: Layers,
                            },
                        ].map((tab) => {
                            const Icon = tab.icon;

                            return (
                                <button
                                    key={tab.id}
                                    onClick={() =>
                                        setActiveSandboxTab(tab.id as any)
                                    }
                                    className={`flex flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-xl px-2.5 py-2.5 text-[11px] font-semibold transition-all duration-200 sm:px-4 sm:py-3 sm:text-xs ${
                                        activeSandboxTab === tab.id
                                            ? 'border border-slate-300 bg-white text-zinc-900 shadow-md dark:border-zinc-700/50 dark:bg-zinc-800 dark:text-white'
                                            : 'text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-white'
                                    }`}
                                >
                                    <Icon className="h-3.5 w-3.5 shrink-0" />
                                    <span className="hidden sm:inline">
                                        {tab.label}
                                    </span>
                                    <span className="inline sm:hidden">
                                        {tab.shortLabel}
                                    </span>
                                </button>
                            );
                        })}
                    </div>

                    {/* Cockpit Card Wrapper */}
                    <div className="relative mx-auto max-w-5xl rounded-3xl border border-slate-200 bg-white p-4 shadow-2xl backdrop-blur-md transition-colors duration-300 sm:p-6 md:p-8 dark:border-zinc-800/80 dark:bg-zinc-900/40">
                        <div className="absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-indigo-500/20 to-transparent" />

                        {/* Windows controls layout */}
                        <div className="mb-6 flex items-center justify-between border-b border-slate-200 pb-4 dark:border-zinc-800">
                            <div className="flex items-center gap-1.5 sm:gap-2">
                                <span className="h-3 w-3 shrink-0 rounded-full bg-rose-500/40" />
                                <span className="h-3 w-3 shrink-0 rounded-full bg-amber-500/40" />
                                <span className="h-3 w-3 shrink-0 rounded-full bg-emerald-500/40" />
                                <div className="mx-1.5 h-4 w-px shrink-0 bg-slate-200 sm:mx-2 dark:bg-zinc-800" />
                                <span className="max-w-[120px] truncate font-mono text-[10px] text-zinc-400 sm:max-w-none sm:text-xs dark:text-zinc-500">
                                    dashboard_preview.vdx
                                </span>
                            </div>
                            <span className="text-zinc-650 dark:text-zinc-550 border-slate-250 hidden rounded-md border bg-slate-100 px-2.5 py-1 font-mono text-[10px] tracking-widest uppercase sm:inline-block dark:border-zinc-800 dark:bg-zinc-950">
                                {t('welcome.live_demo')}
                            </span>
                        </div>

                        {/* Interactive Sandbox Cards */}
                        <AnimatePresence mode="wait">
                            {activeSandboxTab === 'profit' && (
                                <motion.div
                                    key="profit"
                                    initial={{ opacity: 0, y: 10 }}
                                    animate={{ opacity: 1, y: 0 }}
                                    exit={{ opacity: 0, y: -10 }}
                                    transition={{ duration: 0.3 }}
                                    className="grid grid-cols-1 gap-6 lg:grid-cols-3"
                                >
                                    {/* Stat 1 */}
                                    <div className="dark:border-zinc-850 rounded-2xl border border-slate-200 bg-slate-50 p-4 sm:p-6 dark:bg-zinc-950">
                                        <div className="flex items-start justify-between gap-2">
                                            <span className="text-zinc-550 text-xs font-medium dark:text-zinc-400">
                                                {t(
                                                    'welcome.monthly_gross_profit',
                                                )}
                                            </span>
                                            <span className="text-emerald-650 shrink-0 rounded-full bg-emerald-500/10 px-2 py-0.5 text-[10px] font-bold dark:text-emerald-400">
                                                +18.2%
                                            </span>
                                        </div>
                                        <div className="mt-4 text-2xl font-bold text-zinc-900 sm:text-3xl dark:text-white">
                                            {t('common.locale') === 'bn'
                                                ? '৳১৪,৮২০.০০'
                                                : '৳14,820.00'}
                                        </div>
                                        <div className="mt-2 font-mono text-[10px] text-zinc-400 dark:text-zinc-500">
                                            {t('welcome.calculated_orders', {
                                                count:
                                                    t('common.locale') === 'bn'
                                                        ? '৩৪০'
                                                        : '340',
                                            })}
                                        </div>
                                    </div>
                                    {/* Stat 2 */}
                                    <div className="dark:border-zinc-850 rounded-2xl border border-slate-200 bg-slate-50 p-4 sm:p-6 dark:bg-zinc-950">
                                        <div className="flex items-start justify-between gap-2">
                                            <span className="text-zinc-550 text-xs font-medium dark:text-zinc-400">
                                                {t('welcome.avg_order_value')}
                                            </span>
                                            <span className="text-cyan-650 shrink-0 rounded-full bg-cyan-500/10 px-2 py-0.5 text-[10px] font-bold dark:text-cyan-400">
                                                +4.6%
                                            </span>
                                        </div>
                                        <div className="mt-4 text-2xl font-bold text-zinc-900 sm:text-3xl dark:text-white">
                                            {t('common.locale') === 'bn'
                                                ? '৳৮৪.৫০'
                                                : '৳84.50'}
                                        </div>
                                        <div className="mt-2 font-mono text-[10px] text-zinc-400 dark:text-zinc-500">
                                            {t('welcome.aov_desc')}
                                        </div>
                                    </div>
                                    {/* Stat 3 */}
                                    <div className="dark:border-zinc-850 rounded-2xl border border-slate-200 bg-slate-50 p-4 sm:p-6 dark:bg-zinc-950">
                                        <div className="flex items-start justify-between gap-2">
                                            <span className="text-zinc-550 text-xs font-medium dark:text-zinc-400">
                                                {t('welcome.net_profit_margin')}
                                            </span>
                                            <span className="text-indigo-650 shrink-0 rounded-full bg-indigo-500/10 px-2 py-0.5 text-[10px] font-bold dark:text-indigo-400">
                                                {t('welcome.optimal')}
                                            </span>
                                        </div>
                                        <div className="mt-4 text-2xl font-bold text-zinc-900 sm:text-3xl dark:text-white">
                                            {t('common.locale') === 'bn'
                                                ? '৪২.৮%'
                                                : '42.8%'}
                                        </div>
                                        <div className="mt-2 font-mono text-[10px] text-zinc-400 dark:text-zinc-500">
                                            {t('welcome.npm_desc')}
                                        </div>
                                    </div>

                                    {/* Profit Vector Graph Mockup */}
                                    <div className="dark:border-zinc-850 flex flex-col justify-between rounded-2xl border border-slate-200 bg-slate-50 p-4 sm:p-6 lg:col-span-3 dark:bg-zinc-950">
                                        <div className="mb-6 flex items-center justify-between">
                                            <span className="text-xs font-semibold text-zinc-700 dark:text-zinc-300">
                                                {t('welcome.sales_yield')}
                                            </span>
                                            <div className="flex gap-2">
                                                <span className="h-2 w-2 rounded-full bg-cyan-500 dark:bg-cyan-400" />
                                                <span className="font-mono text-[10px] text-zinc-500 dark:text-zinc-400">
                                                    {t('welcome.earnings_path')}
                                                </span>
                                            </div>
                                        </div>
                                        <div className="relative flex h-48 w-full items-end">
                                            {/* SVG Chart with drawing line */}
                                            <svg
                                                className="h-full w-full"
                                                viewBox="0 0 800 200"
                                                preserveAspectRatio="none"
                                            >
                                                <defs>
                                                    <linearGradient
                                                        id="chartGrad"
                                                        x1="0"
                                                        y1="0"
                                                        x2="0"
                                                        y2="1"
                                                    >
                                                        <stop
                                                            offset="0%"
                                                            stopColor="#06B6D4"
                                                            stopOpacity="0.25"
                                                        />
                                                        <stop
                                                            offset="100%"
                                                            stopColor="#3B82F6"
                                                            stopOpacity="0.0"
                                                        />
                                                    </linearGradient>
                                                </defs>
                                                <path
                                                    d="M0 160 Q 150 140, 250 80 T 500 120 T 800 30"
                                                    fill="none"
                                                    stroke="url(#arrowGrad)"
                                                    strokeWidth="4"
                                                    className="animate-[drawPath_3s_infinite]"
                                                />
                                                <path
                                                    d="M0 160 Q 150 140, 250 80 T 500 120 T 800 30 L 800 200 L 0 200 Z"
                                                    fill="url(#chartGrad)"
                                                />
                                            </svg>
                                        </div>
                                    </div>
                                </motion.div>
                            )}

                            {activeSandboxTab === 'vendors' && (
                                <motion.div
                                    key="vendors"
                                    initial={{ opacity: 0, y: 10 }}
                                    animate={{ opacity: 1, y: 0 }}
                                    exit={{ opacity: 0, y: -10 }}
                                    transition={{ duration: 0.3 }}
                                    className="space-y-6"
                                >
                                    <div className="grid grid-cols-1 gap-6 md:grid-cols-2">
                                        <div className="dark:border-zinc-850 rounded-2xl border border-slate-200 bg-slate-50 p-4 sm:p-6 dark:bg-zinc-950">
                                            <span className="text-zinc-550 text-xs font-medium dark:text-zinc-400">
                                                {t('welcome.accumulated_dues')}
                                            </span>
                                            <div className="mt-4 text-2xl font-bold text-zinc-900 sm:text-3xl dark:text-white">
                                                {t('common.locale') === 'bn'
                                                    ? '৳১,৬৯০.০০'
                                                    : '৳1,690.00'}
                                            </div>
                                            <p className="mt-2 flex items-center gap-1.5 text-[10px] text-rose-600 dark:text-rose-400">
                                                <AlertCircle className="h-3 w-3" />
                                                {t(
                                                    'welcome.dues_action_needed',
                                                    {
                                                        count:
                                                            t(
                                                                'common.locale',
                                                            ) === 'bn'
                                                                ? '২'
                                                                : '2',
                                                    },
                                                )}
                                            </p>
                                        </div>
                                        <div className="dark:border-zinc-850 rounded-2xl border border-slate-200 bg-slate-50 p-4 sm:p-6 dark:bg-zinc-950">
                                            <span className="text-zinc-550 text-xs font-medium dark:text-zinc-400">
                                                {t(
                                                    'welcome.total_vendors_linked',
                                                )}
                                            </span>
                                            <div className="mt-4 text-2xl font-bold text-zinc-900 sm:text-3xl dark:text-white">
                                                {t('welcome.active_count', {
                                                    count:
                                                        t('common.locale') ===
                                                        'bn'
                                                            ? '১২'
                                                            : '12',
                                                })}
                                            </div>
                                            <p className="text-emerald-650 mt-2 flex items-center gap-1.5 text-[10px] dark:text-emerald-400">
                                                <CheckCircle2 className="h-3 w-3" />
                                                {t(
                                                    'welcome.all_pipelines_syncing',
                                                )}
                                            </p>
                                        </div>
                                    </div>

                                    {/* Mock Vendor List */}
                                    <div className="dark:border-zinc-850 overflow-hidden rounded-2xl border border-slate-200 bg-slate-50 dark:bg-zinc-950">
                                        <div className="dark:border-zinc-850 text-zinc-650 border-b border-slate-200 bg-slate-100/50 p-4 text-xs font-semibold dark:bg-zinc-950/20 dark:text-zinc-400">
                                            {t('welcome.priority_settlements')}
                                        </div>
                                        <div className="divide-y divide-slate-100 dark:divide-zinc-900">
                                            {mockVendors.map((vendor, i) => (
                                                <div
                                                    key={i}
                                                    className="flex items-center justify-between gap-4 p-4 transition-colors hover:bg-slate-100/40 dark:hover:bg-zinc-900/30"
                                                >
                                                    <div className="min-w-0 flex-1">
                                                        <div className="truncate text-sm font-semibold text-zinc-900 dark:text-white">
                                                            {vendor.name}
                                                        </div>
                                                        <div className="mt-0.5 text-[10px] text-zinc-400 dark:text-zinc-500">
                                                            {t(
                                                                'welcome.updated_ago',
                                                                {
                                                                    time:
                                                                        t(
                                                                            'common.locale',
                                                                        ) ===
                                                                        'bn'
                                                                            ? '৪ ঘণ্টা'
                                                                            : '4 hours',
                                                                },
                                                            )}
                                                        </div>
                                                    </div>
                                                    <div className="flex shrink-0 items-center gap-3 sm:gap-6">
                                                        <span className="font-mono text-sm font-medium text-zinc-800 dark:text-zinc-300">
                                                            {t(
                                                                'common.locale',
                                                            ) === 'bn'
                                                                ? vendor.dues ===
                                                                  '৳1,240.00'
                                                                    ? '৳১,২৪০.০০'
                                                                    : vendor.dues ===
                                                                        '৳450.00'
                                                                      ? '৳৪৫০.০০'
                                                                      : '৳০.০০'
                                                                : vendor.dues ===
                                                                    '৳1,240.00'
                                                                  ? '৳1,240.00'
                                                                  : vendor.dues ===
                                                                      '৳450.00'
                                                                    ? '৳450.00'
                                                                    : '৳0.00'}
                                                        </span>
                                                        <span
                                                            className={`rounded-full border px-2.5 py-0.5 text-[10px] font-semibold ${vendor.color}`}
                                                        >
                                                            {vendor.status ===
                                                            'Pending'
                                                                ? t(
                                                                      'common.locale',
                                                                  ) === 'bn'
                                                                    ? 'বকেয়া'
                                                                    : 'Pending'
                                                                : t(
                                                                        'common.locale',
                                                                    ) === 'bn'
                                                                  ? 'পরিশোধিত'
                                                                  : 'Settled'}
                                                        </span>
                                                    </div>
                                                </div>
                                            ))}
                                        </div>
                                    </div>
                                </motion.div>
                            )}

                            {activeSandboxTab === 'products' && (
                                <motion.div
                                    key="products"
                                    initial={{ opacity: 0, y: 10 }}
                                    animate={{ opacity: 1, y: 0 }}
                                    exit={{ opacity: 0, y: -10 }}
                                    transition={{ duration: 0.3 }}
                                    className="space-y-6"
                                >
                                    <div className="grid grid-cols-1 gap-6 md:grid-cols-2">
                                        <div className="dark:border-zinc-850 rounded-2xl border border-slate-200 bg-slate-50 p-4 sm:p-6 dark:bg-zinc-950">
                                            <span className="text-zinc-550 text-xs font-medium dark:text-zinc-400">
                                                {t(
                                                    'welcome.top_margin_product',
                                                )}
                                            </span>
                                            <div className="mt-4 text-2xl font-bold text-zinc-900 sm:text-3xl dark:text-white">
                                                {t('welcome.locale') === 'bn'
                                                    ? 'অডিও পডস প্রো'
                                                    : 'Audio Pods Pro'}
                                            </div>
                                            <div className="text-cyan-650 mt-2 font-mono text-[10px] dark:text-cyan-400">
                                                {toLocalDigits('51%')}{' '}
                                                {t('welcome.net_yield_margin')}
                                            </div>
                                        </div>
                                        <div className="dark:border-zinc-850 rounded-2xl border border-slate-200 bg-slate-50 p-4 sm:p-6 dark:bg-zinc-950">
                                            <span className="text-zinc-550 text-xs font-medium dark:text-zinc-400">
                                                {t('welcome.low_stock_warning')}
                                            </span>
                                            <div className="mt-4 text-2xl font-bold text-zinc-900 sm:text-3xl dark:text-white">
                                                {t('welcome.locale') === 'bn'
                                                    ? 'ম্যাগসেফ ডক ম্যাক্স'
                                                    : 'MagSafe Dock Max'}
                                            </div>
                                            <div className="mt-2 font-mono text-[10px] text-rose-600 dark:text-rose-400">
                                                {t('welcome.items_remaining', {
                                                    count: toLocalDigits(15),
                                                })}
                                            </div>
                                        </div>
                                    </div>

                                    {/* Products Catalog ledger */}
                                    <div className="dark:border-zinc-850 overflow-hidden rounded-2xl border border-slate-200 bg-slate-50 dark:bg-zinc-950">
                                        <div className="dark:border-zinc-850 text-zinc-650 border-b border-slate-200 bg-slate-100/50 p-4 text-xs font-semibold dark:bg-zinc-950/20 dark:text-zinc-400">
                                            {t(
                                                'welcome.highest_revenue_inventory',
                                            )}
                                        </div>
                                        <div className="divide-y divide-slate-100 dark:divide-zinc-900">
                                            {mockProducts.map((prod, i) => (
                                                <div
                                                    key={i}
                                                    className="flex items-center justify-between gap-4 p-4 transition-colors hover:bg-slate-100/40 dark:hover:bg-zinc-900/30"
                                                >
                                                    <div className="min-w-0 flex-1">
                                                        <div className="truncate text-sm font-semibold text-zinc-900 dark:text-white">
                                                            {t(
                                                                'welcome.locale',
                                                            ) === 'bn'
                                                                ? prod.name ===
                                                                  'Smartwatch Series X'
                                                                    ? 'স্মার্টওয়াচ সিরিজ এক্স'
                                                                    : prod.name ===
                                                                        'Audio Pods Pro'
                                                                      ? 'অডিও পডস প্রো'
                                                                      : 'ম্যাগসেফ ডক ম্যাক্স'
                                                                : prod.name}
                                                        </div>
                                                        <div className="mt-0.5 text-[10px] text-zinc-400 dark:text-zinc-500">
                                                            {t(
                                                                'welcome.stock_level',
                                                                {
                                                                    count: toLocalDigits(
                                                                        prod.stock,
                                                                    ),
                                                                },
                                                            )}
                                                        </div>
                                                    </div>
                                                    <div className="flex shrink-0 items-center gap-3 sm:gap-6">
                                                        <div className="text-right">
                                                            <div className="text-zinc-550 text-[10px] sm:text-xs dark:text-zinc-400">
                                                                {t(
                                                                    'welcome.yield',
                                                                )}
                                                            </div>
                                                            <div className="text-emerald-650 font-mono text-xs font-semibold sm:text-sm dark:text-emerald-400">
                                                                {toLocalDigits(
                                                                    prod.margin,
                                                                )}
                                                            </div>
                                                        </div>
                                                        <div className="text-right">
                                                            <div className="text-zinc-550 text-[10px] sm:text-xs dark:text-zinc-400">
                                                                {t(
                                                                    'welcome.gross_sales',
                                                                )}
                                                            </div>
                                                            <div className="font-mono text-xs font-semibold text-zinc-800 sm:text-sm dark:text-white">
                                                                {t(
                                                                    'common.locale',
                                                                ) === 'bn'
                                                                    ? prod.revenue ===
                                                                      '৳8,420.00'
                                                                        ? '৳৮,৪২০.০০'
                                                                        : prod.revenue ===
                                                                            '৳12,050.00'
                                                                          ? '৳১২,০৫০.০০'
                                                                          : '৳৪,১০০.০০'
                                                                    : prod.revenue}
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            ))}
                                        </div>
                                    </div>
                                </motion.div>
                            )}
                        </AnimatePresence>
                    </div>
                </div>
            </section>

            {/* Core Features Grid */}
            <section
                id="features"
                className="relative z-10 border-t border-slate-200 bg-white py-20 transition-colors duration-300 lg:py-32 dark:border-zinc-900 dark:bg-zinc-950"
            >
                <div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
                    <div className="mx-auto mb-20 max-w-3xl text-center">
                        <span className="rounded-full border border-violet-200 bg-violet-50 px-3.5 py-1.5 text-xs font-bold tracking-widest text-violet-600 uppercase dark:border-violet-900/30 dark:bg-violet-950/30 dark:text-violet-400">
                            {t('welcome.features_sub')}
                        </span>
                        <h2 className="mt-4 text-3xl leading-none font-bold tracking-tight text-zinc-900 sm:text-5xl dark:text-white">
                            {t('welcome.built_for_resellers')}
                        </h2>
                        <p className="text-zinc-650 mt-4 text-lg font-light dark:text-zinc-400">
                            {t('welcome.built_for_resellers_desc')}
                        </p>
                    </div>

                    {/* Features Matrix */}
                    <div className="grid grid-cols-1 gap-8 md:grid-cols-2 lg:grid-cols-3">
                        {[
                            {
                                icon: TrendingUp,
                                title: t('welcome.net_profit_engine'),
                                desc: t('welcome.net_profit_engine_desc'),
                                color: 'from-violet-500/5 dark:from-violet-500/10 to-transparent hover:border-violet-500/30',
                            },
                            {
                                icon: Coins,
                                title: t('welcome.vendor_settlements'),
                                desc: t('welcome.vendor_settlements_desc'),
                                color: 'from-indigo-500/5 dark:from-indigo-500/10 to-transparent hover:border-indigo-500/30',
                            },
                            {
                                icon: Layers,
                                title: t('welcome.inventory_analytics'),
                                desc: t('welcome.inventory_analytics_desc'),
                                color: 'from-cyan-500/5 dark:from-cyan-500/10 to-transparent hover:border-cyan-500/30',
                            },
                            {
                                icon: Cpu,
                                title: t('welcome.unified_data_sync'),
                                desc: t('welcome.unified_data_sync_desc'),
                                color: 'from-purple-500/5 dark:from-purple-500/10 to-transparent hover:border-purple-500/30',
                            },
                            {
                                icon: ShieldCheck,
                                title: t('welcome.granular_security'),
                                desc: t('welcome.granular_security_desc'),
                                color: 'from-emerald-500/5 dark:from-emerald-500/10 to-transparent hover:border-emerald-500/30',
                            },
                            {
                                icon: Users,
                                title: t('welcome.customer_crm'),
                                desc: t('welcome.customer_crm_desc'),
                                color: 'from-pink-500/5 dark:from-pink-500/10 to-transparent hover:border-pink-500/30',
                            },
                        ].map((feat, i) => {
                            const Icon = feat.icon;

                            return (
                                <div
                                    key={i}
                                    className={`bg-gradient-to-b ${feat.color} group rounded-3xl border border-slate-200 bg-white p-8 transition-all duration-300 hover:translate-y-[-4px] dark:border-zinc-900 dark:bg-zinc-900/30`}
                                >
                                    <div className="group-hover:border-slate-350 mb-6 flex h-12 w-12 items-center justify-center rounded-xl border border-slate-200 bg-slate-50 p-2.5 transition-all duration-300 dark:border-zinc-800 dark:bg-zinc-900 dark:group-hover:border-zinc-700">
                                        <Icon className="text-zinc-555 h-full w-full transition-colors group-hover:text-zinc-900 dark:text-zinc-400 dark:group-hover:text-white" />
                                    </div>
                                    <h3 className="text-lg font-semibold text-zinc-900 transition-colors group-hover:text-cyan-600 dark:text-white dark:group-hover:text-cyan-300">
                                        {feat.title}
                                    </h3>
                                    <p className="text-zinc-650 mt-3 text-sm leading-relaxed font-light dark:text-zinc-400">
                                        {feat.desc}
                                    </p>
                                </div>
                            );
                        })}
                    </div>
                </div>
            </section>

            {/* Premium CTA Panel */}
            <section className="relative overflow-hidden bg-slate-50 py-16 transition-colors duration-300 md:py-24 dark:bg-zinc-950">
                <div className="relative z-10 mx-auto max-w-5xl px-4">
                    <div className="via-slate-55 relative overflow-hidden rounded-3xl border border-slate-200 bg-gradient-to-tr from-violet-100 to-cyan-100 p-8 text-center shadow-2xl transition-colors duration-300 md:p-16 dark:border-violet-900/30 dark:from-violet-950/60 dark:via-slate-900/40 dark:to-cyan-950/60">
                        <div className="bg-grid-black/[0.01] dark:bg-grid-white/[0.01] absolute inset-0 bg-[size:24px]" />
                        <div className="absolute -top-12 -left-12 h-64 w-64 rounded-full bg-violet-500/10 blur-[80px]" />
                        <div className="absolute -right-12 -bottom-12 h-64 w-64 rounded-full bg-cyan-500/10 blur-[80px]" />

                        <div className="relative z-10 mx-auto max-w-2xl space-y-6">
                            <h2 className="font-display text-3xl font-bold tracking-tight text-zinc-900 sm:text-5xl dark:text-white">
                                {t('welcome.maximize_limits')}
                            </h2>
                            <p className="text-zinc-650 text-base leading-relaxed font-light sm:text-lg dark:text-zinc-400">
                                {t('welcome.maximize_limits_desc')}
                            </p>
                            <div className="flex flex-col justify-center gap-3 pt-4 sm:flex-row">
                                <Link
                                    href={
                                        auth.user
                                            ? dashboard().url
                                            : login().url
                                    }
                                    className="rounded-xl bg-zinc-900 px-8 py-4 font-semibold text-white shadow-md shadow-black/5 transition-all hover:bg-zinc-800 dark:bg-white dark:text-zinc-950 dark:shadow-white/5 dark:hover:bg-zinc-200"
                                >
                                    {t('welcome.access_cockpit_now')}
                                </Link>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            {/* Footer */}
            <footer className="relative z-10 mt-auto w-full border-t border-slate-200 bg-white py-12 transition-colors duration-300 dark:border-zinc-900 dark:bg-zinc-950">
                <div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
                    <div className="mb-12 grid grid-cols-1 gap-8 md:grid-cols-4">
                        {/* Brand info */}
                        <div className="space-y-4">
                            <div className="flex items-center gap-2.5">
                                <div className="flex h-7 w-7 items-center justify-center rounded-lg border border-slate-200 bg-slate-50 p-1 dark:border-zinc-800 dark:bg-zinc-900">
                                    <AppLogoIcon className="h-full w-full" />
                                </div>
                                <span className="font-display text-lg font-semibold text-zinc-900 dark:text-white">
                                    Profitly
                                </span>
                            </div>
                            <p className="text-xs font-light text-zinc-500">
                                {t('welcome.footer_desc')}
                            </p>
                        </div>

                        {/* Links col 1 */}
                        <div>
                            <h4 className="dark:text-zinc-450 mb-4 text-xs font-semibold tracking-widest text-zinc-700 uppercase">
                                {t('welcome.platform')}
                            </h4>
                            <ul className="space-y-2 text-xs text-zinc-500">
                                <li>
                                    <button
                                        onClick={(e) =>
                                            scrollToSection(e, 'features')
                                        }
                                        className="cursor-pointer border-0 bg-transparent p-0 text-left transition-colors hover:text-zinc-900 dark:hover:text-white"
                                    >
                                        {t('welcome.features')}
                                    </button>
                                </li>
                                <li>
                                    <button
                                        onClick={(e) =>
                                            scrollToSection(
                                                e,
                                                'dashboard-preview',
                                            )
                                        }
                                        className="cursor-pointer border-0 bg-transparent p-0 text-left transition-colors hover:text-zinc-900 dark:hover:text-white"
                                    >
                                        {t('welcome.interactive_demo')}
                                    </button>
                                </li>
                                <li>
                                    <Link
                                        href={login().url}
                                        className="transition-colors hover:text-zinc-900 dark:hover:text-white"
                                    >
                                        {t('welcome.login_portal')}
                                    </Link>
                                </li>
                            </ul>
                        </div>

                        {/* Links col 2 */}
                        <div>
                            <h4 className="dark:text-zinc-450 mb-4 text-xs font-semibold tracking-widest text-zinc-700 uppercase">
                                {t('welcome.resources')}
                            </h4>
                            <ul className="space-y-2 text-xs text-zinc-500">
                                <li>
                                    <a
                                        href="https://laravel.com"
                                        target="_blank"
                                        className="transition-colors hover:text-zinc-900 dark:hover:text-white"
                                    >
                                        {t('welcome.laravel_core')}
                                    </a>
                                </li>
                                <li>
                                    <a
                                        href="https://react.dev"
                                        target="_blank"
                                        className="transition-colors hover:text-zinc-900 dark:hover:text-white"
                                    >
                                        {t('welcome.react_engine')}
                                    </a>
                                </li>
                            </ul>
                        </div>

                        {/* Links col 3 */}
                        <div>
                            <h4 className="dark:text-zinc-450 mb-4 text-xs font-semibold tracking-widest text-zinc-700 uppercase">
                                {t('welcome.security')}
                            </h4>
                            <ul className="space-y-2 text-xs text-zinc-500">
                                <li>
                                    <span className="dark:text-zinc-650 text-zinc-400">
                                        {t('welcome.rbac_config')}
                                    </span>
                                </li>
                                <li>
                                    <span className="dark:text-zinc-650 text-zinc-400">
                                        {t('welcome.action_logs_audit')}
                                    </span>
                                </li>
                                <li>
                                    <span className="dark:text-zinc-650 text-zinc-400">
                                        {t('welcome.data_cryptography')}
                                    </span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <div className="text-zinc-450 flex flex-col items-center justify-between gap-4 border-t border-slate-200 pt-8 text-xs font-light sm:flex-row dark:border-zinc-900 dark:text-zinc-600">
                        <p>
                            &copy; {toLocalDigits(new Date().getFullYear())}{' '}
                            {t('welcome.all_rights_reserved')}
                        </p>
                        <div className="flex gap-4">
                            <span className="cursor-pointer hover:text-zinc-600 dark:hover:text-zinc-500">
                                {t('welcome.privacy_policy')}
                            </span>
                            <span className="cursor-pointer hover:text-zinc-600 dark:hover:text-zinc-500">
                                {t('welcome.terms_of_service')}
                            </span>
                        </div>
                    </div>
                </div>
            </footer>
            <Toaster />
        </div>
    );
}
