/**
 * Cart page — line items grouped by supplier, plus shipping method and
 * landed-cost estimate.
 *
 * Verified against Figma: file `kWz5egPHGT4CwDugoNIbLC`, frame `2:13598`
 * (" Dk bazar cart checkout page"). Copy, prices, geometry and colours here
 * are read from that file, not estimated from a screenshot — which is what
 * the first pass did. Note this is a *different* file key from the one
 * PROJECT_CONTEXT records for the home page (`hvMlVuumQTIvfqXEILfCnN`).
 *
 * The design's two supplier cards are identical in content (same
 * supplier name, same two line items) apart from the second one also
 * carrying a third, unavailable line — reproduced as-is rather than
 * inventing a second distinct supplier, since that's what's actually in
 * the source. Likewise the sidebar's numbers (Items / courier / freight /
 * customs / total) are the screenshot's own figures; they don't net out to
 * a sum of the two group subtotals, which only means the mock data behind
 * the screenshot wasn't itself internally consistent — reproduced verbatim
 * rather than "corrected" into a formula that isn't shown anywhere.
 */

const PAY = "/footer/payments";

export type CartStepStatus = "done" | "current" | "upcoming";

export type CartStep = {
  id: string;
  label: string;
  status: CartStepStatus;
};

export const cartSteps: CartStep[] = [
  { id: "cart", label: "Cart", status: "done" },
  { id: "shipping-payment", label: "Shipping & Payment", status: "current" },
  { id: "confirmation", label: "Confirmation", status: "upcoming" },
];

export const cartBanner = {
  title: "One total, no surprises.",
  body: "Every line below product, China domestic courier, and international freight rolls into the single landed cost on the right. Nothing gets added later at checkout.",
};

export type ShippingMethodId = "sea-cargo" | "air-standard" | "air-express";

export type ShippingMethodOption = {
  id: ShippingMethodId;
  label: string;
  rate: string;
  transit: string;
};

export const shippingMethodOptions: ShippingMethodOption[] = [
  { id: "sea-cargo", label: "Sea Cargo", rate: "৳420/kg", transit: "25–30 days" },
  { id: "air-standard", label: "Air Standard", rate: "৳800/kg", transit: "10–15 days" },
  { id: "air-express", label: "Air Express", rate: "৳1,150/kg", transit: "5–7 days" },
];

export type CartLineItem = {
  id: string;
  name: string;
  variant: string;
  quantity: number;
  /** Per-unit price — the row's line total is `price * quantity`, computed
   * at render so the quantity stepper stays live. */
  price: number;
  /** Real product photo, recovered from Figma's image-fill map. The design
   * pairs one shot per packaging variant: hard-case rows use the folded
   * multi-tool, the white-box row the fanned-open knife. */
  image: string;
  unavailable?: boolean;
};

const ART = "/cart";
/** 800x800, used on every "Hard case packaging" row. */
const HARD_CASE_IMG = `${ART}/pliers-multi.png`;
/** 900x1198 — portrait, so it is drawn `object-contain` inside the square tile. */
const WHITE_BOX_IMG = `${ART}/pliers-open.png`;

export type SupplierGroup = {
  id: string;
  supplierLabel: string;
  supplierName: string;
  destination: string;
  defaultShippingMethodId: ShippingMethodId;
  /** Group subtotal incl. that seller's China courier + freight leg. */
  subtotal: number;
  items: CartLineItem[];
};

