/* eslint-disable */
// DoJa Packs v2 — main app shell, wired to the backend.

const { useState: useAppState, useEffect: useAppEffect } = React;

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "drama": 9,
  "background": "vivid"
}/*EDITMODE-END*/;

const NAV_ITEMS = [
  { id: "home",        label: "Start",        icon: "home" },
  { id: "inventory",   label: "Inventar",     icon: "box" },
  { id: "collection",  label: "Sammlung",     icon: "cards" },
  { id: "badges",      label: "Badges",       icon: "medal" },
  { id: "shards",      label: "Splitter",     icon: "shard" },
  { id: "fluch",       label: "Fluchkasse",   icon: "jar" },
  { id: "leaderboard", label: "Bestenliste",  icon: "trophy" },
  { id: "me",          label: "Profil",       icon: "heart" },
  { id: "infos",       label: "Infos",        icon: "info" },
];

// Badge- und Splitter-Tab nur zeigen, wenn das jeweilige System live geschaltet
// ist (Flags kommen zur Laufzeit aus /api/catalog, siehe bootApp) — daher pro
// Render gefiltert.
function visibleNavItems() {
  return NAV_ITEMS.filter((n) =>
    (n.id !== "badges" || window.BADGES_ENABLED) &&
    (n.id !== "shards" || window.SHARDS_ENABLED) &&
    (n.id !== "fluch" || (window.fluchVisible && fluchVisible())) &&
    (n.id !== "infos" || (window.infosVisible && infosVisible())));
}

// Backend uses pack tiers (common…legend, minecraft); frontend uses PACKS ids —
// mapped via packForTier() (data.jsx).

// Inline SVG nav icons.
const NAV_ICON_PATHS = {
  home:  "M12 2c1.2 5.6 4.2 8.6 9.8 9.8C16.2 13 13.2 16 12 21.8 10.8 16 7.8 13 2.2 11.8 7.8 10.6 10.8 7.6 12 2Z",
  box:   "M12 2 3 7v10l9 5 9-5V7L12 2Zm0 2.31L18.49 8 12 11.69 5.51 8 12 4.31ZM5 9.7l6 3.43v6.84l-6-3.34V9.7Zm14 0v6.93l-6 3.34v-6.84l6-3.43Z",
  cards: "M9 2.5h9A2.5 2.5 0 0 1 20.5 5v11.5l-2.5-1.45V5H9V2.5ZM5.5 6.5h9A2.5 2.5 0 0 1 17 9v9.5A2.5 2.5 0 0 1 14.5 21h-9A2.5 2.5 0 0 1 3 18.5V9a2.5 2.5 0 0 1 2.5-2.5Z",
  trophy: "M7 3h10v2h3v3a4 4 0 0 1-4 4h-.3A5 5 0 0 1 13 14.9V18h3v3H8v-3h3v-3.1A5 5 0 0 1 8.3 12H8a4 4 0 0 1-4-4V5h3V3Zm0 4H6v1a2 2 0 0 0 1 1.7V7Zm10 0v2.7A2 2 0 0 0 18 8V7h-1Z",
  heart: "M12 21S2.7 15.2 2.7 9.1C2.7 6.06 5.06 4 7.7 4c1.95 0 3.46 1.05 4.3 2.55C12.84 5.05 14.35 4 16.3 4c2.64 0 5 2.06 5 5.1C21.3 15.2 12 21 12 21Z",
  medal: "M8.6 2h6.8l-2.5 5.2a7.6 7.6 0 0 0-1.8 0L8.6 2ZM6 2h1.5l2 4.2-1.9 1L6 2Zm12 0h-1.5l-2 4.2 1.9 1L18 2Zm-6 6.2a6.9 6.9 0 1 0 0 13.8 6.9 6.9 0 0 0 0-13.8Zm0 2.4 1.3 2.6 2.9.4-2.1 2 .5 2.9-2.6-1.4-2.6 1.4.5-2.9-2.1-2 2.9-.4L12 10.6Z",
  shard: "M12 2 4 9l8 13 8-13-8-7Zm0 2.6L17.4 9 12 18.4 6.6 9 12 4.6Z",
  info:  "M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20Zm0 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16Zm-1 6h2v7h-2v-7Zm0-3.5h2v2h-2v-2Z",
  jar:   "M7.5 2h9v3h-9V2Zm-.3 4.5h9.6c.1 1 .6 1.7 1.4 2.5.9.9 1.8 2.1 1.8 4V19a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3v-6c0-1.9.9-3.1 1.8-4 .8-.8 1.3-1.5 1.4-2.5Zm1.3 7.5v5h7v-5h-7Z",
};

