import { useCallback as m, useEffect as l, useMemo as y, useRef as p, useState as b, useLayoutEffect as v } from "react";
import { u as C } from "./router-context-CDZd-F2n.js";
import { o as E, p as S, A as _, a as P } from "./use-debounce-search-V04Zachp.js";
import { b as w, u as g, U as L, d as T } from "./use-local-storage-WAcc3MCo.js";
function A(e, n, t) {
  t = typeof t == "function" ? t : void 0;
  var r = t ? t(e, n) : void 0;
  return r === void 0 ? w(e, n, void 0, t) : !!r;
}
function V() {
  const { useSearchParams: e } = C(), [n, t] = e(), r = n.get("query"), i = m(
    (s) => {
      t((u) => {
        var o;
        const a = (o = s == null ? void 0 : s.target) == null ? void 0 : o.value;
        return E(a) ? u.delete("query") : u.set("query", a), u;
      });
    },
    [t]
  );
  return {
    query: r || void 0,
    handleSearch: i
  };
}
function q(e, n) {
  return A(e, n, (t, r) => {
    if (typeof t == "function" && typeof r == "function")
      return t.toString() === r.toString();
  });
}
function h(e) {
  const n = p();
  return q(e, n.current) || (n.current = e), n.current;
}
function D(e, n) {
  l(e, h(n));
}
function R(e, n) {
  return y(e, h(n));
}
const B = 1024 * 1024, M = () => {
  try {
    return !!(window.performance && window.performance.memory);
  } catch {
    return !1;
  }
}, H = () => {
  try {
    if (!M()) return null;
    const e = window.performance.memory;
    return e ? Math.round(e.usedJSHeapSize / B) : null;
  } catch {
    return null;
  }
}, N = (e, n = 1200, t = 3e4) => {
  l(() => {
    if (!M()) {
      console.debug("Memory API not available - memory cleanup disabled");
      return;
    }
    const i = setInterval(() => {
      const s = H();
      s !== null && s > n && (console.debug(`Memory usage (${s}MB) exceeded threshold (${n}MB). Running cleanup...`), e());
    }, t);
    return () => clearInterval(i);
  }, [e, n, t]);
};
function O({
  storageKey: e,
  columns: n,
  defaultVisibleColumns: t
}) {
  const r = y(
    () => t ?? n.map((o) => o.value),
    [t, n]
  ), [i, s] = g(e, r), u = m(
    (o, f) => {
      if (f) {
        const c = i.includes(o) ? i : [...i, o];
        s(c);
      } else {
        const c = i.filter((d) => d !== o);
        s(c);
      }
    },
    [i, s]
  ), a = m(() => {
    s(r);
  }, [s, r]);
  return {
    visibleColumns: i,
    toggleColumn: u,
    resetColumns: a
  };
}
function U() {
  let e, n;
  return typeof document.hidden < "u" ? (e = "hidden", n = "visibilitychange") : typeof document.msHidden < "u" ? (e = "msHidden", n = "msvisibilitychange") : typeof document.webkitHidden < "u" && (e = "webkitHidden", n = "webkitvisibilitychange"), { hidden: e, visibilityChange: n };
}
function I() {
  const [e, n] = b(!0);
  return l(() => {
    const { hidden: t, visibilityChange: r } = U();
    function i() {
      t && document[t] ? n(!1) : n(!0);
    }
    if (typeof document.addEventListener > "u" || typeof t > "u" || typeof r > "u")
      console.warn("The Page Visibility API is not supported");
    else
      return document.addEventListener(r, i, !1), () => {
        document.removeEventListener(r, i, !1);
      };
  }, []), e;
}
const k = 3e4, x = 6e4;
function j(e, {
  startPolling: n = !1,
  pollingInterval: t = k,
  inactiveTabPollingInterval: r = x,
  pollOnInactiveTab: i = !1
}) {
  const s = p(e), [u, a] = b(!1), o = I(), f = o ? t : r;
  return v(() => {
    s.current = e;
  }, [e]), l(() => {
    if (n && !(!o && !i) && !u) {
      const c = setTimeout(async () => {
        var d;
        a(!0);
        try {
          await ((d = s.current) == null ? void 0 : d.call(s));
        } finally {
          a(!1);
        }
      }, f);
      return () => clearTimeout(c);
    }
  }, [f, u, i, n, o]), u;
}
const J = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  UserPreference: L,
  useColumnFilter: O,
  useCommonFilter: V,
  useDebounceSearch: S,
  useDeepCompareEffect: D,
  useDeepCompareMemo: R,
  useDragAndDrop: _,
  useIsMounted: T,
  useLocalStorage: g,
  useMemoryCleanup: N,
  usePolling: j,
  useResizeObserver: P,
  useTabVisible: I
}, Symbol.toStringTag, { value: "Module" }));
export {
  D as a,
  R as b,
  N as c,
  O as d,
  j as e,
  I as f,
  J as i,
  V as u
};
//# sourceMappingURL=index-pxJIr-rq.js.map
