diff --git a/src/components/order-item-context-panel.tsx b/src/components/order-item-context-panel.tsx new file mode 100644 index 0000000..c143440 --- /dev/null +++ b/src/components/order-item-context-panel.tsx @@ -0,0 +1,231 @@ +"use client"; + +import { useCallback, useEffect, useState } from "react"; +import { + ChevronDown, + ChevronUp, + History, + Loader2, + Package, + Receipt, + ShoppingBag, +} from "lucide-react"; +import { cn } from "@/lib/utils"; +import type { OrderItemContextResponse } from "@/lib/server/order-item-context-service"; + +export interface ApplyPayload { + source: "last_quote" | "last_order" | "last_invoiced" | "stock"; + cost_price: number; + supplier_id?: string; + source_label: string; +} + +interface Props { + itemId: string; + defaultOpen?: boolean; + onApply: (payload: ApplyPayload) => void; +} + +const round2 = (n: number) => Math.round(n * 100) / 100; + +function relTime(daysAgo: number): string { + if (daysAgo < 1) return "today"; + if (daysAgo === 1) return "1d"; + if (daysAgo < 30) return `${daysAgo}d`; + const mo = Math.round(daysAgo / 30); + return `${mo}mo`; +} + +interface RowProps { + label: string; + icon: React.ReactNode; + badge: string; + cost: number; + selling: number | null; + markup: number | null; + sellingDimmed?: boolean; + applyDisabled?: boolean; + onApply?: () => void; +} + +function Row({ label, icon, badge, cost, selling, markup, sellingDimmed, applyDisabled, onApply }: RowProps) { + return ( +