// Exercise 1: implement shallowEqual, the comparator behind React.memo
// (theory 1, Section 6)
//
// STEP 1: implement shallowEqual(objA, objB) matching React's default memo
//         comparator EXACTLY: Object.is on the objects themselves first,
//         then same key COUNT, then Object.is on every value pairwise.
// STEP 2: implement shouldSkipRender(prevProps, nextProps) which just calls
//         shallowEqual — this is conceptually what memo calls internally
//         to decide whether to bail out.

function shallowEqual(objA: Record<string, unknown>, objB: Record<string, unknown>): boolean {
  // TODO: if Object.is(objA, objB) -> true (same reference, trivially equal)
  // TODO: compare Object.keys(objA).length to Object.keys(objB).length -> if different, false
  // TODO: for every key in objA, Object.is(objA[key], objB[key]) must hold -> else false
  // TODO: otherwise true
  return false; // placeholder
}

function shouldSkipRender(
  prevProps: Record<string, unknown>,
  nextProps: Record<string, unknown>,
): boolean {
  // TODO: return shallowEqual(prevProps, nextProps)
  return false; // placeholder
}

export { shallowEqual, shouldSkipRender };

// --- self-check: do not modify below this line ---
console.log(shallowEqual({ a: 1 }, { a: 1 }) ? "PASS (equal primitive values)" : "FAIL (equal primitive values)");
console.log(shallowEqual({ a: 1 }, { a: 2 }) ? "FAIL (different values detected as equal)" : "PASS (different values detected)");

const sameRef = { x: 1 };
console.log(shallowEqual(sameRef, sameRef) ? "PASS (identical reference short-circuits true)" : "FAIL (identical reference short-circuits true)");

console.log(
  shallowEqual({ a: 1, b: 2 }, { a: 1 }) ? "FAIL (different key count detected as equal)" : "PASS (different key count detected)",
);

const nestedA = { user: { name: "Ana" } };
const nestedB = { user: { name: "Ana" } }; // different object, same shape — NOT shallow-equal
console.log(
  shallowEqual(nestedA, nestedB) ? "FAIL (nested objects are only shallow — should be false here)" : "PASS (shallow only — nested object identity differs)",
);

const stableNested = nestedA.user;
console.log(
  shallowEqual({ user: stableNested }, { user: stableNested })
    ? "PASS (same nested reference passes shallow check)"
    : "FAIL (same nested reference passes shallow check)",
);

console.log(
  shouldSkipRender({ label: "x" }, { label: "x" }) ? "PASS (shouldSkipRender delegates to shallowEqual)" : "FAIL (shouldSkipRender delegates to shallowEqual)",
);

// Verify visually: wrap a component in memo(Component, shouldSkipRender) if
// your setup allows a custom comparator, or just trust the assertions above —
// they exercise the exact comparison React's default memo runs internally.