function NavGlyph({ name }) {
  return (
    <svg className="nav-glyph" viewBox="0 0 24 24" width="15" height="15" aria-hidden="true">
      <path d={NAV_ICON_PATHS[name]} fill="currentColor" />
    </svg>
  );
}

function Sidebar({ current, go, invCount, user }) {
  return (
    <aside className="sidebar">
      <div className="brand brand-stack">
        <div className="brand-logo" aria-label="DoJa Cards">
          <img className="brand-doja" src="brand/doja-logo.webp" alt="DoJa" />
          <img className="brand-cards" src="brand/cards-script.png" alt="Cards" />
        </div>
        <div className="brand-sub">{window.MINECRAFT_ENABLED ? <span className="brand-sub-mc">Minecraft Update</span> : "Saison 1"}</div>
      </div>

      <nav className="nav">
        {visibleNavItems().map((n) => (
          <button
            key={n.id}
            className={`nav-item ${current === n.id ? "active" : ""}`}
            onClick={() => go(n.id)}
          >
            <span className="nav-icon"><NavGlyph name={n.icon} /></span>
            {n.label}
            {n.id === "inventory" && invCount > 0 && <span className="nav-badge">{invCount}</span>}
          </button>
        ))}
      </nav>

      <div className="sidebar-foot">
        {user ? (
          <div style={{
            display: "flex", alignItems: "center", gap: 11, marginBottom: 16,
            padding: "10px 4px",
          }}>
            <div style={{
              width: 38, height: 38, flex: "none",
              display: "grid", placeItems: "center",
              background: "var(--yellow)", color: "#0F0820",
              fontWeight: 900, fontSize: 16, fontFamily: "var(--font-display)",
            }}>{(user.display_name || "?")[0].toUpperCase()}</div>
            <div style={{ overflow: "hidden" }}>
              <div style={{
                fontWeight: 800, fontSize: 13, whiteSpace: "nowrap",
                overflow: "hidden", textOverflow: "ellipsis",
              }}>{user.display_name}</div>
              <a href="/api/auth/logout" style={{
                fontSize: 11, color: "var(--ink-400)", fontFamily: "var(--font-mono)",
                letterSpacing: "0.06em",
              }}>Abmelden</a>
            </div>
          </div>
        ) : (
          <a
            href="/api/auth/login"
            className="btn btn-primary"
            style={{ display: "block", textAlign: "center", textDecoration: "none", marginBottom: 16 }}
          >
            Mit Twitch einloggen
          </a>
        )}
        <SidebarQuote />
      </div>
    </aside>
  );
}

// Zitat unten links. Mit dem Update „Zitate“ (Admin → Updates) kommt bei jedem
// Laden ein zufälliges aus QUOTES und wechselt alle 45 Sekunden; sonst der Klassiker.
const DEFAULT_QUOTES = [
  { by: "tjon_tjon", text: "Ich muss los. Tschuss." },
  { by: "EpvpDani", text: "Ja moin" },
  { by: "FrauKonzerte", text: "HYPERS" },
  { by: "DoJa", text: "Bin ich dumm?" },
  { by: "Namodia", text: "Du bist nicht dumm DoJa^^" },
  { by: "felix_dtrx", text: "Salve" },
];
function SidebarQuote() {
  const QUOTES = Array.isArray(window.QUOTES_LIST) ? window.QUOTES_LIST : DEFAULT_QUOTES;
  const on = !!((window.FEATURES && window.FEATURES.quotes) || (window.MY_FEATURES && window.MY_FEATURES.quotes));
  const pick = () => Math.floor(Math.random() * QUOTES.length);
  const [i, setI] = useAppState(pick);
  useAppEffect(() => {
    if (!on || QUOTES.length < 2) return;
    const id = setInterval(() => setI((x) => (x + 1 + Math.floor(Math.random() * (QUOTES.length - 1))) % QUOTES.length), 45000);
    return () => clearInterval(id);
  }, [on]);
  const q = on && QUOTES[i % QUOTES.length] ? QUOTES[i % QUOTES.length] : { by: "DoJa", text: "Schön, dass du da bist." };
  return (
    <>
      <div className="quote">„{q.text}“</div>
      <div className="quote-by">{q.by}</div>
    </>
  );
}

