// GPS boxd — sample data for all screens. Realistic but fictional.

const USERS = [
  { pin: "8472", name: "Tobias Hullette", role: "admin", shift: "Day", since: "Sep 12, 2024" },
  { pin: "3819", name: "Markus Rumswinkel", role: "manager", shift: "Day", since: "Oct 04, 2024" },
  { pin: "5531", name: "Cole Mirovsky", role: "worker", shift: "Day", since: "Jan 14, 2026" },
  { pin: "7264", name: "Tomás Vega", role: "worker", shift: "Night", since: "Nov 20, 2025" },
  { pin: "2208", name: "Priya Anand", role: "worker", shift: "Day", since: "Feb 02, 2026" },
];

// Station config — list of bays/tables. Admin manages them in Settings → Station.
const STATIONS = [
  { id: "st-1", name: "Bay 1 · Table 1", active: true, terminal: "this terminal" },
];
// Legacy single-station alias — always reflects the active one.
const STATION = STATIONS.find((s) => s.active) || STATIONS[0];

// Notification policy — PO requests batch into a daily admin digest, never per-request emails.
const NOTIFICATION_CONFIG = {
  adminDigestTime: "08:00",
  adminDigestRecipient: "tobias@germanperformancesolutions.com",
  adminDigestLastSent: "today 08:00",
  adminDigestNextSend: "tomorrow 08:00",
};

// Pending PO requests — queued by floor/system, sent to admin in the daily digest.
const PENDING_PO_REQUESTS = [
  {
    id: "REQ-204", sku: "GPS-CN-TMAP-3B", name: "T-Connector MAP (3-pin Bosch)",
    suggestedQty: 200, estCost: 340.00, vendor: "Bosch Mobility Direct",
    source: "WO-24190 shortage", requestedBy: "Cole Mirovsky", requestedAt: "today 07:24",
    reason: "shortage during kitting", priority: "URGENT",
  },
  {
    id: "REQ-205", sku: "GPS-PKG-OC-S", name: "Branded Outer Carton — Small",
    suggestedQty: 500, estCost: 312.50, vendor: "ULINE Packaging",
    source: "auto · below reorder", requestedBy: "system", requestedAt: "today 07:08",
    reason: "par drift", priority: "NORMAL",
  },
  {
    id: "REQ-206", sku: "GPS-OR-VTN-12", name: "O-Ring Viton 12mm",
    suggestedQty: 300, estCost: 84.00, vendor: "ULINE Packaging",
    source: "forecast · thermostat batch", requestedBy: "system", requestedAt: "today 06:42",
    reason: "projected consumption", priority: "NORMAL",
  },
];

// Supplier-SKU → GPS-SKU mapping (autofill in receiving for blind extras / vendor part numbers).
const SUPPLIER_SKU_MAP = [
  { supplierSku: "ARP-3032", gpsSku: "GPS-BOLT-M6-20", name: "M6×20 Bolt Grade 10.9", vendor: "ARP Fasteners" },
  { supplierSku: "ARP-OR12E", gpsSku: "GPS-ORING-12MM", name: "O-Ring 12mm EPDM", vendor: "ARP Fasteners" },
  { supplierSku: "ARP-VL50", gpsSku: "GPS-MNT-VLC-50", name: "Velcro Mount Strip 50mm", vendor: "ARP Fasteners" },
  { supplierSku: "BCH-3PMAP", gpsSku: "GPS-CN-TMAP-3B", name: "T-Connector MAP 3-pin Bosch", vendor: "Bosch Mobility" },
  { supplierSku: "PCB-N63V2", gpsSku: "GPS-PCB-N63-V2", name: "Tuning Box N63 PCB", vendor: "Sourcemax PCB" },
  { supplierSku: "WH-N634", gpsSku: "GPS-WH-N63-4P", name: "Wiring Harness N63 4-pin", vendor: "Sourcemax PCB" },
  { supplierSku: "ULN-OC-S", gpsSku: "GPS-PKG-OC-S", name: "Branded Outer Carton Small", vendor: "ULINE Packaging" },
  { supplierSku: "ULN-VTN12", gpsSku: "GPS-OR-VTN-12", name: "O-Ring Viton 12mm", vendor: "ULINE Packaging" },
  { supplierSku: "ULN-FOAM-DN", gpsSku: "GPS-PKG-FI-DN", name: "Foam donut insert", vendor: "ULINE Packaging" },
  { supplierSku: "ARP-N63-TH", gpsSku: "GPS-AD-N63-TH", name: "Adapter Loom N63 Throttle", vendor: "Sourcemax PCB" },
];

