/* ───────────────────────── EVE Monitor — Radar 0.0 data ───────────────────────── */

window.RadarData = (() => {
  // Constellation systems with relative positions (-1..1 space)
  const systems = [
    { id: 'YA0-XJ',  x:  0.00, y:  0.00, risk: 78, hub: true,  label: 'YA0-XJ',  active: true },
    { id: 'XR3-7P',  x:  0.45, y: -0.30, risk: 12 },
    { id: '6VDT-H',  x: -0.55, y: -0.20, risk: 64 },
    { id: 'F-NQWO',  x:  0.30, y:  0.55, risk: 28 },
    { id: 'KEE-N6',  x: -0.30, y:  0.50, risk: 42 },
    { id: 'B-DBYQ',  x:  0.75, y:  0.20, risk:  8 },
    { id: 'M-OEE8',  x: -0.78, y:  0.25, risk: 91 },
    { id: '3-FKCZ',  x:  0.10, y: -0.70, risk: 35 },
    { id: 'PF-346',  x: -0.10, y:  0.85, risk: 18 },
    { id: 'O-IVNH',  x:  0.62, y: -0.65, risk: 52 },
    { id: 'Z-2Y2Y',  x: -0.65, y: -0.60, risk:  4 },
  ];

  // graph edges (system jumps)
  const edges = [
    ['YA0-XJ','XR3-7P'], ['YA0-XJ','6VDT-H'], ['YA0-XJ','F-NQWO'],
    ['YA0-XJ','KEE-N6'], ['YA0-XJ','3-FKCZ'],
    ['XR3-7P','B-DBYQ'], ['XR3-7P','O-IVNH'],
    ['6VDT-H','M-OEE8'], ['6VDT-H','Z-2Y2Y'],
    ['F-NQWO','PF-346'], ['KEE-N6','PF-346'],
    ['KEE-N6','M-OEE8'], ['3-FKCZ','Z-2Y2Y'], ['3-FKCZ','O-IVNH'],
  ];

  // Rolling intel events — used to seed the live feed
  const eventTemplates = [
    { tag: 'HOSTILE',   sev: 'high',   text: 'Cyno lit · {ship}',           ship: 'Rorqual' },
    { tag: 'HOSTILE',   sev: 'high',   text: '{ship} appeared in local',    ship: 'Vargur' },
    { tag: 'BUBBLE',    sev: 'high',   text: 'Interdiction bubble up',     },
    { tag: 'GANG',      sev: 'med',    text: 'Gang of {n} hostiles',        n: 8 },
    { tag: 'NEUTRAL',   sev: 'med',    text: 'Neutral in local',           },
    { tag: 'CLEAR',     sev: 'low',    text: 'System reports clear',       },
    { tag: 'CYNO',      sev: 'high',   text: 'Cyno field detected',        },
    { tag: 'GATECAMP',  sev: 'med',    text: 'Gatecamp confirmed · {n} ppl', n: 5 },
    { tag: 'INTEL',     sev: 'low',    text: 'Scout reports clear',        },
    { tag: 'KILL',      sev: 'med',    text: 'Killmail · {ship} down',     ship: 'Loki' },
    { tag: 'WARN',      sev: 'high',   text: 'Hostile bridge active',      },
  ];

  const pilots = ['Karth Vex', 'Yola Sahn', 'Pyre Mott', 'Tess Ardent', 'Iko Vahn', 'Zhara Tarn'];

  function makeEvent(now = Date.now()) {
    const t = eventTemplates[Math.floor(Math.random() * eventTemplates.length)];
    const sys = systems[Math.floor(Math.random() * systems.length)].id;
    const ship = t.ship || ['Loki','Vargur','Cerberus','Sabre','Hurricane','Rorqual'][Math.floor(Math.random()*6)];
    const n = t.n || (3 + Math.floor(Math.random() * 12));
    return {
      id: 'e' + now + '-' + Math.random().toString(36).slice(2,6),
      ts: now,
      tag: t.tag,
      sev: t.sev,
      sys,
      pilot: pilots[Math.floor(Math.random() * pilots.length)],
      text: t.text.replace('{ship}', ship).replace('{n}', n),
    };
  }

  // Seed initial feed (last ~30 minutes)
  function seedFeed(count = 14) {
    const out = [];
    const now = Date.now();
    for (let i = 0; i < count; i++) {
      const e = makeEvent(now - (i * (90 + Math.random() * 80) * 1000));
      out.push(e);
    }
    return out.sort((a,b) => b.ts - a.ts);
  }

  // Killboard recent
  const kills = [
    { time: '18:38', ship: 'Loki',      pilot: 'k.Vex',   value: '412M', loss: false },
    { time: '18:31', ship: 'Vargur',    pilot: 'Hostile', value: '1.8B', loss: true  },
    { time: '18:24', ship: 'Sabre',     pilot: 'k.Mott',  value: '64M',  loss: false },
    { time: '18:11', ship: 'Cerberus',  pilot: 'Hostile', value: '380M', loss: true  },
    { time: '17:54', ship: 'Hurricane', pilot: 'k.Ardent',value: '210M', loss: false },
  ];

  return { systems, edges, eventTemplates, makeEvent, seedFeed, kills, pilots };
})();
