"use client";
import { useLayoutEffect as D, useEffect as w, useRef as o, useMemo as h, useCallback as i } from "react";
const L = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u";
function l(n) {
  const t = Object.prototype.toString.call(n);
  return t === "[object Window]" || // In Electron context the Window object serializes to [object global]
  t === "[object global]";
}
function b(n) {
  return "nodeType" in n;
}
function c(n) {
  var t, e;
  return n ? l(n) ? n : b(n) && (t = (e = n.ownerDocument) == null ? void 0 : e.defaultView) != null ? t : window : window;
}
function p(n) {
  const {
    Document: t
  } = c(n);
  return n instanceof t;
}
function S(n) {
  return l(n) ? !1 : n instanceof c(n).HTMLElement;
}
function V(n) {
  return n instanceof c(n).SVGElement;
}
function O(n) {
  return n ? l(n) ? n.document : b(n) ? p(n) ? n : S(n) || V(n) ? n.ownerDocument : document : document : document;
}
const E = L ? D : w;
function j(n) {
  const t = o(n);
  return E(() => {
    t.current = n;
  }), i(function() {
    for (var e = arguments.length, u = new Array(e), r = 0; r < e; r++)
      u[r] = arguments[r];
    return t.current == null ? void 0 : t.current(...u);
  }, []);
}
function A() {
  const n = o(null), t = i((u, r) => {
    n.current = setInterval(u, r);
  }, []), e = i(() => {
    n.current !== null && (clearInterval(n.current), n.current = null);
  }, []);
  return [t, e];
}
function N(n, t) {
  t === void 0 && (t = [n]);
  const e = o(n);
  return E(() => {
    e.current !== n && (e.current = n);
  }, t), e;
}
function X(n, t) {
  const e = o();
  return h(
    () => {
      const u = n(e.current);
      return e.current = u, u;
    },
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [...t]
  );
}
function Y(n) {
  const t = j(n), e = o(null), u = i(
    (r) => {
      r !== e.current && t?.(r, e.current), e.current = r;
    },
    //eslint-disable-next-line
    []
  );
  return [e, u];
}
function v(n) {
  const t = o();
  return w(() => {
    t.current = n;
  }, [n]), t.current;
}
let f = {};
function F(n, t) {
  return h(() => {
    if (t)
      return t;
    const e = f[n] == null ? 0 : f[n] + 1;
    return f[n] = e, n + "-" + e;
  }, [n, t]);
}
function y(n) {
  return function(t) {
    for (var e = arguments.length, u = new Array(e > 1 ? e - 1 : 0), r = 1; r < e; r++)
      u[r - 1] = arguments[r];
    return u.reduce((s, g) => {
      const R = Object.entries(g);
      for (const [d, T] of R) {
        const a = s[d];
        a != null && (s[d] = a + n * T);
      }
      return s;
    }, {
      ...t
    });
  };
}
const H = /* @__PURE__ */ y(1), W = /* @__PURE__ */ y(-1);
function C(n) {
  return "clientX" in n && "clientY" in n;
}
function q(n) {
  if (!n)
    return !1;
  const {
    KeyboardEvent: t
  } = c(n.target);
  return t && n instanceof t;
}
function I(n) {
  if (!n)
    return !1;
  const {
    TouchEvent: t
  } = c(n.target);
  return t && n instanceof t;
}
function x(n) {
  if (I(n)) {
    if (n.touches && n.touches.length) {
      const {
        clientX: t,
        clientY: e
      } = n.touches[0];
      return {
        x: t,
        y: e
      };
    } else if (n.changedTouches && n.changedTouches.length) {
      const {
        clientX: t,
        clientY: e
      } = n.changedTouches[0];
      return {
        x: t,
        y: e
      };
    }
  }
  return C(n) ? {
    x: n.clientX,
    y: n.clientY
  } : null;
}
const m = "a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";
function G(n) {
  return n.matches(m) ? n : n.querySelector(m);
}
export {
  H as add,
  L as canUseDOM,
  G as findFirstFocusableNode,
  x as getEventCoordinates,
  O as getOwnerDocument,
  c as getWindow,
  C as hasViewportRelativeCoordinates,
  p as isDocument,
  S as isHTMLElement,
  q as isKeyboardEvent,
  b as isNode,
  V as isSVGElement,
  I as isTouchEvent,
  l as isWindow,
  W as subtract,
  j as useEvent,
  A as useInterval,
  E as useIsomorphicLayoutEffect,
  N as useLatestValue,
  X as useLazyMemo,
  Y as useNodeRef,
  v as usePrevious,
  F as useUniqueId
};
