"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { Package, QrCode, Boxes, ScanLine, ShieldCheck, CheckCircle2, FileText, Bell, Plus, BarChart3, Layers, ArrowUpRight, } from "lucide-react"; import { KpiCard, KpiSkeleton } from "@/components/KpiCard"; import ScanTrendChart from "@/components/ScanTrendChart"; import { api } from "@/lib/api"; const INDIA_DOTS = [ [62, 42], [55, 52], [48, 30], [58, 70], [60, 58], [44, 46], ]; export default function DashboardPage() { const [s, setS] = useState(null); const [trend, setTrend] = useState([]); const [topP, setTopP] = useState([]); const [topL, setTopL] = useState([]); const [activity, setActivity] = useState([]); useEffect(() => { api("/dashboard/summary").then(setS).catch(() => {}); api("/dashboard/scan-trend?days=7").then(setTrend).catch(() => {}); api("/dashboard/top-products").then(setTopP).catch(() => {}); api("/dashboard/top-locations").then(setTopL).catch(() => {}); api("/dashboard/recent-activity").then(setActivity).catch(() => {}); }, []); const maxP = Math.max(1, ...topP.map((p) => p.scans)); return (
{/* KPI row 1 */}
{!s ? ( [...Array(4)].map((_, i) => ) ) : ( <> } tint="bg-blue-50 text-blue-600" /> } tint="bg-emerald-50 text-emerald-600" /> } tint="bg-violet-50 text-violet-600" /> } tint="bg-orange-50 text-orange-500" /> )}
{/* KPI row 2 */}
{!s ? ( [...Array(4)].map((_, i) => ) ) : ( <> } tint="bg-blue-50 text-blue-600" /> } tint="bg-emerald-50 text-emerald-600" /> } tint="bg-amber-50 text-amber-500" /> } tint="bg-rose-50 text-rose-500" /> )}
{/* Charts row */}

Scan Trend

This Week

Top Products (By Scans)

{topP.map((p) => (
{p.name}
{p.scans}
))} {topP.length === 0 &&
No scan data yet.
}
View All Products

Top Locations (By Scans)

{INDIA_DOTS.map(([x, y], i) => ( ))}
    {topL.map((l, i) => (
  1. {i + 1}. {l.city} {l.scans}
  2. ))} {topL.length === 0 &&
  3. No locations yet.
  4. }
{/* Activity + Quick actions */}

Recent Activity

View All
{activity.map((a, i) => (
{a.action?.replace(".", " ")}
{a.details}
{a.user}
{a.at ? new Date(a.at).toLocaleString() : ""}
))} {activity.length === 0 &&
No recent activity.
}

Quick Actions

} label="Add Product" tint="bg-blue-600 text-white" /> } label="Generate QR" tint="bg-emerald-50 text-emerald-600" /> } label="Add Batch" tint="bg-violet-50 text-violet-600" /> } label="View Analytics" tint="bg-amber-50 text-amber-600" /> } label="Compliance" tint="bg-rose-50 text-rose-500" /> } label="Settings" tint="bg-slate-100 text-slate-600" />
); } function QuickAction({ href, icon, label, tint }: any) { return (
{icon}
{label} ); }