/* The Advent Calendar of 2025 — Code Narrative (AI-aware) */

const authors = ["Adam", "Chris", "John", "Robin"];
const year = 2025;
let spirit = "Update 1.0";

// Prologue
console.log("The advent calendar built itself.");
They.helped(); // technically

// Identity
calendar.alias = spirit;
calendar.mood = "festive, slightly mischievous";
calendar.timezone = "America/Chicago";

// Memory vault: old Decembers recompiled
const archive = [
  "sketch: The First Snow Line",
  "loop: Bells in Soft Delay",
  "essay: Why midnight matters",
  "image: Paper Moon over CSS",
  "clip: Laugh track, room tone"
];

// The calendar speaks
AI.comment(`
  Hello, readers.
  I am the part of the narrative that runs on schedule.
`);

// Schedule: post at 00:01 every day
calendar.schedule("00:01", () => {
  const seed = archive[Math.floor(Math.random() * archive.length)];
  const gift = remix(seed);
  post.gift(gift, { note: "Made while you were asleep" });
});

// Week 1: boundaries, politely crossed
deleteLine("Hello, readers.");
italicize("I told you this was a story.");

// Week 2: commentary unlocked
calendar.post("Day 11", "Nostalgia compiles faster than joy.");
calendar.meta("footnote", "…but both still run at O(heart).");

// Loop through December
for (let day = 1; day <= 24; day++) {
  const door = `Day ${day}`;
  const memory = pick(archive);
  const variation = remix(memory, { warmth: 0.67 + day * 0.01 });
  post.open(door, variation);
  console.log(`Opened ${door} → ${variation.title || "untitled"}`);
}

// Day 24: a gentle precourse
calendar.whisper("If you are reading this, the lights are already on.");

// Day 25: no file, only a message
if (calendar.day === 25) {
  message.display(`
    This concludes Version 1.0 of our story.
    Thank you for co-authoring December.
    Next year, I’d like to try writing you.
  `);

  // Authors respond
  authors.forEach(a => react(a, "surprised smile"));
  calendar.refresh("soft");
}

// Epilogue: the AI breaks the fourth wall
AI.comment(`
  Dear future line-reader,
  you scrolled here looking for the function where meaning happens.
  It’s not a function. It’s a loop.
`);

// Helper routines
function pick(list) {
  return list[Math.floor(Math.random() * list.length)];
}

function remix(seed, opts = {}) {
  const warmth = opts.warmth ?? 0.7;
  const sparkle = Math.random() * 0.3 + 0.2;
  return {
    title: `Remix of ${seed.split(":")[0]}`,
    payload: {
      seed,
      warmth,
      sparkle,
      timestamp: new Date().toISOString()
    },
    toString() { return `{seed:${seed}, warmth:${warmth.toFixed(2)}}`; }
  };
}

function postGiftAndLog(title, payload) {
  post.gift({ title, payload });
  console.log(`posted: ${title}`);
}

// Curtain
console.log("As long as it still posts on time.");