// ShipStation rate quotes (mocked — shown to worker at carrier-pick step)
const SHIPPING_RATES = [
  { id: "ups-ground", carrier: "UPS Ground", days: "3–5", price: 14.20, recommended: true, expedited: false },
  { id: "usps-priority", carrier: "USPS Priority", days: "2–3", price: 16.85, expedited: false },
  { id: "ups-2day", carrier: "UPS 2nd Day Air", days: "2", price: 28.40, expedited: true },
  { id: "dhl-express", carrier: "DHL Express Intl", days: "1–2", price: 41.20, expedited: true, international: true },
  { id: "ups-next", carrier: "UPS Next Day Air", days: "1", price: 58.90, expedited: true },
  { id: "fedex-priority", carrier: "FedEx Priority Overnight", days: "1", price: 64.20, expedited: true },
];

// Per-SKU shipping defaults — packed weight + box dims. Real ShipStation pulls from product profile.
const SHIPPING_DEFAULTS = {
  "GPS-TBX-S55-V2": { weight: 4.2, length: 10, width: 8, height: 6, boxType: "GPS-PKG-OC-S" },
  "GPS-TBX-N63-V2": { weight: 4.5, length: 10, width: 8, height: 6, boxType: "GPS-PKG-OC-S" },
  "GPS-DP-B58-3.0": { weight: 18.0, length: 32, width: 12, height: 8, boxType: "Custom — oversized" },
  "GPS-CHG-EA888-G3": { weight: 6.5, length: 24, width: 8, height: 6, boxType: "Custom — long" },
  "GPS-THERM-30T-G1": { weight: 1.8, length: 6, width: 6, height: 4, boxType: "Small box" },
  _default: { weight: 4.0, length: 10, width: 8, height: 6, boxType: "GPS-PKG-OC-S" },
};

// HS code reference for international (customs)
const HS_CODES = {
  "GPS-TBX-S55-V2": { hs: "8543.70.99", desc: "Electronic ECU tuning module", customsValue: 599.00 },
  "GPS-TBX-N63-V2": { hs: "8543.70.99", desc: "Electronic ECU tuning module", customsValue: 649.00 },
  "GPS-DP-B58-3.0": { hs: "8708.92.50", desc: "Automotive exhaust component", customsValue: 489.00 },
  "GPS-THERM-30T-G1": { hs: "8409.91.50", desc: "Engine thermostat housing", customsValue: 189.00 },
  _default: { hs: "8708.99.81", desc: "Automotive performance part", customsValue: 100.00 },
};

// Multiple paused sessions — with reason context
const PAUSED_SESSIONS = [
  {
    id: "PS-001", woId: "WO-24190", woType: "KITTING",
    name: "Tuning Box N63 — X5/X6 50i",
    progress: "Step 5 of 9",
    pausedBy: "Tomás Vega",
    pausedAt: "yesterday 22:41",
    reason: "Ran out of materials",
    note: "GPS-CN-TMAP-3B — only 14 in bin, need 12 for run",
  },
  {
    id: "PS-002", woId: "WO-24188", woType: "ASSY",
    name: "Thermostat Housing — Audi 3.0T Gen 1 (rerun)",
    progress: "Batch 2 of 4 · Step 4 · 6/20 units done",
    pausedBy: "Priya Anand",
    pausedAt: "today 06:47",
    reason: "Waiting for supervisor approval",
    note: "Tolerance variance on press-fit — need Markus to sign off before continuing",
  },
  {
    id: "PS-003", woId: "WO-24180", woType: "KITTING",
    name: "Charge Pipe — EA888 Gen3 (rebuild)",
    progress: "Step 8 of 11",
    pausedBy: "Cole Mirovsky",
    pausedAt: "Fri 16 May 17:02",
    reason: "Ran out of time / end of shift",
    note: "Will pick up first thing Monday",
  },
];
// Keep singular alias for any legacy refs.
const PAUSED_SESSION = PAUSED_SESSIONS[0];

