"use client" import { useEffect, useState } from "react" import { Package, ShoppingCart, Users, TrendingUp, Loader2, ArrowUpRight, Clock, CheckCircle2, DollarSign, AlertCircle } from "lucide-react" import Link from "next/link" import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell } from "recharts" export default function SupplierDashboardPage() { const [stats, setStats] = useState({ totalProducts: 0, activeOrders: 0, connectedVendors: 0, totalRevenue: 0, pendingConnections: 0, recentProducts: 0, averageProductPrice: 0, recentConnections: 0 }) const [loading, setLoading] = useState(true) const [error, setError] = useState("") useEffect(() => { fetchDashboardData() }, []) const fetchDashboardData = async () => { try { setLoading(true) const [profileRes, analyticsRes, ordersRes] = await Promise.all([ fetch("/api/supplier/profile").catch(() => null), fetch("/api/supplier/analytics").catch(() => null), fetch("/api/supplier/orders").catch(() => null) ]) const profileData = profileRes?.ok ? await profileRes.json().catch(() => ({})) : {} const analyticsData = analyticsRes?.ok ? await analyticsRes.json().catch(() => ({})) : {} const ordersData = ordersRes?.ok ? await ordersRes.json().catch(() => ({})) : {} setStats({ totalProducts: analyticsData?.stats?.totalProducts || 0, activeOrders: ordersData?.orders?.length || 0, connectedVendors: analyticsData?.stats?.connectedVendors || 0, totalRevenue: 0, pendingConnections: analyticsData?.stats?.pendingConnections || 0, recentProducts: analyticsData?.stats?.recentProducts || 0, averageProductPrice: analyticsData?.stats?.averageProductPrice || 0, recentConnections: analyticsData?.stats?.recentConnections || 0 }) setError("") } catch { setError("Failed to load dashboard data") } finally { setLoading(false) } } return (

Supplier Dashboard

Welcome to your supplier portal

{error && (
{error}
)} {loading ? (
) : ( <> {/* Stats Grid */}

{stats.totalProducts}

Total Products

{stats.activeOrders}

Active Orders

{stats.connectedVendors}

Connected Vendors

${stats.totalRevenue.toFixed(2)}

Total Revenue

{/* Additional Stats */}

{stats.pendingConnections}

Pending Connections

${stats.averageProductPrice.toFixed(2)}

Avg. Product Price

{/* Quick Actions & Recent Activity */}

Quick Actions

Common tasks and shortcuts

Add New Product View Vendor Connections View Orders

Recent Activity (7 days)

{stats.pendingConnections > 0 && (

{stats.pendingConnections} pending connection{stats.pendingConnections !== 1 ? "s" : ""}

Review now →
)} {stats.recentProducts > 0 && (

{stats.recentProducts} new product{stats.recentProducts !== 1 ? "s" : ""} added

View products →
)} {stats.recentConnections > 0 && (

{stats.recentConnections} new connection{stats.recentConnections !== 1 ? "s" : ""}

View vendors →
)} {stats.pendingConnections === 0 && stats.recentProducts === 0 && stats.recentConnections === 0 && (

No recent activity

)}
{/* Performance Overview */}

Performance Overview

Key metrics at a glance.

{ const num = typeof value === "number" ? value : Number(value) return [Number.isFinite(num) ? num : 0, "Count"] }} /> {[0, 1, 2, 3].map((i) => ( ))}

Products, connected vendors, pending connections, and new activity (last 7 days)

)}
) }