// brownie/data.jsx — all static content for Brownie Empire.
// Original producer lineup, upgrades, and achievements designed from scratch.
//
// The player taps a brownie square to bake Crumbs (the main currency).
// 18 producers each generate passive Crumbs/sec.
// Prestige currency is "Fudge Crumbs" — granted on reset based on total baked.

// ──────────────────────────────────────────────────────────────────────
// PRODUCERS — 18-tier escalation arc.
//
// Arc: hand tools → home kitchen → neighborhood → small biz → industrial
//      → regional → national → global → surreal.
//
// Prices follow a gentle geometric curve. Early tiers are cheap and fast;
// late tiers have much higher bps but longer time-to-buy.
// ──────────────────────────────────────────────────────────────────────

const PRODUCERS = [
  // Tier 1 — hand tools & home baker
  { id: 'spoon',      name: 'Wooden Spoon',     tagline: 'stirs batter by hand',        basePrice: 15,            baseBps: 0.1,     unlockAt: 0 },
  { id: 'whisk',      name: 'Whisk',            tagline: 'whips up air pockets',        basePrice: 100,           baseBps: 1,       unlockAt: 0 },
  { id: 'mixer',      name: 'Stand Mixer',      tagline: 'the upgrade every kitchen needs', basePrice: 1100,       baseBps: 8,       unlockAt: 150 },
  { id: 'oven',       name: 'Home Oven',        tagline: 'your trusty kitchen workhorse', basePrice: 12_000,       baseBps: 47,      unlockAt: 2000 },
  // Tier 2 — neighborhood
  { id: 'stall',      name: 'Bake Stall',       tagline: 'weekend market pop-up',       basePrice: 130_000,       baseBps: 260,     unlockAt: 20_000 },
  { id: 'foodtruck',  name: 'Food Truck',       tagline: 'brownies on the move',        basePrice: 1_400_000,     baseBps: 1_400,   unlockAt: 250_000 },
  { id: 'bakery',     name: 'Corner Bakery',    tagline: 'your first real storefront',  basePrice: 20_000_000,    baseBps: 7_800,   unlockAt: 3_000_000 },
  // Tier 3 — small biz to industrial
  { id: 'chain',      name: 'Bakery Chain',     tagline: 'three locations, one recipe', basePrice: 330_000_000,   baseBps: 44_000,  unlockAt: 50_000_000 },
  { id: 'warehouse',  name: 'Warehouse Kitchen',tagline: 'industrial-scale baking',     basePrice: 5.1e9,         baseBps: 260_000, unlockAt: 8e8 },
  { id: 'factory',    name: 'Brownie Factory',  tagline: 'conveyor belts of fudge',     basePrice: 75e9,          baseBps: 1.6e6,   unlockAt: 1.2e10 },
  // Tier 4 — regional to national
  { id: 'farm',       name: 'Cocoa Farm',       tagline: 'grows the magic bean',        basePrice: 1e12,          baseBps: 10e6,    unlockAt: 1.6e11 },
  { id: 'plantation', name: 'Chocolate Plantation', tagline: 'endless rows of cacao',    basePrice: 14e12,         baseBps: 65e6,    unlockAt: 2.3e12 },
  { id: 'lab',        name: 'Flavor Lab',       tagline: 'science-grade deliciousness', basePrice: 170e12,        baseBps: 430e6,   unlockAt: 2.8e13 },
  // Tier 5 — global
  { id: 'hq',         name: 'Global HQ',        tagline: 'boardrooms of brownie',       basePrice: 2.1e15,        baseBps: 2.9e9,   unlockAt: 3.4e14 },
  { id: 'academy',    name: 'Baking Academy',   tagline: 'trains the next generation',  basePrice: 26e15,         baseBps: 21e9,    unlockAt: 4.2e15 },
  // Tier 6 — surreal / fantastic
  { id: 'vault',      name: 'Fudge Vault',      tagline: 'compressed crumb matter',     basePrice: 310e15,        baseBps: 150e9,   unlockAt: 5e16 },
  { id: 'dimension',  name: 'Cocoa Dimension',  tagline: 'a plane of pure chocolate',   basePrice: 71e18,         baseBps: 1.1e12,  unlockAt: 1.1e19 },
  { id: 'ancestor',   name: 'Brownie Ancestor', tagline: 'the first baker, returned',   basePrice: 12e21,         baseBps: 8e12,    unlockAt: 1.9e21 },
];

// ──────────────────────────────────────────────────────────────────────
// UPGRADES — tiered per-producer multipliers + special effects.
// Each producer has 3 tiered upgrades (unlock at 1/10/50 owned) that
// double its output. Plus a handful of "mega" upgrades that tweak the
// game globally.
// ──────────────────────────────────────────────────────────────────────

const UPGRADES = [];