// Weekly inventory-audit WO is generated by the system; one assigned per week.
const INVENTORY_AUDIT_WO = {
  id: "WO-24220", type: "AUDIT", priority: "NORMAL",
  sku: "—", name: "Weekly inventory walk · check qty + bin location",
  qty: 0, due: "Fri 22 May 17:00", location: "All bays",
  orders: ["scheduled · weekly"],
  recurrence: "weekly",
};

const WORK_ORDERS = [
  INVENTORY_AUDIT_WO,
  {
    id: "WO-24187", type: "SHIPPING", priority: "URGENT",
    sku: "GPS-TBX-S55-V2", name: "Tuning Box S55 — BMW M3/M4",
    qty: 4, due: "today 14:00", location: "Bay 03 · Rack B2",
    orders: ["#GPS-104882", "#GPS-104884", "#GPS-104891", "#GPS-104903"],
    customers: [
      { order: "#GPS-104882", name: "James Reyes", address: "1411 Mockingbird Ln, Asheville NC 28801", units: 1, country: "US" },
      { order: "#GPS-104884", name: "Devin Park", address: "284 Hollins Ave, Wilmington NC 28401", units: 1, country: "US" },
      { order: "#GPS-104891", name: "Kelly Trent", address: "9 Birch Hill Dr, Charlotte NC 28207", units: 1, country: "US" },
      { order: "#GPS-104903", name: "Lukas Becker", address: "Hauptstraße 47, 10827 Berlin, Germany", units: 1, country: "DE" },
    ],
  },
  {
    id: "WO-24190", type: "KITTING", priority: "URGENT",
    sku: "GPS-TBX-N63-V2", name: "Tuning Box N63 — X5/X6 50i",
    qty: 6, due: "today 16:30", location: "Bay 01 · Rack A4",
    orders: ["#GPS-104908", "#GPS-104915", "#GPS-104921"],
  },
  {
    id: "WO-24193", type: "ASSY", priority: "NORMAL",
    sku: "GPS-THERM-30T-G1", name: "Thermostat Housing — Audi 3.0T Gen 1",
    qty: 20, due: "tomorrow", location: "Assy Cell 2",
    orders: ["#GPS-104930", "#GPS-104935", "#GPS-104942", "#GPS-104947"],
  },
  {
    id: "WO-24196", type: "KITTING", priority: "NORMAL",
    sku: "GPS-CHG-EA888-G3", name: "Charge Pipe — EA888 Gen3",
    qty: 8, due: "tomorrow", location: "Bay 02 · Rack C1",
    orders: ["#GPS-104941", "#GPS-104944"],
  },
  {
    id: "WO-24201", type: "RECEIVING", priority: "PLANNED",
    sku: "GPS-PO-2026-0142", name: "Inbound shipment · ARP Fasteners Inc.",
    qty: 800, due: "today", location: "Dock 2",
    orders: ["GPS-PO-2026-0142"],
    poId: "GPS-PO-2026-0142",
  },
  {
    id: "WO-24220", type: "AUDIT", priority: "PLANNED",
    sku: "—", name: "Weekly inventory walk · count, relocate, include boxed parts",
    qty: 10, due: "this week", location: "all bays",
    orders: ["recurring · every Mon 06:00"],
  },
];

