/* ===== Seed data & shared helpers ===== */

// Container / vehicle presets — internal usable dims in mm
const CONTAINERS = [
  { id: '20ft',   name: "20ft Dry Container",  L: 5898, W: 2352, H: 2393, maxPayload: 28000, axles: ['drive','tandem'] },
  { id: '40ft',   name: "40ft Dry Container",  L: 12032, W: 2352, H: 2393, maxPayload: 28800, axles: ['drive','tandem'] },
  { id: '40hc',   name: "40ft High-Cube",       L: 12032, W: 2352, H: 2698, maxPayload: 28560, axles: ['drive','tandem'] },
  { id: 'eur',    name: "EU Trailer (13.6m)",   L: 13600, W: 2480, H: 2700, maxPayload: 24000, axles: ['steer','drive','tandem'] },
  { id: 'usdry',  name: "US 53ft Dry Van",      L: 16154, W: 2591, H: 2705, maxPayload: 20000, axles: ['steer','drive','tandem'] },
  { id: 'flat',   name: "Flatbed Trailer",      L: 12200, W: 2440, H: 0,    maxPayload: 22000, axles: ['steer','drive','tandem'] },
];

// Pallet presets — base in mm
const PALLETS = [
  { id: 'eur', name: 'EUR (EPAL)',  L: 1200, W: 800,  weight: 25, maxH: 1800, maxLoad: 1500 },
  { id: 'us',  name: 'US GMA',       L: 1219, W: 1016, weight: 22, maxH: 1800, maxLoad: 1361 },
  { id: 'aus', name: 'AU Standard',  L: 1165, W: 1165, weight: 32, maxH: 1800, maxLoad: 1000 },
];

const CATEGORIES = [
  { id: 'general',  name: 'General',   color: '#7a6a64' },
  { id: 'food',     name: 'Food',      color: '#1F8A5B' },
  { id: 'chilled',  name: 'Chilled',   color: '#2A8C9A' },
  { id: 'hazmat',   name: 'Hazmat',    color: '#C13333' },
  { id: 'fragile',  name: 'Fragile',   color: '#2E5FA8' },
  { id: 'ambient',  name: 'Ambient',   color: '#E8893C' },
];

// Category compatibility matrix:  allowed | warn | blocked
const CAT_MATRIX = {
  general:  { general:'allowed', food:'allowed', chilled:'allowed', hazmat:'warn',    fragile:'allowed', ambient:'allowed' },
  food:     { general:'allowed', food:'allowed', chilled:'allowed', hazmat:'blocked', fragile:'allowed', ambient:'allowed' },
  chilled:  { general:'allowed', food:'allowed', chilled:'allowed', hazmat:'blocked', fragile:'warn',    ambient:'warn'    },
  hazmat:   { general:'warn',    food:'blocked', chilled:'blocked', hazmat:'warn',    fragile:'blocked', ambient:'warn'    },
  fragile:  { general:'allowed', food:'allowed', chilled:'warn',    hazmat:'blocked', fragile:'allowed', ambient:'allowed' },
  ambient:  { general:'allowed', food:'allowed', chilled:'warn',    hazmat:'warn',    fragile:'allowed', ambient:'allowed' },
};

const CARGO_TYPE_ICONS = {
  pallet: 'pallet', carton: 'carton', box: 'box',
  barrel: 'barrel', pipe: 'pipe', roll: 'roll',
};

const CARGO_COLORS = ['#C13333', '#E8893C', '#F0B830', '#1F8A5B', '#2E5FA8', '#7B4FB5', '#2A8C9A', '#8C5A2C'];