// Per-producer tiered upgrades (name, required owned count, cost multiplier of basePrice)
const PRODUCER_UP_TIERS = [
  { owned: 1,  priceMult: 10,    effect: 2, label: 'Sharper' },
  { owned: 10, priceMult: 100,   effect: 2, label: 'Heavy-duty' },
  { owned: 50, priceMult: 10000, effect: 2, label: 'Legendary' },
];

for (const p of PRODUCERS) {
  for (const tier of PRODUCER_UP_TIERS) {
    UPGRADES.push({
      id: `up_${p.id}_${tier.owned}`,
      name: `${tier.label} ${p.name}`,
      desc: `${p.name} production ×${tier.effect}`,
      price: Math.round(p.basePrice * tier.priceMult),
      unlockOwned: { pid: p.id, n: tier.owned },
      multiplier: { pid: p.id, value: tier.effect },
    });
  }
}

// Global / tap upgrades
UPGRADES.push(
  { id: 'tap_1', name: 'Rolling Pin',   desc: 'Taps give ×2 crumbs',           price: 1000,      tapMult: 2,     unlockEarned: 500 },
  { id: 'tap_2', name: 'Sugar Rush',    desc: 'Taps give another ×2',          price: 500_000,   tapMult: 2,     unlockEarned: 250_000 },
  { id: 'tap_3', name: 'Fudge Fingers', desc: 'Taps give another ×2',          price: 50e9,      tapMult: 2,     unlockEarned: 10e9 },
  { id: 'tap_4', name: 'Divine Pinch',  desc: 'Taps give another ×5',          price: 1e15,      tapMult: 5,     unlockEarned: 5e14 },
  { id: 'glob_1', name: 'Premium Cocoa',  desc: 'All production ×1.25',        price: 1e6,        globalMult: 1.25, unlockEarned: 5e5 },
  { id: 'glob_2', name: 'Artisan Touch',  desc: 'All production ×1.25',        price: 1e9,        globalMult: 1.25, unlockEarned: 5e8 },
  { id: 'glob_3', name: 'Secret Recipe',  desc: 'All production ×1.5',         price: 1e12,       globalMult: 1.5,  unlockEarned: 5e11 },
  { id: 'glob_4', name: 'Fudge Perfection', desc: 'All production ×2',         price: 1e16,       globalMult: 2,    unlockEarned: 5e15 },
);

// ──────────────────────────────────────────────────────────────────────
// ACHIEVEMENTS — each gives a small permanent +1% global mult.
// Mix of milestones, producer counts, prestige milestones.
// ──────────────────────────────────────────────────────────────────────

const ACHIEVEMENTS = [];

// Total baked milestones
for (const n of [100, 10_000, 1e6, 1e9, 1e12, 1e15, 1e18]) {
  ACHIEVEMENTS.push({
    id: `baked_${n}`,
    name: `Baked ${fmtShort(n)}`,
    desc: `Bake a total of ${fmtShort(n)} crumbs`,
    test: (s) => s.totalEarned >= n,
  });
}

// Total taps milestones
for (const n of [100, 1000, 10_000, 100_000]) {
  ACHIEVEMENTS.push({
    id: `taps_${n}`,
    name: `Sore Thumbs (${fmtShort(n)})`,
    desc: `Tap the brownie ${fmtShort(n)} times`,
    test: (s) => s.totalTaps >= n,
  });
}

// Producer count milestones — 1/25/100/200 of each producer
for (const p of PRODUCERS) {
  for (const n of [1, 25, 100]) {
    ACHIEVEMENTS.push({
      id: `own_${p.id}_${n}`,
      name: `${n}× ${p.name}`,
      desc: `Own ${n} ${p.name}${n > 1 ? 's' : ''}`,
      test: (s) => (s.producers[p.id] || 0) >= n,
    });
  }
}

// Prestige milestones
for (const n of [1, 100, 10_000, 1e6]) {
  ACHIEVEMENTS.push({
    id: `fudge_${n}`,
    name: `${fmtShort(n)} Fudge Crumbs`,
    desc: `Earn ${fmtShort(n)} Fudge Crumbs total`,
    test: (s) => (s.lifetimeFudge || 0) >= n,
  });
}

function fmtShort(n) {
  if (!isFinite(n)) return '0';
  if (n < 0) return '-' + fmtShort(-n);
  if (n < 1) return n === 0 ? '0' : n.toFixed(2);
  if (n < 10) return n.toFixed(1);
  if (n < 1000) return String(Math.floor(n));
  const units = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'Dc'];
  let u = -1;
  while (n >= 1000 && u < units.length - 1) { n /= 1000; u++; }
  return `${n.toFixed(n < 10 ? 2 : n < 100 ? 1 : 0)}${units[u]}`;
}

// ──────────────────────────────────────────────────────────────────────
// Exports
// ──────────────────────────────────────────────────────────────────────

Object.assign(window, { BE_PRODUCERS: PRODUCERS, BE_UPGRADES: UPGRADES, BE_ACHIEVEMENTS: ACHIEVEMENTS, beFmt: fmtShort });
