// pdx-data.jsx — Pokédex-layer extensions over data.jsx (additive; loads after it).
// Adds: competitive ROLE taxonomy, archetype→role map, dex numbering, seen-store.
// (Real fusion/team data is supplied at runtime by the bootstrap in pdx-app.jsx:
//  window.FUSIONS = the global search index, window.MAP_TEAMS = real teams by level.)

// ── Competitive role taxonomy (the spine of the dex) ─────────────────────────
const ROLES = {
  SWEEPER:  { key: "SWEEPER",  label: "Setup Sweeper",  short: "Sweeper",   color: "#ff5470", glyph: "▲" },
  BREAKER:  { key: "BREAKER",  label: "Wallbreaker",    short: "Breaker",   color: "#ff8a3c", glyph: "✶" },
  BULKY:    { key: "BULKY",    label: "Bulky Attacker", short: "Bulky Atk", color: "#ffc24b", glyph: "◆" },
  PIVOT:    { key: "PIVOT",    label: "Pivot / Support",short: "Pivot",     color: "#2fe6b0", glyph: "⇄" },
  STATUS:   { key: "STATUS",   label: "Status Spreader",short: "Status",    color: "#7cd66a", glyph: "☣" },
  HAZARD:   { key: "HAZARD",   label: "Hazard Control", short: "Hazards",   color: "#5bb0ff", glyph: "✦" },
  DISRUPT:  { key: "DISRUPT",  label: "Disruptor",      short: "Disruptor", color: "#b07cff", glyph: "↯" },
};
const ROLE_ORDER = ["SWEEPER", "BREAKER", "BULKY", "PIVOT", "STATUS", "HAZARD", "DISRUPT"];

// archetype enum → role bucket
const ARCH_TO_ROLE = {
  SETUP_SWEEPER:  "SWEEPER",
  WALLBREAKER:    "BREAKER",
  BULKY_ATTACKER: "BULKY",
  REGEN_PIVOT:    "PIVOT",
  MAGIC_GUARD_LO: "PIVOT",
  WEATHER_CORE:   "DISRUPT",
  TRICK_ROOM:     "DISRUPT",
  STATUS:         "STATUS",
  HAZARD_LEAD:    "HAZARD",
};
const roleOf = (archetype) => ROLES[ARCH_TO_ROLE[archetype]] || ROLES.BULKY;

// dex code from head.body → "№ 006 · 009"
const dexCode = (f) => `${String(f.headId).padStart(3, "0")} · ${String(f.bodyId).padStart(3, "0")}`;
// stable per-fusion key for seen-store
const fusionKey = (f) => `${f.headId}.${f.bodyId}`;

// ── Seen store (cosmetic dex-registration; localStorage, own namespace) ──────
const SEEN_KEY = "if-pokedex-seen-v1";
function loadSeen() {
  try { return new Set(JSON.parse(localStorage.getItem(SEEN_KEY) || "[]")); }
  catch { return new Set(); }
}
function saveSeen(set) {
  try { localStorage.setItem(SEEN_KEY, JSON.stringify([...set])); } catch {}
}

// ── stat color grading (red→amber→green) ─────────────────────────────────────
function pdxStatColor(v) {
  const t = Math.max(0, Math.min(1, v / 200));
  const hue = 4 + t * 142, sat = 74 - t * 8, light = 55 + t * 5;
  return `hsl(${hue} ${sat}% ${light}%)`;
}

Object.assign(window, {
  ROLES, ROLE_ORDER, ARCH_TO_ROLE, roleOf, dexCode, fusionKey,
  loadSeen, saveSeen, pdxStatColor,
});
