// Milestone data + shared helpers

const MILESTONES = [
  {
    n: "I",
    icon: "seed",
    title: "Plant the Seed",
    goal: 50000,
    cumulative: 50000,
    blurb: "Launch the Head Start program. Secure our first facility. Build the foundational systems. Open the doors to our first children.",
    bullets: ["Head Start program launch", "Facility lease secured", "Foundational operations", "First cohort enrolled"],
  },
  {
    n: "II",
    icon: "sprout",
    title: "Establish the Foundation",
    goal: 150000,
    cumulative: 200000,
    blurb: "Expand operations, begin the search for permanent land, complete legal and planning work, and grow the community around the vision.",
    bullets: ["Operational expansion", "Land search begins", "Legal & planning work", "Community formation"],
  },
  {
    n: "III",
    icon: "tree",
    title: "Secure the Land",
    goal: 1000000,
    cumulative: 1200000,
    blurb: "Purchase the land that will become New Eden. Begin architectural master planning. Prepare the site for what is to come.",
    bullets: ["Land purchased", "Master plan drafted", "Site development plan", "Zoning & permits"],
  },
  {
    n: "IV",
    icon: "build",
    title: "Build the School",
    goal: 7500000,
    goalLabel: "$5M – $10M",
    cumulative: 10000000,
    blurb: "Break ground on the main academic building. Launch the elementary program. Hire core faculty and expand our service to families.",
    bullets: ["Academic building construction", "Elementary program launch", "Staff & faculty expansion", "K–4 enrollment"],
  },
  {
    n: "V",
    icon: "campus",
    title: "Expand the Academy",
    goal: 20000000,
    goalLabel: "$15M – $30M",
    cumulative: 30000000,
    blurb: "Add middle-school grades. Raise the Dining Hall and Town Hall — the heart of daily academy life. Deepen the program.",
    bullets: ["Middle school grades added", "Dining Hall built", "Town Hall built", "Facilities expansion"],
  },
  {
    n: "VI",
    icon: "home",
    title: "Student Living",
    goal: 35000000,
    goalLabel: "$30M – $60M",
    cumulative: 60000000,
    blurb: "Build boys' and girls' dormitories. Launch the full residential program for grades 5–12. Welcome students to live and learn on grounds.",
    bullets: ["Boys' dormitory", "Girls' dormitory", "Residential program (5–12)", "Residential staff hired"],
  },
  {
    n: "VII",
    icon: "crown",
    title: "Stadium Partner",
    goal: null,
    goalLabel: "Partnership",
    cumulative: null,
    blurb: "Secure a naming-rights partner to anchor the stadium before we break ground. Align the vision with a committed partner for the generations ahead.",
    bullets: ["Naming-rights partner", "Stadium vision aligned", "Partnership finalized", "Groundbreaking prepared"],
  },
  {
    n: "VIII",
    icon: "stadium",
    title: "Legacy Build",
    goal: 50000000,
    goalLabel: "$80M – $120M",
    cumulative: 120000000,
    blurb: "Complete the athletic facilities. Raise the New Eden Stadium. Expand the grounds to match the full vision — a place that endures for generations.",
    bullets: ["Full athletic facilities", "New Eden Stadium", "Track & field, courts", "Grounds completion"],
  },
];

// starting state — used by progress bar. Feel free to nudge from tweaks.
const INITIAL_RAISED = 85000;
const FINAL_GOAL = 120000000;

function formatMoney(n, { compact = false } = {}) {
  if (n == null) return "—";
  if (compact) {
    if (n >= 1e9) return `$${(n/1e9).toFixed(1)}B`;
    if (n >= 1e6) return `$${(n/1e6).toFixed(n >= 1e7 ? 0 : 1)}M`;
    if (n >= 1e3) return `$${(n/1e3).toFixed(0)}K`;
    return `$${n}`;
  }
  return "$" + n.toLocaleString("en-US");
}

// status based on cumulative raised
function statusFor(milestone, raised) {
  if (milestone.cumulative == null) {
    return raised >= FINAL_GOAL ? "complete" : "locked";
  }
  if (raised >= milestone.cumulative) return "complete";
  const prev = MILESTONES[MILESTONES.indexOf(milestone) - 1];
  const prevCum = prev ? prev.cumulative : 0;
  if (raised > prevCum) return "progress";
  return "locked";
}

// Small glyph pack (original icons — simple line shapes)
function Glyph({ name, size = 28, stroke = "currentColor", strokeWidth = 1.3 }) {
  const s = size;
  const common = { fill: "none", stroke, strokeWidth, strokeLinecap: "round", strokeLinejoin: "round" };
  switch (name) {
    case "seed":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <path d="M16 26 V14" />
          <path d="M16 14 C 10 14 8 10 8 8 C 12 8 16 10 16 14" />
          <path d="M16 14 C 22 14 24 10 24 8 C 20 8 16 10 16 14" />
          <path d="M11 26 Q 16 23 21 26" />
        </svg>
      );
    case "sprout":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <path d="M16 28 V12" />
          <path d="M16 16 C 10 16 7 12 7 9 C 12 9 16 12 16 16" />
          <path d="M16 20 C 22 20 26 17 26 13 C 21 13 16 16 16 20" />
          <path d="M9 28 H 23" />
        </svg>
      );
    case "tree":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <path d="M16 28 V16" />
          <circle cx="16" cy="11" r="7" />
          <path d="M16 11 L 12 15 M 16 11 L 20 15 M 16 16 V 11" />
        </svg>
      );
    case "build":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <path d="M5 27 H 27" />
          <path d="M8 27 V 14 L 16 9 L 24 14 V 27" />
          <path d="M13 27 V 20 H 19 V 27" />
          <path d="M12 10 V 6 H 20 V 10" />
        </svg>
      );
    case "campus":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <path d="M3 27 H 29" />
          <path d="M5 27 V 17 L 12 13 L 19 17 V 27" />
          <path d="M19 27 V 19 L 25 16 L 29 19 V 27" />
          <path d="M9 27 V 22 H 15 V 27" />
        </svg>
      );
    case "home":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <path d="M4 15 L 16 6 L 28 15" />
          <path d="M7 13 V 27 H 25 V 13" />
          <path d="M13 27 V 18 H 19 V 27" />
          <path d="M16 6 V 3" />
        </svg>
      );
    case "stadium":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <ellipse cx="16" cy="18" rx="12" ry="6" />
          <path d="M4 14 V 18 M 28 14 V 18" />
          <ellipse cx="16" cy="14" rx="12" ry="6" />
          <path d="M10 14 V 18 M 16 14 V 18 M 22 14 V 18" />
        </svg>
      );
    case "crown":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <path d="M5 22 L 7 10 L 12 16 L 16 8 L 20 16 L 25 10 L 27 22 Z" />
          <path d="M5 26 H 27" />
        </svg>
      );
    case "leaf":
      return (
        <svg width={s} height={s} viewBox="0 0 32 32" {...common}>
          <path d="M6 26 C 6 14 14 6 26 6 C 26 18 18 26 6 26 Z" />
          <path d="M6 26 L 22 10" />
        </svg>
      );
    default:
      return null;
  }
}

Object.assign(window, { MILESTONES, INITIAL_RAISED, FINAL_GOAL, formatMoney, statusFor, Glyph });