/* Seed cargo manifest — mixed pallets, cartons, SKUs */
const SEED_CARGO = [
  { id: 'p001', tag: 'Pallet', type: 'pallet', sku: 'PLT-EUR-A', desc: 'EUR pallet · Beverages',     qty: 8,  L: 1200, W: 800,  H: 1450, weight: 720, category: 'ambient', stop: 1, color: '#C13333', locked: false },
  { id: 'p002', tag: 'Pallet', type: 'pallet', sku: 'PLT-EUR-B', desc: 'EUR pallet · Canned food',   qty: 6,  L: 1200, W: 800,  H: 1400, weight: 820, category: 'food',    stop: 1, color: '#1F8A5B', locked: false },
  { id: 'p003', tag: 'Pallet', type: 'pallet', sku: 'PLT-EUR-C', desc: 'EUR pallet · Cleaning chem', qty: 4,  L: 1200, W: 800,  H: 1300, weight: 540, category: 'hazmat',  stop: 2, color: '#7B4FB5', locked: true },
  { id: 'c004', tag: 'Carton', type: 'carton', sku: 'BX-LRG-01', desc: 'Large carton · Apparel',     qty: 14, L: 600,  W: 400,  H: 400,  weight: 22,  category: 'general', stop: 2, color: '#E8893C', locked: false },
  { id: 'c005', tag: 'Carton', type: 'carton', sku: 'BX-MED-04', desc: 'Med carton · Electronics',   qty: 22, L: 500,  W: 360,  H: 280,  weight: 14,  category: 'fragile', stop: 3, color: '#2E5FA8', locked: false },
  { id: 's006', tag: 'SKU',    type: 'box',    sku: 'GD-1029',   desc: 'Loose box · Tools',          qty: 6,  L: 380,  W: 240,  H: 220,  weight: 11,  category: 'general', stop: 2, color: '#8C5A2C', locked: false },
  { id: 's007', tag: 'Barrel', type: 'barrel', sku: 'BR-200L',   desc: '200L drum · Lubricant',      qty: 4,  L: 580,  W: 580,  H: 880,  weight: 196, category: 'hazmat',  stop: 3, color: '#F0B830', locked: false },
  { id: 's008', tag: 'Pipe',   type: 'pipe',   sku: 'PP-3M-DN50',desc: 'Steel pipe · 3m · DN50',     qty: 12, L: 3000, W: 60,   H: 60,   weight: 18,  category: 'general', stop: 3, color: '#7B4FB5', locked: false },
];

const SEED_VIOLATIONS = [
  { id: 'v1', item: 'p003', severity: 'bad',  rule: 'Category conflict', detail: 'Hazmat (PLT-EUR-C) within 600 mm of Food (PLT-EUR-B). Separation zone required.' },
  { id: 'v2', item: 'c005', severity: 'warn', rule: 'Stacking',           detail: 'Fragile carton has 18 kg stacked on top — exceeds 12 kg fragile cap.' },
  { id: 'v3', item: 's007', severity: 'warn', rule: 'Axle load',          detail: 'Drive axle 10.6t / 11.5t — approaching limit.' },
];

const RECENT_SESSIONS = [
  { id: 'r1', name: 'IKEA Hamburg → Munich · 40ft HC', module: 'Containerization', date: '2 hours ago',  util: 87, weight: '24.8 t / 28.5 t', violations: 0, status: 'ok' },
  { id: 'r2', name: 'AMZ FBA EU · Pallet build #4421',  module: 'Palletization',    date: '4 hours ago',  util: 92, weight: '0.74 t / 1.5 t', violations: 0, status: 'ok' },
  { id: 'r3', name: 'Carrefour weekly · 53ft van',      module: 'Containerization', date: 'Yesterday',    util: 78, weight: '17.2 t / 20.0 t', violations: 2, status: 'warn' },
  { id: 'r4', name: 'Apparel SKU cartonization · SS26', module: 'Cartonization',    date: '2 days ago',   util: 81, weight: '—',              violations: 0, status: 'ok' },
  { id: 'r5', name: 'Pharma cold chain · DHL CH-ZRH',   module: 'Containerization', date: '3 days ago',   util: 64, weight: '11.4 t / 24 t',  violations: 1, status: 'bad' },
];

window.Mojro = window.Mojro || {};
Object.assign(window.Mojro, {
  CONTAINERS, PALLETS, CATEGORIES, CAT_MATRIX,
  CARGO_TYPE_ICONS, CARGO_COLORS,
  SEED_CARGO, SEED_VIOLATIONS, RECENT_SESSIONS,
});