// Prompt shown to logged-out visitors.
function LoginGate() {
  return (
    <div className="empty">
      <h3>Logg dich ein</h3>
      <div>Melde dich mit Twitch an, um dein Inventar und deine Sammlung zu sehen.</div>
      <a
        href="/api/auth/login"
        className="btn btn-primary"
        style={{ display: "inline-block", textDecoration: "none", marginTop: 20 }}
      >
        Mit Twitch einloggen
      </a>
    </div>
  );
}

// Weihnachtskarte für „Nur ich“-Tests: steht noch nicht im öffentlichen Katalog,
// also aus /api/me nachtragen, damit Sammlung und Kalender sie kennen.
function addAdventCard(m) {
  addMeCard(m && m.fluch && m.fluch.card);
  const c = m && m.advent && m.advent.card;
  if (!c || (window.ALL_CARDS || []).some((x) => x.id === c.id)) return;
  window.ALL_CARDS = [...(window.ALL_CARDS || []), { id: c.id, name: c.name, rarity: c.rarity, num: c.num, set: c.card_set, image: c.image, desc: c.descr }];
}

// Fluchkassen-Karte für „Nur ich“-Tests genauso nachtragen.
function addMeCard(c) {
  if (!c || (window.ALL_CARDS || []).some((x) => x.id === c.id)) return;
  window.ALL_CARDS = [...(window.ALL_CARDS || []), { id: c.id, name: c.name, rarity: c.rarity, num: c.num, set: c.card_set, image: c.image, desc: c.descr }];
}

