import { useState as h, useCallback as m } from "react";
import { noop as F } from "es-toolkit/compat";
import t from "./useEvent.js";
const z = {
  requestFullscreen: F,
  exitFullscreen: F,
  toggleFullscreen: F,
  isFullscreen: !1,
  isEnabled: !1
}, v = [
  "requestFullscreen",
  "webkitRequestFullscreen",
  "webkitRequestFullScreen",
  "mozRequestFullScreen"
], R = ["exitFullscreen", "webkitExitFullscreen", "webkitCancelFullScreen", "mozCancelFullScreen"], B = [
  "fullscreenElement",
  "webkitFullscreenElement",
  "webkitCurrentFullScreenElement",
  "mozFullScreenElement"
], H = [
  "fullscreenElement",
  "webkitFullscreenEnabled",
  "webkitCurrentFullScreenElement",
  "mozFullScreenEnabled"
], u = (n, l) => n.find((o) => o in l), I = (n = document) => u(v, n), L = () => u(R, document), k = () => {
  const n = u(B, document);
  return n ? document[n] : null;
}, M = () => u(H, document), A = (n = {}) => {
  if (typeof window > "u")
    return console.warn("useFullscreen: window is undefined."), z;
  const { element: l, onChange: o, onError: S, requestFullscreenOptions: N = {} } = n, p = !l || !(l instanceof HTMLElement) ? document.querySelector("html") : l, f = k(), [x, d] = h(!!f), [c, E] = h(f), w = m(async (e) => {
    const s = e instanceof HTMLElement;
    try {
      const r = e && s ? e : p, q = I(r);
      if (q)
        return await r[q](N);
      throw new Error("Request function not found");
    } catch (r) {
      console.log(r);
    }
  }, []), b = m(async () => {
    try {
      const e = L();
      if (c && e)
        return await document[e]();
    } catch (e) {
      console.warn(e);
    }
  }, [c]), C = m(
    (e) => {
      c ? b() : w(e);
    },
    [c]
  ), i = () => {
    const e = k(), s = !!e;
    s ? (d(!0), E(e)) : (d(!1), E(null)), o?.call(document, event || new Event("default"), s);
  }, a = () => (e) => S?.call(document, e);
  t("fullscreenchange", i), t("webkitfullscreenchange", i), t("mozfullscreenchange", i), t("fullscreenerror", a), t("webkitfullscreenerror", a), t("mozfullscreenerror", a);
  const g = M(), y = g ? !!document[g] : !1;
  return {
    requestFullscreen: w,
    exitFullscreen: b,
    toggleFullscreen: C,
    isFullscreen: x,
    isEnabled: y
  };
};
export {
  A as default
};
//# sourceMappingURL=useFullscreen.js.map
