"use client"; import { useMemo, useState } from "react"; import type { Shipment } from "@/payload-types"; import { ShipmentCard } from "@/components/frontend/logistics/ShipmentCard"; import { Button } from "@/components/ui/button"; import { usePageCommands } from "@/components/command-palette/CommandPaletteContext"; import { CheckCircleIcon, ClockIcon, ListFilterIcon, TruckIcon, XCircleIcon } from "lucide-react"; import { isShipmentActive } from "@/lib/shipping/client"; const statusFilters = [ { label: "All", value: null }, { label: "Active", value: "active" }, { label: "Completed", value: "completed" }, { label: "Cancelled", value: "cancelled" }, { label: "Stranded", value: "stranded" }, ]; interface ShipmentsListProps { shipments: Shipment[]; } export function ShipmentsList({ shipments }: ShipmentsListProps) { const [filter, setFilter] = useState(null); usePageCommands([ { id: "shipments:filter-all", group: "Shipments", label: "Filter: All Shipments", icon: ListFilterIcon, keywords: ["filter", "all", "shipments"], onSelect: () => setFilter(null), }, { id: "shipments:filter-active", group: "Shipments", label: "Filter: Active Shipments", icon: ClockIcon, keywords: ["filter", "active", "in transit", "pending"], onSelect: () => setFilter("active"), }, { id: "shipments:filter-completed", group: "Shipments", label: "Filter: Completed Shipments", icon: CheckCircleIcon, keywords: ["filter", "completed", "arrived", "done"], onSelect: () => setFilter("completed"), }, { id: "shipments:filter-cancelled", group: "Shipments", label: "Filter: Cancelled Shipments", icon: XCircleIcon, keywords: ["filter", "cancelled", "failed"], onSelect: () => setFilter("cancelled"), }, { id: "shipments:filter-stranded", group: "Shipments", label: "Filter: Stranded Shipments", icon: TruckIcon, keywords: ["filter", "stranded", "stuck"], onSelect: () => setFilter("stranded"), }, ]); const filtered = useMemo(() => { if (!filter) return shipments; if (filter === "active") { return shipments.filter((s) => isShipmentActive(s)); } return shipments.filter((s) => s.status === filter); }, [shipments, filter]); return (
{statusFilters.map((f) => ( ))}
{filtered.length === 0 ? (

No shipments found.

) : (
{filtered.map((shipment) => ( ))}
)}
); }