function App() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const [view, setView] = useAppState("home");
  const [me, setMe] = useAppState(null); // null = loading; else { user, inventory, cards }
  const [leaders, setLeaders] = useAppState([]);
  // Ranglisten je Set ({ zero, minecraft? }) für die Tabs der Bestenliste.
  const [leaderSets, setLeaderSets] = useAppState({});
  const [leaderBoard, setLeaderBoard] = useAppState(null);
  const [opening, setOpening] = useAppState(null);
  // Another user's public profile.
  // profileData: null = loading, false = not found, else { user, cards }.
  const [profileLogin, setProfileLogin] = useAppState(null);
  const [profileData, setProfileData] = useAppState(null);

  // Load another user's collection and switch to their profile.
  function openProfile(login) {
    if (!login) return;
    setProfileLogin(login);
    setProfileData(null);
    setView("profile");
    if (window.location.hash !== "#u/" + login) window.location.hash = "u/" + login;
    fetch("/api/leaderboard?login=" + encodeURIComponent(login))
      .then((r) => (r.ok ? r.json() : Promise.reject(r)))
      .then((d) => setProfileData(d))
      .catch(() => setProfileData(false));
  }

  // Load account, inventory, cards and leaderboard from the backend.
  function refreshMe() {
    return Promise.all([
      fetch("/api/me").then((r) => r.json()),
      fetch("/api/leaderboard").then((r) => r.json()).catch(() => ({ leaders: [] })),
    ])
      .then(([m, lb]) => { window.MY_FEATURES = (m && m.features) || {}; addAdventCard(m); setMe(m); setLeaders(lb.leaders || []); setLeaderSets(lb.sets || {}); setLeaderBoard(lb.board || null); })
      .catch(() => { setMe({ user: null, inventory: [], cards: [] }); setLeaders([]); setLeaderSets({}); setLeaderBoard(null); });
  }
  useAppEffect(() => { refreshMe(); }, []);

  // Shareable profile links: #u/<login> opens another user's profile.
  // Code deep links: #c/<code> (z.B. aus QR-Codes) prefills the redeem box.
  const [codePrefill, setCodePrefill] = useAppState("");
  useAppEffect(() => {
    function fromHash() {
      const m = (window.location.hash || "").match(/^#u\/(.+)$/);
      if (m) openProfile(decodeURIComponent(m[1]));
      const c = (window.location.hash || "").match(/^#c\/(.+)$/);
      if (c) {
        setCodePrefill(decodeURIComponent(c[1]));
        setView("inventory");
      }
      // Direktlinks auf Seiten, z.B. für !packs im Chat:
      // #infos, #infos/packs (Abschnitt aufgeklappt), #fluchkasse
      const v = (window.location.hash || "").match(/^#(infos|fluchkasse|bestenliste)(?:\/([a-z]+))?$/i);
      if (v) {
        const page = { infos: "infos", fluchkasse: "fluch", bestenliste: "leaderboard" }[v[1].toLowerCase()];
        window.INFO_JUMP = page === "infos" && v[2] ? v[2].toLowerCase() : null;
        setView(page);
        if (window.INFO_JUMP) window.dispatchEvent(new Event("infojump"));
        // Hash wieder entfernen, damit Neuladen nicht hängen bleibt und der
        // Link beim nächsten Klick erneut greift.
        try { history.replaceState(null, "", window.location.pathname + window.location.search); } catch (e) {}
      }
    }
    fromHash();
    window.addEventListener("hashchange", fromHash);
    return () => window.removeEventListener("hashchange", fromHash);
  }, []);

  // Redeem a one-time pack code; resolves to the server result either way.
  function redeemCode(code) {
    return fetch("/api/me", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ code }),
    })
      .then((r) => r.json().then((d) => ({ ok: r.ok && d.ok, ...d })))
      .then((d) => {
        if (d.ok) refreshMe();
        return d;
      })
      .catch(() => ({ ok: false, error: "Netzwerkfehler, versuch es gleich nochmal." }));
  }

  // Background depth tweak.
  useAppEffect(() => {
    const root = document.documentElement;
    if (t.background === "vivid")        root.style.setProperty("--bg-deep", "#0A0A0B");
    else if (t.background === "deep")    root.style.setProperty("--bg-deep", "#000000");
    else if (t.background === "twilight")root.style.setProperty("--bg-deep", "#15151A");
  }, [t.background]);

  const user = me && me.user;
  const inventory = ((me && me.inventory) || []).map((x) => ({
    id: "inv-" + x.pack_tier,
    pack: (packForTier(x.pack_tier) || {}).id,
    tier: x.pack_tier,
    count: x.count,
  }));
  // owned = aktuell besessen (Badge oben rechts, Duplikat-Filter),
  // drawn = insgesamt gezogen (Kartenmodal, "Gezogen"-Statistik, Badges).
  const owned = {};
  const drawn = {};
  for (const c of ((me && me.cards) || [])) {
    owned[c.card_id] = c.count;
    drawn[c.card_id] = Math.max(c.count, c.drawn || 0);
  }
  const invCount = inventory.reduce((s, it) => s + it.count, 0);

  // Open a pack — server-authoritative: backend consumes the pack and draws the card.
  function openInv(it) {
    const pack = PACKS.find((p) => p.id === it.pack);
    if (!pack) return;
    fetch("/api/open", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ tier: it.tier }),
    })
      .then((r) => (r.ok ? r.json() : Promise.reject(r)))
      .then((data) => {
        const card = ALL_CARDS.find((c) => c.id === data.card_id);
        // `owned` reflects the collection before this draw (refreshMe runs on close),
        // so a missing entry means this card is new for the user.
        const isNew = card && !owned[card.id];
        setOpening({ pack, cards: [{ ...card, isNew }], onComplete: refreshMe });
      })
      .catch(() => alert("Pack konnte nicht geöffnet werden. Lad die Seite neu und versuch es erneut."));
  }
  function closeOpening() {
    if (opening) opening.onComplete();
    setOpening(null);
  }

  // Splitter: Duplikate eintauschen. Server bucht atomar; wir übernehmen die
  // zurückgemeldeten Werte direkt in den State (kein voller Reload nötig).
  function exchangeCards(cardId, amount) {
    return fetch("/api/me", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ exchange: { card_id: cardId, amount } }),
    })
      .then((r) => r.json().then((d) => ({ ok: r.ok && d.ok, ...d })))
      .then((d) => {
        if (d.ok) {
          setMe((m) => ({
            ...m,
            shards: d.shards,
            cards: (m.cards || []).map((c) => (c.card_id === cardId ? { ...c, count: d.count } : c)),
          }));
        }
        return d;
      })
      .catch(() => ({ ok: false, error: "Netzwerkfehler, versuch es gleich nochmal." }));
  }

  // Splitter: Pack kaufen — landet im Inventar wie ein Twitch-Pack.
  function buyPack(tier) {
    return fetch("/api/me", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ buy: { tier } }),
    })
      .then((r) => r.json().then((d) => ({ ok: r.ok && d.ok, ...d })))
      .then((d) => {
        if (d.ok) {
          setMe((m) => {
            const inv = [...(m.inventory || [])];
            const i = inv.findIndex((x) => x.pack_tier === tier);
            if (i >= 0) inv[i] = { ...inv[i], count: d.count };
            else inv.push({ pack_tier: tier, count: d.count });
            return { ...m, shards: d.shards, inventory: inv };
          });
        }
        return d;
      })
      .catch(() => ({ ok: false, error: "Netzwerkfehler, versuch es gleich nochmal." }));
  }

  // Save the up-to-3 showcase badges; server echoes the validated list back.
  function saveShowcase(list) {
    return fetch("/api/me", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ showcase: list }),
    })
      .then((r) => (r.ok ? r.json() : Promise.reject(r)))
      .then((d) => {
        if (Array.isArray(d.showcase)) setMe((m) => ({ ...m, showcase: d.showcase }));
        // Leaderboard shows the picks — refresh it in the background.
        fetch("/api/leaderboard").then((r) => r.json()).then((lb) => { setLeaders(lb.leaders || []); setLeaderSets(lb.sets || {}); setLeaderBoard(lb.board || null); }).catch(() => {});
      })
      .catch(() => alert("Auswahl konnte nicht gespeichert werden. Versuch es gleich nochmal."));
  }

  function goBack() {
    if (window.location.hash) window.location.hash = "";
    setView("leaderboard");
  }

  // Build owned/drawn maps from the loaded profile response.
  const profileOwned = {};
  const profileDrawn = {};
  if (profileData && profileData.cards) {
    for (const c of profileData.cards) {
      profileOwned[c.card_id] = c.count;
      profileDrawn[c.card_id] = Math.max(c.count, c.drawn || 0);
    }
  }

  let content;
  if (view === "home") {
    content = <HomeView go={setView} leaders={leaders} me={me} refreshMe={refreshMe} />;
  } else if (view === "profile") {
    // Public — no login required.
    content = (
      <PublicProfileView
        profile={profileData === null ? null : (profileData ? profileData.user : false)}
        owned={profileOwned}
        drawn={profileDrawn}
        badges={(profileData && profileData.badges) || []}
        fluch={profileData && profileData.fluch}
        onBack={goBack}
      />
    );
  } else if (view === "infos" && window.infosVisible && infosVisible()) {
    // Öffentlich, auch ohne Login.
    content = <InfosView me={me} go={setView} />;
  } else if (view === "fluch" && window.fluchVisible && fluchVisible()) {
    // Öffentlich, auch ohne Login.
    content = <FluchView me={me} onUser={openProfile} />;
  } else if (view === "leaderboard") {
    // Öffentlich, auch ohne Login.
    content = <LeaderboardView user={user} leaders={leaders} leaderSets={leaderSets} board={leaderBoard} onUser={openProfile} />;
  } else if (me === null) {
    content = <div className="empty"><h3>Lädt …</h3></div>;
  } else if (!user) {
    content = <LoginGate />;
  } else if (view === "inventory") {
    content = <InventoryView inventory={inventory} openInv={openInv} redeemCode={redeemCode} codePrefill={codePrefill} />;
  } else if (view === "collection") {
    content = <CollectionView owned={owned} drawn={drawn} />;
  } else if (view === "shards" && window.SHARDS_ENABLED) {
    const Shards = window.splitterTabsVisible && splitterTabsVisible() ? ShardsTabsView : ShardsView;
    content = (
      <Shards
        owned={owned}
        drawn={drawn}
        shards={me.shards || 0}
        inventory={inventory}
        onExchange={exchangeCards}
        onBuy={buyPack}
        go={setView}
      />
    );
  } else if (view === "badges" && window.BADGES_ENABLED) {
    content = (
      <BadgesView
        badges={me.badges || []}
        stats={me.badgeStats || null}
        showcase={me.showcase || []}
        onSaveShowcase={saveShowcase}
      />
    );
  } else if (view === "me") {
    content = <ProfileView owned={owned} drawn={drawn} user={user} leaders={leaders} freePack={me && me.freePack} freePackMc={me && me.freePackMc} badgeStats={me && me.badgeStats} badges={me.badges || []} showcase={me.showcase || []} goBadges={() => setView("badges")} shards={me.shards || 0} goShards={() => setView("shards")} fluch={me.fluch} goBoard={() => setView("leaderboard")} />;
  }

  return (
    <>
      <div className="app">
        <Sidebar current={view} go={setView} invCount={invCount} user={user} />
        <main className="main" data-screen-label={`${NAV_ITEMS.findIndex(n => n.id === view) + 1} ${view}`}>
          {content}
        </main>
      </div>

      {opening && (
        <PackOpening
          pack={opening.pack}
          cards={opening.cards}
          onClose={closeOpening}
          dramaIntensity={t.drama}
        />
      )}

      <TweaksPanel title="Tweaks">
        <TweakSection label="Hintergrund-Tiefe">
          <TweakRadio
            value={t.background}
            options={[
              { value: "vivid",    label: "Lebendig" },
              { value: "twilight", label: "Hell" },
              { value: "deep",     label: "Tief" },
            ]}
            onChange={(v) => setTweak("background", v)}
          />
        </TweakSection>

        <TweakSection label="Pack-Drama">
          <TweakSlider
            label="Intensität"
            min={0} max={10} step={1}
            value={t.drama}
            onChange={(v) => setTweak("drama", v)}
          />
        </TweakSection>
      </TweaksPanel>
    </>
  );
}