const KIT_STEPS = [
  { qty: 6, part: "Tuning Box N63 — Main PCB Enclosure", sku: "GPS-PCB-N63-V2", bin: "A4-01" },
  { qty: 6, part: "Wiring Harness — N63 4-Pin", sku: "GPS-WH-N63-4P", bin: "A4-02" },
  { qty: 12, part: "T-Connector — MAP Sensor (3-pin Bosch)", sku: "GPS-CN-TMAP-3B", bin: "A4-03" },
  { qty: 6, part: "Adapter Loom — N63 Throttle", sku: "GPS-AD-N63-TH", bin: "A4-04" },
  { qty: 24, part: "Velcro Mount Strip — 50mm", sku: "GPS-MNT-VLC-50", bin: "B1-12" },
  { qty: 6, part: "Quick-Start Card (EN/DE)", sku: "GPS-DOC-QS-N63", bin: "DOC-A" },
  { qty: 6, part: "Anti-static Bag — Medium", sku: "GPS-PKG-ASB-M", bin: "PKG-04" },
  { qty: 6, part: "Foam Insert — Tuning Box (die-cut)", sku: "GPS-PKG-FI-TBX", bin: "PKG-05" },
  { qty: 6, part: "GPS Branded Outer Carton — Small", sku: "GPS-PKG-OC-S", bin: "PKG-01" },
];

const FLAGGED_SHORTAGES = [
  { sku: "GPS-CN-TMAP-3B", flaggedBy: "Markus Rumswinkel", at: "14m ago" },
];

// Assembly steps for WO-24193 (Thermostat Housing — Audi 3.0T Gen 1 · qty 20)
const ASSY_STEPS = [
  {
    title: "Inspect machined housing",
    detail: "Check seal face, thread bores, and bleed port. Reject if any chatter marks on seal face or burrs in thread.",
    critical: false,
    image: "inspect",
    tools: ["visual", "thread gauge M6"],
  },
  {
    title: "Install Viton O-ring",
    detail: "Light film of silicone grease. Seat O-ring fully in groove — no twists, no pinch. Discard any with surface marks.",
    critical: false,
    image: "oring",
    tools: ["O-ring GPS-OR-VTN-12", "silicone grease"],
  },
  {
    title: "Press thermostat element into housing",
    detail: "Orient bleed hole at 12 o'clock (toward boss marked B). Press until shoulder fully seated — you should feel it bottom out cleanly.",
    critical: true,
    image: "press",
    tools: ["arbor press", "GPS-THERM-EL fixture"],
  },
  {
    title: "Install housing cap",
    detail: "Four M6×16 SHCS in cross pattern. Snug all four first, then torque to spec in cross sequence (1–3–2–4).",
    critical: true,
    torqueSpec: "12 Nm",
    image: "bracket",
    tools: ["4mm hex bit", "torque wrench 0–20 Nm"],
  },
  {
    title: "Pressure-test assembly",
    detail: "Cap both ports. Pressurize to 25 psi. Hold 60 sec. Spray soap on cap interface and bleed port. Fail on any bubble.",
    critical: true,
    spec: "25 psi · 60s hold",
    image: "pressure",
    tools: ["pressure rig", "soap solution"],
    requiresHold: true,
  },
  {
    title: "Stamp serial + date code",
    detail: "Dot-peen on flat boss next to GPS logo. Format: TH-YYWW-NNN. Verify legibility on QC reader.",
    critical: false,
    image: "stamp",
    tools: ["dot-peen", "QC reader"],
  },
  {
    title: "Bag, label, place in tote",
    detail: "Anti-static bag medium, fold once, foam donut around housing. Apply WO barcode label. Tote at packing station.",
    critical: false,
    image: "box",
    tools: ["GPS-PKG-ASB-M", "foam donut", "barcode printer"],
  },
];

