import { useMemo, useState } from "react" import { Link, useNavigate } from "react-router-dom" import { ArrowRight, BarChart3, CheckCircle2, Clock3, Command, Globe2, Layers3, Moon, ShieldCheck, Sparkles, Sun, TimerReset, Waypoints, } from "lucide-react" import { toast } from "sonner" import { Button } from "../components/ui/button" import { useTheme } from "../components/ThemeProvider" import { useTranslation } from "../hooks/useTranslation" import { cn } from "../lib/utils" import { startDemo } from "../api/demo" import { setDemoSessionMeta, setSessionTokens } from "../lib/session" const formatNumber = (value: number, lang: "en" | "fa") => new Intl.NumberFormat(lang === "fa" ? "fa-IR" : "en-US").format(value) export default function Landing() { const navigate = useNavigate() const { t, lang, setLanguage } = useTranslation() const { theme, setTheme } = useTheme() const [isStartingDemo, setIsStartingDemo] = useState(false) const isAuthenticated = typeof window !== "undefined" && !!localStorage.getItem("accessToken") const isDarkMode = theme === "dark" || (theme === "system" && document.documentElement.classList.contains("dark")) const metrics = useMemo( () => [ { value: lang === "fa" ? "۹۸٪" : "98%", label: t.landing.metrics.capture, tone: "from-cyan-500/20 to-cyan-500/5 text-cyan-700 dark:text-cyan-200", }, { value: lang === "fa" ? "۴.۶×" : "4.6x", label: t.landing.metrics.visibility, tone: "from-emerald-500/20 to-emerald-500/5 text-emerald-700 dark:text-emerald-200", }, { value: lang === "fa" ? "< ۲m" : "< 2m", label: t.landing.metrics.decision, tone: "from-amber-500/20 to-amber-500/5 text-amber-700 dark:text-amber-200", }, ], [lang, t.landing.metrics], ) const capabilityCards = useMemo( () => [ { icon: TimerReset, title: t.landing.capabilities.time.title, description: t.landing.capabilities.time.description, }, { icon: BarChart3, title: t.landing.capabilities.reports.title, description: t.landing.capabilities.reports.description, }, { icon: ShieldCheck, title: t.landing.capabilities.control.title, description: t.landing.capabilities.control.description, }, ], [t.landing.capabilities], ) const workflow = useMemo( () => [ t.landing.workflow.capture, t.landing.workflow.structure, t.landing.workflow.improve, ], [t.landing.workflow], ) const ctaTarget = isAuthenticated ? "/timesheet" : "/auth" const handleStartDemo = async () => { if (isStartingDemo) return setIsStartingDemo(true) try { const demo = await startDemo() setSessionTokens(demo.access, demo.refresh) setDemoSessionMeta(demo.expires_at) toast.success(t.demo?.started || "Demo environment is ready.") navigate("/timesheet") } catch (error) { console.error(error) toast.error(t.demo?.startError || "Could not start the demo environment.") } finally { setIsStartingDemo(false) } } return (
{t.landing.hero.description}
{description}
{t.landing.workflowDescription}
{t.landing.finalCtaDescription}