"use client";

import { useEffect } from "react";

// iOS Safari bug: with viewportFit=cover + maximumScale=1, restoring from
// bfcache after lock/unlock can leave the visual viewport in a stale
// "zoomed" state. Nudging scroll + forcing a reflow on pageshow
// (persisted) realigns it without changing the zoom level.
export function ViewportRedrawOnResume() {
  useEffect(() => {
    const onShow = (e: PageTransitionEvent) => {
      if (!e.persisted) return;
      window.scrollTo(window.scrollX, window.scrollY);
      void document.body.offsetHeight;
    };
    window.addEventListener("pageshow", onShow);
    return () => window.removeEventListener("pageshow", onShow);
  }, []);
  return null;
}