const INVENTORY = [
  { sku: "GPS-ORING-12MM", name: "O-Ring 12mm EPDM", type: "consumable", location: "A1-03",
    qty: 14, boxed: 0, reserved: 0, par: 50, status: "ORDER_NOW", daysLeft: 1.2,
    onOrder: 200, eta: "May 27", onOrderPo: "GPS-PO-2026-0142" },
  { sku: "GPS-BOLT-M6-20", name: "M6×20 Bolt — Grade 10.9", type: "hardware", location: "A1-07",
    qty: 847, boxed: 500, reserved: 24, par: 200, status: "OK", daysLeft: 28,
    onOrder: 500, eta: "May 27", onOrderPo: "GPS-PO-2026-0142" },
  { sku: "GPS-CN-TMAP-3B", name: "T-Connector MAP (3-pin Bosch)", type: "hardware", location: "A4-03",
    qty: 14, boxed: 6, reserved: 12, par: 50, status: "WATCH", daysLeft: 4,
    onOrder: 200, eta: "pending approval", onOrderPo: "REQ-204" },
  { sku: "GPS-THERM-ASSY", name: "Assembled Thermostat — 3.0T Gen 1", type: "assy", location: "C2-01",
    qty: 8, boxed: 8, reserved: 2, par: 5, status: "OK", daysLeft: null,
    onOrder: 0, eta: null },
  { sku: "GPS-PCB-N63-V2", name: "Tuning Box N63 PCB Enclosure", type: "hardware", location: "A4-01",
    qty: 42, boxed: 24, reserved: 6, par: 30, status: "OK", daysLeft: 14,
    onOrder: 40, eta: "May 24", onOrderPo: "GPS-PO-2026-0140" },
  { sku: "GPS-PKG-OC-S", name: "Branded Outer Carton — Small", type: "consumable", location: "PKG-01",
    qty: 72, boxed: 0, reserved: 0, par: 150, status: "WATCH", daysLeft: 6,
    onOrder: 500, eta: "pending approval", onOrderPo: "REQ-205" },
  { sku: "GPS-MNT-VLC-50", name: "Velcro Mount Strip — 50mm", type: "consumable", location: "B1-12",
    qty: 480, boxed: 0, reserved: 24, par: 100, status: "OK", daysLeft: 35,
    onOrder: 100, eta: "May 27", onOrderPo: "GPS-PO-2026-0142" },
  { sku: "GPS-AD-N63-TH", name: "Adapter Loom — N63 Throttle", type: "hardware", location: "A4-04",
    qty: 22, boxed: 0, reserved: 6, par: 30, status: "WATCH", daysLeft: 9,
    onOrder: 0, eta: null },
  { sku: "GPS-TBX-N63-V2", name: "Tuning Box N63 — X5/X6 50i", type: "kit", location: "B2-01",
    qty: 3, boxed: 3, reserved: 0, kitted: 2, par: 5, needed: 6,
    canBuild: 0, bottleneck: "GPS-CN-TMAP-3B", status: "CRITICAL" },
  { sku: "GPS-TBX-S55-V2", name: "Tuning Box S55 — BMW M3/M4", type: "kit", location: "B2-02",
    qty: 8, boxed: 8, reserved: 0, kitted: 4, par: 10, needed: 4,
    canBuild: 8, bottleneck: null, status: "OK" },
  { sku: "GPS-DP-B58-3.0", name: "Downpipe B58 — 340i / M340i", type: "kit", location: "D1-04",
    qty: 5, boxed: 4, reserved: 0, kitted: 1, par: 6, needed: 3,
    canBuild: 3, bottleneck: null, status: "WATCH" },
  { sku: "GPS-CHG-EA888-G3", name: "Charge Pipe — EA888 Gen3", type: "kit", location: "C1-02",
    qty: 11, boxed: 11, reserved: 0, kitted: 0, par: 10, needed: 8,
    canBuild: 11, bottleneck: null, status: "OK" },
];

const APPROVALS = [
  { id: "WO-24210", reason: "Auto · stock below reorder point",
    sku: "GPS-TBX-S55-V2", name: "Tuning Box S55 — BMW M3/M4",
    suggestedQty: 25, currentStock: 3, reorderPoint: 10,
    triggerOrders: ["#GPS-104882", "#GPS-104884", "#GPS-104891", "#GPS-104903", "#GPS-104912"],
    leadTime: "4 days", submittedBy: "system", submittedAt: "2m ago" },
  { id: "WO-24211", reason: "Manual · shortage during kitting",
    sku: "GPS-CN-TMAP-3B", name: "T-Connector MAP (3-pin Bosch)",
    suggestedQty: 200, currentStock: 14, reorderPoint: 50,
    triggerOrders: ["WO-24190 shortage"], leadTime: "2 days",
    submittedBy: "Markus Rumswinkel", submittedAt: "14m ago" },
  { id: "WO-24212", reason: "Forecast spike · 8 Shopify orders in 24h",
    sku: "GPS-DP-B58-3.0", name: "Downpipe B58 — 340i / M340i",
    suggestedQty: 12, currentStock: 5, reorderPoint: 6,
    triggerOrders: ["#GPS-104930", "#GPS-104935", "#GPS-104942", "#GPS-104947", "#GPS-104951", "#GPS-104955", "#GPS-104961", "#GPS-104967"],
    leadTime: "6 days", submittedBy: "system", submittedAt: "38m ago" },
];

