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