// Load catalog (cards + packs) from the DB, then render. Components read
// ALL_CARDS / PACKS as globals, so we overwrite them before the first render.
// On fetch failure the data.jsx values stay as fallback so the page always renders.
async function bootApp() {
  try {
    const r = await fetch("/api/catalog");
    if (r.ok) {
      const d = await r.json();
      if (Array.isArray(d.cards) && d.cards.length) window.ALL_CARDS = d.cards;
      if (Array.isArray(d.packs) && d.packs.length) window.PACKS = d.packs;
      // Laufzeit-Schalter fürs Badge-System (Admin-Dashboard → DB → hier).
      if (typeof d.badgesEnabled === "boolean") window.BADGES_ENABLED = d.badgesEnabled;
      // Laufzeit-Schalter + Tauschwerte fürs Splitter-System.
      if (typeof d.shardsEnabled === "boolean") window.SHARDS_ENABLED = d.shardsEnabled;
      if (d.shardValues && typeof d.shardValues === "object") window.SHARD_VALUES = d.shardValues;
      window.MC_PACK_INFO = d.mcPackInfo || null;
      // Launch-Schalter Minecraft Edition (Admin-Dashboard → DB → hier).
      if (typeof d.minecraftEnabled === "boolean") window.MINECRAFT_ENABLED = d.minecraftEnabled;
      // Launch-Schalter Promo-Karten.
      if (typeof d.promoEnabled === "boolean") window.PROMO_ENABLED = d.promoEnabled;
      // Neue Updates, die für alle live sind (Admin → Updates).
      if (d.features && typeof d.features === "object") window.FEATURES = d.features;
      // Zitate unten links (Admin → Zitate).
      if (Array.isArray(d.quotes)) window.QUOTES_LIST = d.quotes;
    }
  } catch (e) {
    // Network/server error: data.jsx fallback stays active.
  }
  // Vor dem Launch keine Minecraft-Inhalte zeigen — auch nicht aus dem
  // data.jsx-Fallback (der Server filtert /api/catalog bereits selbst).
  if (!window.MINECRAFT_ENABLED) {
    window.ALL_CARDS = window.ALL_CARDS.filter((c) => c.rarity !== "special");
    window.PACKS = window.PACKS.filter((p) => !isSpecialPack(p));
  }
  if (!window.PROMO_ENABLED) {
    window.ALL_CARDS = window.ALL_CARDS.filter((c) => c.rarity !== "promo");
  }
  ReactDOM.createRoot(document.getElementById("root")).render(<App />);
}
bootApp();
