'use client'; import { ArrowRight, TrendingUp, DollarSign, Activity, PackageCheck, Users, Boxes, Building2, Layers, } from 'lucide-react'; import { ComposedChart, Bar, Area, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, } from 'recharts'; import { DashboardRevenuePoint, DashboardMonthlyPoint, } from '@/services/api/adminService'; import { cn } from '@/lib/utils'; import Link from 'next/link'; import { DashboardHeaderNav } from '@/components/dashboard/DashboardHeaderNav'; import { useDashboardData } from '@/components/dashboard/useDashboardData'; import { CARD, formatCompact, formatInr, samplePoints, CardTitle, PeriodPills, DeltaPill, } from '@/components/dashboard/DashboardShared'; export default function ExecutiveDashboardPage() { const { stats: displayStats, loading, refreshing, userName, chartMode, setChartMode, fetchData, } = useDashboardData(); const byStatus = displayStats.orders_by_status ?? {}; const countOf = (key: string) => byStatus[key] ?? 0; const totalOrders = displayStats.total_orders ?? 0; const delivered = countOf('delivered'); const conversion = totalOrders > 0 ? (delivered / totalOrders) * 100 : 0; const conversionDelta = 15.5; const daily: DashboardRevenuePoint[] = displayStats.revenue_chart_daily ?? []; const monthly: DashboardMonthlyPoint[] = displayStats.revenue_chart_monthly ?? []; const sourceChart: Array = chartMode === 'weekly' ? samplePoints(daily, 12) : monthly; const rawPoints = sourceChart.map((row) => ({ name: 'date' in row ? row.date?.replace('08-', '') ?? '' : row.label?.slice(0, 3) ?? '', revenue: row.revenue, orders: row.orders, })); const maxRev = Math.max(...rawPoints.map((row) => row.revenue), 1); const maxOrd = Math.max(...rawPoints.map((row) => row.orders), 1); const salesScale = (maxRev * 0.72) / maxOrd; const chartPoints = rawPoints.map((row) => ({ ...row, sales: row.orders * salesScale, })); if (loading) { return (
{[...Array(4)].map((_, i) => (
))}
); } return (
fetchData(true)} /> {/* KPI Cards Row */}

Gross Revenue (All Time)

{formatInr(displayStats.revenue_all_time)}

Target Exceeded

30-Day Enterprise Run-Rate

{formatInr(displayStats.revenue_last_30_days)}

Vs previous month

Average Order Value (AOV)

{formatInr(displayStats.revenue_all_time / Math.max(totalOrders, 1))}

Order basket size gain

Gross Fulfillment Rate

{conversion.toFixed(1)}%

Delivered vs Total
{/* Analytics & Portfolio Scope */}
Executive Revenue Analytics & Projections

{formatCompact(displayStats.revenue_last_30_days).replace('₹', '')}

30-Day Consolidated Turnover (INR)

(v >= 1000 ? `₹${(v / 1000).toFixed(0)}k` : `₹${v}`)} /> { if (!active || !payload?.length) return null; const row = payload[0]?.payload as { revenue: number; orders: number }; return (

{label}

{formatInr(row.revenue)}

{row.orders} corporate transactions

); }} />
Enterprise Portfolio Scope

Total Customer Accounts

{displayStats.total_users}

Product Portfolio

{displayStats.total_products} SKUs

{displayStats.total_stock_units} Units

Partner Brands

{displayStats.total_brands} Brands

{displayStats.total_categories} Categories

Supported Devices

{displayStats.total_device_models} Models

{displayStats.total_device_series} Series
{/* Transaction Ledger Table */}
Executive Transaction Ledger Audit Full Orders
{(displayStats.recent_orders ?? []).map((order) => ( ))}
Order Ref Client / Customer Transaction Value Fulfillment Stage Priority
{order.order_no} {order.customer_name} {formatInr(order.amount)} {order.status} High Priority
); }