// gw-data.jsx — fictional but realistic data for the Guild Wars tracker.
// Exposes window.GW_DATA, window.GW_GUILDS, window.GW_HOME.

const GW_HOME = { name: "Dads on break", tag: "DOB", logo: "logos/home.png" };

const GW_GUILDS = [
  { id: "g1", name: "Legion de dragones", tag: "LDD", logo: "logos/g1.png", active: true },
  { id: "g2", name: "Northern Crown", tag: "NCR", logo: "logos/g2.png", active: true },
  { id: "g3", name: "Ashen Vow", tag: "ASH", logo: "logos/g3.png", active: true },
  { id: "g4", name: "Pax Mortis", tag: "PXM", logo: "logos/g4.png", active: true },
  { id: "g5", name: "Сыны Грозы", tag: "СГ", logo: "logos/g5.png", active: true },
  { id: "g6", name: "Void Wardens", tag: "VWD", logo: "logos/g6.png", active: true },
];

// Attacker pool — our guild members who run attacks.
const ATTACKERS = [
  "Андрей163RUS", "Kalima", "Alina", "Alister", "Semura", "Next-5",
  "ShadowFox", "Дракон99", "Mortis", "Veyra", "Кузя", "Nox_77",
  "Гефест", "Lyric", "Темныймаг", "Orin", "Sable", "Ирбис",
  "Voltage", "Ремор", "Kaori", "Гром", "Эфир", "Wraith",
];

// Opponent (Legion de dragones) defender names.
const DEFENDERS = [
  "Semura", "Next-5", "Vortigern", "Аметист", "Drogo", "Selene",
  "Бастион", "Ravenholt", "Юкико", "Marcus", "Сильвана", "Quill",
  "Тайфун", "Eldrin", "Морвен", "Castor", "Аркан", "Lumen",
  "Зефир", "Thorne",
];

// Deterministic pseudo-random so the layout is stable across reloads.
function rng(seed) {
  let s = seed % 2147483647;
  if (s <= 0) s += 2147483646;
  return () => (s = (s * 16807) % 2147483647) / 2147483647;
}

function fmt(n) {
  return n.toLocaleString("ru-RU");
}

function makeStats(rnd) {
  // Five hero/titan rows of battle stats for the popup screenshot fallback.
  return Array.from({ length: 5 }, () => ({
    dmg: Math.round((40 + rnd() * 160) * 1000),
    taken: Math.round((1 + rnd() * 18) * 1e6),
    heal: Math.round((rnd() * 16) * 1e6),
  }));
}

function buildAttacks(rnd, count, kind) {
  const used = new Set();
  return Array.from({ length: count }, (_, i) => {
    let name;
    do {
      name = ATTACKERS[Math.floor(rnd() * ATTACKERS.length)];
    } while (used.has(name) && used.size < ATTACKERS.length);
    used.add(name);
    const win = rnd() > 0.42;
    return {
      id: `${kind}-${i}`,
      attacker: name,
      result: win ? "win" : "loss",
      // attacker squad power and stars for the popup header
      power: (4.6 + rnd() * 1.1).toFixed(2) + "M",
      stars: win ? 3 : Math.floor(rnd() * 3),
      stats: makeStats(rnd),
    };
  });
}

const GW_DATA = DEFENDERS.map((name, i) => {
  const rnd = rng(i * 101 + 7);
  // Heroes & titans rows each get 1..5 attack variants.
  const heroCount = 1 + Math.floor(rnd() * 5);
  const titanCount = 1 + Math.floor(rnd() * 4);
  return {
    id: `opp-${i + 1}`,
    rank: i + 1,
    name,
    power: (4.4 + rnd() * 1.3).toFixed(2) + "M",
    heroes: buildAttacks(rnd, heroCount, "h"),
    titans: buildAttacks(rnd, titanCount, "t"),
  };
});

window.GW_HOME = GW_HOME;
window.GW_GUILDS = GW_GUILDS;
window.GW_DATA = GW_DATA;
window.GW_FMT = fmt;
