// Exercise 3: detect hydration-mismatch-prone code
//
// Given snippets of Client Component render bodies (as strings, for
// static analysis practice — no real JSX execution needed), implement
// isHydrationSafe(code), which returns false if the code reads
// `Date.now()`, `Math.random()`, or `window` DIRECTLY in a way that
// would differ between server render and client render (i.e. NOT
// inside a useEffect callback), and true otherwise.
//
// Simplification for this exercise: treat any occurrence of
// "useEffect(" in the snippet as making the WHOLE snippet safe (real
// analysis would need to check the effect only reads it inside its own
// callback — out of scope here).

function isHydrationSafe(code: string): boolean {
  // TODO: implement per the rules above.
  // Hint: if code.includes("useEffect(") return true immediately.
  // Otherwise return false if it mentions "Date.now()", "Math.random()",
  // or "window" — true if it mentions none of them.
  return true;
}

// --- self-check: do not modify below this line ---
const cases: [string, boolean][] = [
  ['return <div>{Date.now()}</div>;', false],
  ['return <div>{Math.random()}</div>;', false],
  ['return <div>{window.innerWidth}</div>;', false],
  ['return <div>Static content</div>;', true],
  ['useEffect(() => { console.log(window.innerWidth); }, []); return <div />;', true],
];

let allPass = true;
for (const [code, expected] of cases) {
  const result = isHydrationSafe(code);
  const pass = result === expected;
  if (!pass) allPass = false;
  console.log(`isHydrationSafe(...) -> ${result} (expected ${expected}): ${pass ? "PASS" : "FAIL"}`);
}
console.log(allPass ? "ALL PASS" : "SOME FAILED");