const ALL_BADGES = [
  { id: "first_kit", name: "First Kit", icon: "📦", category: "Volume", desc: "Complete your first kitting session" },
  { id: "ten_strong", name: "Ten Strong", icon: "📦", category: "Volume", desc: "10 kitting sessions complete" },
  { id: "century", name: "Century", icon: "🏭", category: "Volume", desc: "100 sessions total" },
  { id: "quick_kit", name: "Quick Kit", icon: "⚡", category: "Speed", desc: "Kitting session under 10 min" },
  { id: "speed_round", name: "Speed Round", icon: "⚡", category: "Speed", desc: "3 kits in one day, all under 10 min" },
  { id: "clean_run", name: "Clean Run", icon: "✅", category: "Accuracy", desc: "Session with zero shortages" },
  { id: "streak_10", name: "Streak of 10", icon: "✅", category: "Accuracy", desc: "10 sessions, zero shortages" },
  { id: "perfect_week", name: "Perfect Week", icon: "🎯", category: "Accuracy", desc: "Full week, zero shortages" },
  { id: "five_days", name: "Five Days", icon: "📅", category: "Consistency", desc: "5 consecutive working days" },
  { id: "night_owl", name: "Night Owl", icon: "🌙", category: "Consistency", desc: "10 sessions started after 6pm" },
  { id: "early_bird", name: "Early Bird", icon: "☀️", category: "Consistency", desc: "10 sessions started before 7am" },
  { id: "builder", name: "Builder", icon: "🔧", category: "Special", desc: "50 assembly sessions complete" },
  { id: "postmaster", name: "Postmaster", icon: "📬", category: "Special", desc: "100 shipping sessions complete" },
  { id: "all_rounder", name: "All Rounder", icon: "🧰", category: "Special", desc: "10+ sessions in every category" },
  { id: "top_of_week", name: "Top of the Week", icon: "👑", category: "Special", desc: "Highest session count in a week" },
  { id: "team_player", name: "Team Player", icon: "🤝", category: "Special", desc: "Week of 100% on-time team rate" },
];

const BADGES_EARNED = {
  "Cole Mirovsky": ["first_kit", "ten_strong", "clean_run", "quick_kit", "five_days"],
  "Markus Rumswinkel": ["first_kit", "ten_strong", "century", "quick_kit", "speed_round", "clean_run", "streak_10", "five_days", "builder", "top_of_week"],
  "Priya Anand": ["first_kit", "ten_strong", "clean_run", "five_days"],
  "Tomás Vega": ["first_kit", "night_owl"],
  "Tobias Hullette": ["first_kit", "ten_strong", "century", "all_rounder"],
};

const LEADERBOARD = [
  { name: "Markus Rumswinkel", sessions: 18, avgKitMin: 11.8, onTimeRate: 100, badges: ["⚡", "✅", "📅"] },
  { name: "Cole Mirovsky", sessions: 12, avgKitMin: 13.2, onTimeRate: 96, badges: ["📦", "✅"] },
  { name: "Priya Anand", sessions: 9, avgKitMin: 14.1, onTimeRate: 100, badges: ["🔧", "📅"] },
  { name: "Tomás Vega", sessions: 6, avgKitMin: 15.1, onTimeRate: 83, badges: ["🌙"] },
];

