"use client" import { useState, useEffect } from "react" import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription } from "@/components/common/sheet" import { clientFetch } from "@/lib/api" import { Badge } from "@/components/common/badge" import { Separator } from "@/components/common/separator" import { ScrollArea } from "@/components/common/scroll-area" import { ShoppingCart, TrendingUp, BarChart3, Package, History, ExternalLink, AlertCircle } from "lucide-react" import { formatGBP } from "@/lib/utils/format" import Link from "next/link" import { Button } from "@/components/common/button" import { Skeleton } from "@/components/common/skeleton" interface ProductPeekProps { productId: string | null open: boolean onOpenChange: (open: boolean) => void } export function ProductPeek({ productId, open, onOpenChange }: ProductPeekProps) { const [product, setProduct] = useState(null) const [loading, setLoading] = useState(false) useEffect(() => { if (open && productId) { fetchProductDetails() } }, [open, productId]) const fetchProductDetails = async () => { setLoading(true) try { // In this app, productId might be the ID used in the list, // which corresponds to the mongo _id or a semantic ID. const data = await clientFetch(`/products/${productId}`) setProduct(data) } catch (error) { console.error("Failed to fetch product details for peek:", error) } finally { setLoading(false) } } return (
Product Insight {product && ( onOpenChange(false)}> )}
{loading ? : product ? product.name : "Loading..."}
{loading ? (
) : product ? (
{/* Product Visual & Basic Info */}
{product.type || "Physical"}

{product.name}

{/* Inventory Stats */}
Current Stock
{product.currentStock || 0} {(product.currentStock || 0) <= 5 && }
Unit Type
{product.unitType || "Units"}
{/* Analytics Section */}

Performance Metrics

Type {product.type || "Physical"}
Rating
{"★".repeat(Math.round(product.rating || 5))}
({product.rating || "5.0"})
{/* Status & Settings */}

Market Visibility

Active Listing

This product is currently visible to all buyers.

{/* Quick Actions */}
onOpenChange(false)} className="w-full">
) : (
Failed to load product details.
)} ) }