/* ============================================================
   IRONLOG — Centralized mock data.
   Everything the UI reads lives here. Swap for real API later.
   Exposed on window.IRONLOG.
   ============================================================ */

const IRONLOG = (function () {
  /* ---------- Athlete / before-after ---------- */
  const profile = {
    name: "MARCUS REYES",
    handle: "the_iron_ledger",
    discipline: "Raw Powerlifting",
    federation: "USPA · 90kg Class",
  };

  const transformation = {
    before: { date: "08/14/2024", bodyweightKg: 74, label: "Before physique" },
    after:  { date: "05/22/2026", bodyweightKg: 91, label: "After physique" },
  };

  /* ---------- Goal ---------- */
  const goal = {
    headline: "GOAL: POWERLIFTER.",
    sub: "A 1000 lb total. No shortcuts, no excuses, no off-season.",
  };

  /* ---------- Personal records ---------- */
  // trend = recent measured values, oldest → newest (for sparkline)
  const prsMain = [
    { id: "dl-conv", lift: "Conventional Deadlift", value: 420, unit: "lbs", trend: [355,370,385,395,405,420], isNew: true,  updated: "05/28/2026" },
    { id: "dl-sumo", lift: "Sumo Deadlift",         value: 375, unit: "lbs", trend: [320,335,345,355,365,375], isNew: false, updated: "05/14/2026" },
    { id: "bench",   lift: "Bench Press",            value: 265, unit: "lbs", trend: [225,235,245,250,258,265], isNew: false, updated: "05/26/2026" },
    { id: "legpress",lift: "Leg Press",              value: 660, unit: "lbs", trend: [520,560,590,610,640,660], isNew: true,  updated: "05/30/2026" },
    { id: "squat",   lift: "Back Squat",             value: 330, unit: "lbs", trend: [275,290,300,310,320,330], isNew: false, updated: "05/19/2026" },
  ];

  const prsOther = [
    { id: "tri-push", lift: "Tricep Pushdown", value: 190, unit: "lbs", trend: [150,160,170,180,185,190], isNew: false, updated: "05/21/2026" },
    { id: "ohp",      lift: "Shoulder Press",  value: 145, unit: "lbs", trend: [115,125,130,135,140,145], isNew: false, updated: "05/12/2026" },
    { id: "curl",     lift: "Strict Curl",     value: 110, unit: "lbs", trend: [85,90,95,100,105,110],     isNew: true,  updated: "05/29/2026" },
    { id: "chest-pr", lift: "Chest Press",     value: 200, unit: "lbs", trend: [160,170,180,190,195,200],  isNew: false, updated: "05/18/2026" },
    { id: "calf",     lift: "Calf Raises",     value: 300, unit: "lbs", trend: [220,245,265,280,290,300],  isNew: false, updated: "05/10/2026" },
    { id: "tbar",     lift: "T-Bar Rows",      value: 200, unit: "lbs", trend: [150,165,175,185,195,200],  isNew: false, updated: "05/23/2026" },
  ];

  /* ---------- Philosophy ---------- */
  const philosophy = {
    body:
      "I do not aim for aesthetics — no chasing abs or a body that looks good on TikTok. " +
      "I train for a body that can move the heaviest weight possible. I do not cut. " +
      "I eat at maintenance, sometimes a little over.\n\n" +
      "The bar does not care how I feel. It does not negotiate. " +
      "Every rep is a deposit, and the only currency the iron respects is consistency.\n\n" +
      "Strength is the one honest number. You either moved it, or you did not.",
    by: "— Marcus, training log",
  };

  /* ---------- Supplements ---------- */
  const supplements = [
    { id: "creatine", name: "Creatine Monohydrate", amount: 10,  unit: "g",   note: "AM + PM split", timing: "Daily" },
    { id: "whey",     name: "Whey Isolate",          amount: 200, unit: "g",   note: "Post-session + before bed", timing: "Daily" },
    { id: "vitd",     name: "Vitamin D3",            amount: 5000,unit: "IU",  note: "With first meal", timing: "Daily" },
    { id: "fish",     name: "Omega-3 (EPA/DHA)",     amount: 3,   unit: "g",   note: "Joint support", timing: "Daily" },
    { id: "caffeine", name: "Caffeine",              amount: 200, unit: "mg",  note: "Pre-training only", timing: "Train days" },
  ];

  /* ---------- Calendar / training log ----------
     Keyed by YYYY-MM-DD. status: 'gym' | 'rest'.
     Gym days carry a full session. */
  const exPool = {
    push: [
      ["Bench Press", "4×5 @ 105kg"], ["Incline DB Press", "3×10 @ 32kg"],
      ["Shoulder Press", "4×8 @ 60kg"], ["Tricep Pushdown", "3×12 @ 75kg"],
      ["Chest Press", "3×10 @ 85kg"],
    ],
    pull: [
      ["Conventional Deadlift", "5×3 @ 175kg"], ["T-Bar Rows", "4×8 @ 85kg"],
      ["Lat Pulldown", "3×12 @ 70kg"], ["Strict Curl", "3×10 @ 45kg"],
      ["Face Pulls", "3×15 @ 30kg"],
    ],
    legs: [
      ["Back Squat", "5×5 @ 140kg"], ["Leg Press", "4×10 @ 280kg"],
      ["Romanian Deadlift", "3×8 @ 120kg"], ["Calf Raises", "4×15 @ 130kg"],
      ["Leg Extension", "3×12 @ 65kg"],
    ],
    sumo: [
      ["Sumo Deadlift", "6×2 @ 165kg"], ["Hip Thrust", "4×8 @ 150kg"],
      ["Leg Press", "3×12 @ 250kg"], ["Hamstring Curl", "3×12 @ 55kg"],
    ],
  };
  const titlePool = {
    push: "Push · Bench Focus", pull: "Pull · Deadlift Focus",
    legs: "Legs · Squat Focus", sumo: "Sumo + Posterior",
  };
  const notePool = [
    "Felt strong off the floor. Grip held all sets.",
    "Bar speed snappy on the top sets — left a rep in the tank.",
    "Lower back a little tight, kept it conservative.",
    "PR attempt next week. Nailed every triple today.",
    "Deload-ish volume. Focused on bracing and tempo.",
    "",
  ];

  function pad(n){ return n < 10 ? "0"+n : ""+n; }
  function key(y,m,d){ return `${y}-${pad(m+1)}-${pad(d)}`; }

  function buildSession(kind, dateLabel) {
    const list = exPool[kind];
    const exercises = list.map(([name, scheme]) => {
      const m = scheme.match(/(\d+)×(\d+)\s*@\s*([\d.]+)(\w+)/);
      const sets = +m[1], reps = +m[2], weight = +m[3], unit = m[4];
      return { name, sets, reps, weight, unit, volume: Math.round(sets*reps*weight) };
    });
    const totalVolume = exercises.reduce((a,e)=>a+e.volume,0);
    return {
      status: "gym",
      title: titlePool[kind],
      date: dateLabel,
      exercises,
      totalVolume,
      durationMin: 62 + Math.floor(Math.random()*38),
      note: notePool[Math.floor(Math.random()*notePool.length)],
    };
  }

  // Weekly template: Mon push, Tue pull, Wed rest, Thu legs, Fri sumo, Sat pull(light)/rest, Sun rest
  function patternFor(dow) {
    // dow: 0 Sun .. 6 Sat
    switch (dow) {
      case 1: return "push";
      case 2: return "pull";
      case 4: return "legs";
      case 5: return "sumo";
      case 6: return Math.random() > 0.45 ? "push" : null;
      default: return null; // Sun, Wed rest
    }
  }

  function buildMonth(year, month /*0-idx*/, fillUntilDay) {
    const days = new Date(year, month+1, 0).getDate();
    const out = {};
    for (let d = 1; d <= days; d++) {
      if (fillUntilDay && d > fillUntilDay) break;
      const dow = new Date(year, month, d).getDay();
      const dateLabel = `${pad(month+1)}/${pad(d)}/${year}`;
      const kind = patternFor(dow);
      if (kind) out[key(year, month, d)] = buildSession(kind, dateLabel);
      else out[key(year, month, d)] = { status: "rest", title: "Rest & Recover", date: dateLabel, exercises: [], totalVolume: 0, note: dow === 0 ? "Full rest. Mobility + sauna." : "Active recovery — 30 min walk." };
    }
    return out;
  }

  // Seed May (full) + June up to the 1st (current date June 1 2026)
  const log = Object.assign(
    {},
    buildMonth(2026, 3),       // April (full, for back-nav)
    buildMonth(2026, 4),       // May (full)
    buildMonth(2026, 5, 1),    // June up to the 1st
  );

  // A couple of hero sessions with richer notes
  if (log["2026-05-28"]) { log["2026-05-28"].note = "420 lb conventional pull — new lifetime PR. The grind paid."; log["2026-05-28"].title = "Pull · PR Day"; }
  if (log["2026-05-30"]) { log["2026-05-30"].note = "660 lb leg press for a clean set of 10. Quads done."; }

  /* ---------- Chat (canned coach responses) ---------- */
  const chatSeed = [
    { id: 1, role: "ai", text: "Coach here. I've got your full log in front of me — deadlift, bench, the calendar, all of it. Ask me anything about your training." },
  ];

  const cannedReplies = [
    "Your conventional deadlift is trending hard — up from 405 to **420 lbs** on 05/28, a fresh lifetime PR. Bar speed in your notes looks crisp, so I'd ride this wave: one more heavy single next week, then back off the volume.",
    "Last Monday (05/26) was a Push · Bench day: Bench 4×5 @ 105kg, Incline DB 3×10 @ 32kg, Shoulder Press 4×8 @ 60kg, and Tricep Pushdown. Total volume landed around 9,200 kg. Solid session.",
    "Comparing bench month-over-month: you closed April at ~258 lbs working tops and hit **265 lbs** in May. That's a ~3% climb — right on pace for a powerlifter holding maintenance calories.",
    "This month you logged a clean training split — roughly 4 gym days a week with Wednesday and Sunday as planned rest. Your streak is intact. Recovery looks managed; no red flags in the notes.",
    "Looking at the image — form check: brace harder before the floor breaks and keep the bar dragging up the shins. Your hips look like they shoot slightly early on the heavy singles. Cue 'push the floor away.'",
    "At 91kg bodyweight with a 420 deadlift, 330 squat, and 265 bench, your estimated total is sitting near **1,015 lbs**. You've crossed the four-plate-deadlift, 1000 lb total milestone. Now we chase the next plate.",
  ];

  const chatChips = [
    "How's my deadlift trending?",
    "What did I lift last Monday?",
    "Compare bench this month vs last",
    "Am I on track for a 1000 lb total?",
  ];

  return {
    profile, transformation, goal,
    prsMain, prsOther, philosophy, supplements,
    log, chatSeed: chatSeed, cannedReplies, chatChips,
    helpers: { pad, key },
  };
})();

window.IRONLOG = IRONLOG;