const LEADERBOARD_ALLTIME = [
  { name: "Markus Rumswinkel", sessions: 312, avgKitMin: 10.9, onTimeRate: 98 },
  { name: "Tobias Hullette", sessions: 287, avgKitMin: 12.4, onTimeRate: 99 },
  { name: "Cole Mirovsky", sessions: 142, avgKitMin: 13.0, onTimeRate: 95 },
  { name: "Tomás Vega", sessions: 88, avgKitMin: 14.6, onTimeRate: 87 },
  { name: "Priya Anand", sessions: 76, avgKitMin: 13.8, onTimeRate: 97 },
];

const MY_STATS = {};

const ACTIVITY_LOG = [];

const PURCHASE_ORDERS = [];

const VENDORS = [
  { name: "ARP Fasteners Inc.", email: "sales@arp-fast.com", leadTime: 7, products: 12, reliability: 96 },
  { name: "Bosch Mobility Direct", email: "b2b@bosch.de", leadTime: 4, products: 8, reliability: 99 },
  { name: "ULINE Packaging", email: "orders@uline.com", leadTime: 2, products: 6, reliability: 100 },
  { name: "MercRacing GmbH", email: "fabrik@mercracing.de", leadTime: 14, products: 4, reliability: 92 },
];

const INTEGRATIONS = [
  { name: "Shopify", status: "ok", detail: "germanperformancesolutions.com · synced 2m ago" },
  { name: "ShipStation", status: "ok", detail: "Preferred: UPS Ground · 47 labels today" },
  { name: "Email (SMTP)", status: "ok", detail: "smtp.gpsboxd.io · last test 1h ago" },
  { name: "Label Printer", status: "warn", detail: "Zebra ZD420 · low ribbon warning" },
];

Object.assign(window, {
  INVENTORY_AUDIT_WO,
  USERS, STATIONS, STATION, NOTIFICATION_CONFIG, PENDING_PO_REQUESTS,
  PAUSED_SESSIONS, PAUSED_SESSION, WORK_ORDERS, KIT_STEPS, ASSY_STEPS, FLAGGED_SHORTAGES,
  INVENTORY, APPROVALS, ALL_BADGES, BADGES_EARNED, LEADERBOARD,
  LEADERBOARD_ALLTIME, MY_STATS, ACTIVITY_LOG, PURCHASE_ORDERS, VENDORS, INTEGRATIONS,
  SUPPLIER_SKU_MAP, SHIPPING_RATES, SHIPPING_DEFAULTS, HS_CODES,
});

// Sync live data from backend (sync XHR so subsequent Babel scripts see updated window.*).
// Falls back silently to the mock data above if backend is offline.
(function syncFromBackend() {
  try {
    const xhr = new XMLHttpRequest();
    xhr.open('GET', '/api/bootstrap', false);
    xhr.send(null);
    if (xhr.status === 200) {
      const live = JSON.parse(xhr.responseText);
      if (live.USERS)           window.USERS           = live.USERS;
      if (live.INVENTORY)       window.INVENTORY       = live.INVENTORY;
      if (live.WORK_ORDERS)     window.WORK_ORDERS     = live.WORK_ORDERS;
      if (live.PAUSED_SESSIONS) window.PAUSED_SESSIONS = live.PAUSED_SESSIONS;
      if (live.KIT_STEPS)       window.KIT_STEPS       = live.KIT_STEPS;
      if (live.ASSY_STEPS_DB)   window.ASSY_STEPS_DB   = live.ASSY_STEPS_DB;
      if (live.STATION)         window.STATION         = live.STATION;
      if (live.STATIONS)        window.STATIONS        = live.STATIONS;
      if (live.NOTIFICATION_CONFIG)  window.NOTIFICATION_CONFIG  = live.NOTIFICATION_CONFIG;
      if (live.PURCHASE_ORDERS)      window.PURCHASE_ORDERS      = live.PURCHASE_ORDERS;
      if (live.ACTIVITY_LOG)         window.ACTIVITY_LOG         = live.ACTIVITY_LOG;
      window.SHOPIFY_LAST_SYNC     = live.SHOPIFY_LAST_SYNC || null;
      window.SHIPSTATION_LAST_TEST = live.SHIPSTATION_LAST_TEST || null;
      console.log('[GPS boxd] Live data loaded from backend.');
    }
  } catch (e) {
    // backend offline — using mock data
  }
})();
