import { getCurrentWindow } from "@tauri-apps/api/window";
import { useEffect, useState } from "react";

/**
 * True while the macOS *window* is fullscreen (the green button), as distinct
 * from the video being fullscreen. In that state the traffic lights are gone,
 * so the title-bar strip the app paints is pure dead space and must collapse.
 */
export function useWindowFullscreen(): boolean {
  const [full, setFull] = useState(false);

  useEffect(() => {
    const win = getCurrentWindow();
    let unlisten: (() => void) | undefined;
    const check = () => {
      win.isFullscreen().then(setFull).catch(() => {});
    };
    check();
    win.onResized(check).then((u) => (unlisten = u));
    return () => unlisten?.();
  }, []);

  return full;
}
