diff --git a/app/src/lib/status.ts b/app/src/lib/status.ts new file mode 100644 index 0000000..c1a7c7a --- /dev/null +++ b/app/src/lib/status.ts @@ -0,0 +1,26 @@ +import type { OrderStatus } from "@/data/mock"; + +export type StatusColor = "default" | "accent" | "success" | "warning" | "danger"; + +export interface StatusInfo { + label: string; + color: StatusColor; +} + +const ORDER_STATUS_INFO: Record = { + AwaitingConfirm: { label: "Awaiting Confirm", color: "warning" }, + Active: { label: "Active", color: "accent" }, + Complete: { label: "Complete", color: "success" }, + Cancelled: { label: "Cancelled", color: "default" }, + Disputed: { label: "Disputed", color: "danger" }, +}; + +export function orderStatusInfo(status: OrderStatus): StatusInfo { + return ORDER_STATUS_INFO[status]; +} + +export function availabilityInfo(qty: number): StatusInfo { + if (qty === 0) return { label: "Out of Stock", color: "default" }; + if (qty <= 3) return { label: `Only ${qty} left!`, color: "warning" }; + return { label: `${qty} in stock`, color: "success" }; +}