// Exercise 1: the updater-function form vs the direct-value form
//
// simulateClicks(times) must return what `count` would end up as if a
// button calling setCount(count + 1) were clicked `times` times SYNCHRONOUSLY
// within a single handler invocation (i.e. all `times` calls read the SAME
// stale `count` from one render, exactly like calling setCount(count + 1)
// `times` times in a row inside one function body).
//
// simulateClicksFixed(times) must return what count would end up as if the
// FIXED version (setCount(prev => prev + 1)) were called `times` times in
// a row within one handler invocation.
//
// This is a pure-logic exercise — no React needed, just modeling the two
// behaviors described in the theory file.

function simulateClicks(startCount: number, times: number): number {
  // TODO: model calling setCount(count + 1) `times` times where `count` is
  // frozen at startCount for all `times` calls (closure captures one value).
  // Net effect: the LAST call wins, all of them compute the same result.
  return startCount;
}

function simulateClicksFixed(startCount: number, times: number): number {
  // TODO: model calling setCount(prev => prev + 1) `times` times, where each
  // call actually sees the result of the previous one (true increment).
  return startCount;
}

// --- self-check: do not modify below this line ---
const buggyResult = simulateClicks(0, 3);
console.log("buggy (direct value) result:", buggyResult, "expected 1");
console.log(buggyResult === 1 ? "PASS" : "FAIL");

const fixedResult = simulateClicksFixed(0, 3);
console.log("fixed (updater fn) result:", fixedResult, "expected 3");
console.log(fixedResult === 3 ? "PASS" : "FAIL");
