"use client" import { useState, useEffect } from "react" import OrderStats from "./order-stats" import QuickActions from "./quick-actions" import RecentActivity from "./recent-activity" import { getGreeting } from "@/lib/utils/general" import { statsConfig } from "@/config/dashboard" import { getRandomQuote } from "@/config/quotes" import type { OrderStatsData } from "@/lib/types" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { ShoppingCart, RefreshCcw, ArrowRight } from "lucide-react" import { Button } from "@/components/ui/button" import { useToast } from "@/components/ui/use-toast" import { Skeleton } from "@/components/ui/skeleton" import { clientFetch } from "@/lib/api" import { motion } from "framer-motion" import Link from "next/link" interface ContentProps { username: string orderStats: OrderStatsData } interface TopProduct { id: string; name: string; price: number | number[]; image: string; count: number; revenue: number; } export default function Content({ username, orderStats }: ContentProps) { const [greeting, setGreeting] = useState(""); const [topProducts, setTopProducts] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const { toast } = useToast(); const [randomQuote, setRandomQuote] = useState(getRandomQuote()); const fetchTopProducts = async () => { try { setIsLoading(true); const data = await clientFetch('/orders/top-products'); setTopProducts(data); } catch (err) { console.error("Error fetching top products:", err); setError(err instanceof Error ? err.message : "Failed to fetch top products"); } finally { setIsLoading(false); } }; useEffect(() => { setGreeting(getGreeting()); fetchTopProducts(); }, []); const handleRetry = () => { fetchTopProducts(); }; return (

{greeting}, {username}!

"{randomQuote.text}" — {randomQuote.author}

{/* Quick ActionsSection */}

Quick Actions

{/* Order Statistics */}

Overview

{statsConfig.map((stat, index) => ( ))}
{/* Recent Activity Section */}
{/* Best Selling Products Section */}
Top Performing Listings Your products with the highest sales volume
{error && ( )}
{isLoading ? (
{[...Array(5)].map((_, i) => (
))}
) : error ? (
Failed to load product insights
) : topProducts.length === 0 ? (

Begin your sales journey

Your top performing listings will materialize here as you receive orders.

) : (
{topProducts.map((product, index) => (
{!product.image && ( )}

{product.name}

£{(Number(Array.isArray(product.price) ? product.price[0] : product.price) || 0).toFixed(2)}
{product.count}
Units Sold
£{product.revenue.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
))}
)}
); }