// ─── Types ────────────────────────────────────────────────────────────────────

export type OrderStatus =
  | "pending"
  | "confirmed"
  | "processing"
  | "shipped"
  | "delivered"
  | "cancelled"
  | "refunded"
  | "return"
  | "completed"

export type PaymentStatus = "pending" | "paid" | "failed" | "refunded"

export type OrderEventType =
  | "status_change"
  | "label_created"
  | "tracking_update"
  | "customer_cancel"
  | "return_requested"
  | "return_received"
  | "return_accepted"
  | "refund"

type BadgeVariant = "default" | "secondary" | "destructive" | "outline"

interface StatusConfig {
  label: string
  variant: BadgeVariant
  className?: string
}

// ─── Order status ─────────────────────────────────────────────────────────────

export const ORDER_STATUS_CONFIG: Record<OrderStatus, StatusConfig> = {
  pending: { label: "Pending", variant: "secondary" },
  confirmed: {
    label: "Confirmed",
    variant: "outline",
    className: "border-blue-500 text-blue-600",
  },
  processing: {
    label: "Processing",
    variant: "outline",
    className: "border-violet-500 text-violet-600",
  },
  shipped: {
    label: "Shipped",
    variant: "outline",
    className: "border-indigo-500 text-indigo-600",
  },
  delivered: {
    label: "Delivered",
    variant: "default",
    className: "bg-green-600",
  },
  cancelled: { label: "Cancelled", variant: "destructive" },
  refunded: {
    label: "Refunded",
    variant: "secondary",
    className: "line-through",
  },
  return: {
    label: "Return Requested",
    variant: "outline",
    className: "border-orange-500 text-orange-600",
  },
  completed: {
    label: "Completed",
    variant: "default",
    className: "bg-teal-600",
  },
}

// ─── Payment status ───────────────────────────────────────────────────────────

export const PAYMENT_STATUS_CONFIG: Record<PaymentStatus, StatusConfig> = {
  pending: { label: "Pending", variant: "secondary" },
  paid: { label: "Paid", variant: "default", className: "bg-green-600" },
  failed: { label: "Failed", variant: "destructive" },
  refunded: { label: "Refunded", variant: "secondary" },
}

// ─── Timeline event labels ────────────────────────────────────────────────────

export const EVENT_TYPE_LABELS: Record<OrderEventType, string> = {
  status_change: "Status changed",
  label_created: "Shipping label created",
  tracking_update: "Tracking update",
  customer_cancel: "Customer requested cancellation",
  return_requested: "Customer requested return",
  return_received: "Return marked as received",
  return_accepted: "Return accepted — label created",
  refund: "Refund issued",
}

// ─── Timeline dot color (status_change events only) ───────────────────────────
// Neutral dot for all other event types.

export const TIMELINE_DOT_COLOR: Partial<Record<OrderStatus, string>> = {
  confirmed: "text-blue-500",
  processing: "text-violet-500",
  shipped: "text-indigo-500",
  delivered: "text-green-600",
  cancelled: "text-destructive",
  refunded: "text-muted-foreground",
  return: "text-orange-500",
  completed: "text-teal-600",
}