export const supplierGroups: SupplierGroup[] = [
  {
    id: "ningbo-tool-co-1",
    supplierLabel: "Verified Supplier",
    supplierName: "Ningbo Tool Co.",
    destination: "To Dhaka, BD",
    defaultShippingMethodId: "sea-cargo",
    subtotal: 3151.6,
    items: [
      {
        id: "folding-multitool-pliers-hardcase",
        name: "Folding Multi-Tool Pliers Camping & Outdoor",
        variant: "Hard case packaging",
        quantity: 1,
        price: 758,
        image: HARD_CASE_IMG,
      },
      {
        // 2,875 / 3 units in the screenshot — kept as a per-unit price
        // rather than rounded to a cleaner number, so the displayed line
        // total still reconciles at qty 3.
        id: "folding-multitool-pliers-whitebox",
        name: "Folding Multi-Tool Pliers Camping & Outdoor",
        variant: "White box packaging x 3",
        quantity: 3,
        price: 958.33,
        image: WHITE_BOX_IMG,
      },
    ],
  },
  {
    id: "ningbo-tool-co-2",
    supplierLabel: "Verified Supplier",
    supplierName: "Ningbo Tool Co.",
    destination: "To Dhaka, BD",
    defaultShippingMethodId: "sea-cargo",
    subtotal: 3151.6,
    items: [
      {
        id: "folding-multitool-pliers-hardcase-2",
        name: "Folding Multi-Tool Pliers Camping & Outdoor",
        variant: "Hard case packaging",
        quantity: 1,
        price: 758,
        image: HARD_CASE_IMG,
      },
      {
        id: "folding-multitool-pliers-whitebox-2",
        name: "Folding Multi-Tool Pliers Camping & Outdoor",
        variant: "White box packaging x 3",
        quantity: 3,
        price: 958.33,
        image: WHITE_BOX_IMG,
      },
      {
        id: "folding-multitool-pliers-hardcase-3",
        name: "Folding Multi-Tool Pliers Camping & Outdoor",
        variant: "Hard case packaging",
        quantity: 1,
        price: 758,
        image: HARD_CASE_IMG,
        unavailable: true,
      },
    ],
  },
];

export const shippingEstimate = {
  destination: "Delivering to Dhaka, Bangladesh",
  unavailableNotice: "1 item unavailable— not included in this total",
  rows: [
    { label: "Items (4 of 5)", value: 4110.0 },
    { label: "China domestic courier", value: 305.9 },
    { label: "International freight", value: 650.9 },
    { label: "Customs & duty (est.)", value: 180.0 },
  ],
  totalLabel: "Shipping estimate",
  total: 5246.8,
  note: "Final duty confirmed at customs clearance — you'll never pay more than this estimate ±5%.",
};

export type CartPaymentIcon = { id: string; name: string; image: string; w: number; h: number };

// The design's own six, in its own order and at its own box sizes (Figma
// nodes 2:15389/15413/15390/15391/15403/15404). An earlier guess had Upay
// here and no Nagad; Nagad is in fact present but authored as vector paths
// rather than an image fill, so it was exported from the render endpoint
// instead — see public/cart/nagad.png.
export const cartPaymentIcons: CartPaymentIcon[] = [
  { id: "bkash", name: "bKash", image: `${PAY}/bkash.png`, w: 45, h: 21 },
  { id: "mastercard", name: "Mastercard", image: `${PAY}/mastercard.png`, w: 24, h: 15 },
  { id: "visa", name: "Visa", image: `${PAY}/visa.png`, w: 37, h: 27 },
  { id: "nagad", name: "Nagad", image: "/cart/nagad.png", w: 36, h: 15 },
  { id: "rocket", name: "Rocket", image: `${PAY}/rocket.png`, w: 32, h: 20 },
  { id: "dutch-bangla-bank", name: "Dutch-Bangla Bank", image: `${PAY}/dutch-bangla-bank.png`, w: 26, h: 26 },
];

export const cartGuarantees = [
  "100% money back guarantee",
  "Live order & freight tracking",
  "Quality inspection before shipping",
];

export const cartCta = {
  label: "Continue to Payment",
  note: "You can review everything once more before paying",
};

/** ৳758 for whole-taka line prices, ৳3,151.6 for the one-decimal rollups —
 * matches the screenshot's own mixed formatting rather than forcing both
 * onto the same decimal count. */
export function formatTaka(amount: number, { decimals = 0 }: { decimals?: number } = {}) {
  return `৳${amount.toLocaleString("en-US", {
    minimumFractionDigits: decimals,
    maximumFractionDigits: decimals,
  })}`;
}
