import { B as A, F as E, I as M, a as _, c as D, u as w, b as F, d as G, e as S } from "./Items-DQba1BFQ.js";
import { useCallback as u, useMemo as b } from "react";
import { array as h } from "@synnaxlabs/x";
import { c as d } from "./Editable-C17ILP50.js";
import "./Text-2MISZsc5.js";
import "./jsx-runtime-tc70JA_2.js";
import "./types-CGRCBVD4.js";
import "./css-D90kZTM8.js";
import "./Box-Bi280MYh.js";
import "./Provider-jFWpR0CX.js";
import { u as U } from "./useStaticData-p8sk2VCJ.js";
const I = 10, y = ({ offset: t, searchTerm: e = "", ...s }, a = I) => ({
  ...s,
  offset: (t ?? -a) + a,
  limit: a,
  searchTerm: e
}), g = (t, e, s = I) => ({
  ...t,
  searchTerm: e,
  offset: 0,
  limit: s
}), x = ({
  retrieve: t,
  pageSize: e = I
}) => {
  const s = u(() => {
    t((c) => y(c, e), { mode: "append" });
  }, [t, e]), a = u(
    (c) => t((n) => g(n, c, e)),
    [t, e]
  );
  return b(
    () => ({ fetchMore: s, search: a }),
    [s, a]
  );
}, C = ({
  first: t,
  second: e
}) => {
  const s = b(
    () => [...t.data, ...e.data],
    [t.data, e.data]
  ), a = u(
    (n) => {
      if (Array.isArray(n)) {
        const m = t.getItem?.(n) ?? [], i = e.getItem?.(n) ?? [];
        return [...m, ...i];
      }
      return t.getItem?.(n) ?? e.getItem?.(n);
    },
    [t.getItem, e.getItem]
  ), c = u(
    (n, m) => {
      const i = t.subscribe?.(n, m), p = e.subscribe?.(n, m);
      return () => {
        i?.(), p?.();
      };
    },
    [t.subscribe, e.subscribe]
  );
  return b(() => ({ data: s, getItem: a, subscribe: c }), [s, a, c]);
}, P = (t) => {
  const e = u(
    ((s) => {
      if (Array.isArray(s)) {
        const c = new Set(s);
        return t.filter((n) => c.has(n)).map((n) => ({ key: n }));
      }
      const a = t.find((c) => c === s);
      return a ? { key: a } : void 0;
    }),
    [t]
  );
  return b(() => ({ data: t, getItem: e }), [t, e]);
}, R = ({ initialData: t } = {}) => {
  const e = d(() => {
    const r = /* @__PURE__ */ new Map();
    return t == null || t.forEach((o) => r.set(o.key, o)), r;
  }), s = d(() => /* @__PURE__ */ new Map()), a = u((r) => {
    const o = new Set(r);
    s.current.forEach((l, f) => {
      o.has(l) && f();
    });
  }, []), c = u((r) => {
    const o = h.toArray(r), l = o.map((f) => f.key);
    o.forEach((f) => e.current.set(f.key, f)), a(l);
  }, []), n = u((r) => {
    const o = h.toArray(r);
    o.forEach((l) => e.current.delete(l)), a(o);
  }, []), m = u(
    (r, o) => o == null ? () => {
    } : (s.current.set(r, o), () => {
      s.current.delete(r);
    }),
    [s]
  ), i = u(
    ((r) => {
      if (r != null)
        return Array.isArray(r) ? r.map((o) => e.current.get(o)).filter((o) => o != null) : e.current.get(r);
    }),
    []
  ), p = u((r) => e.current.has(r), []);
  return b(
    () => ({ setItem: c, deleteItem: n, subscribe: m, getItem: i, hasItem: p }),
    [c, n, m, i, p]
  );
}, Q = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  BaseFrame: A,
  Frame: E,
  Item: M,
  Items: _,
  createGetItem: D,
  page: y,
  search: g,
  useCombinedData: C,
  useData: w,
  useItem: F,
  useKeysData: P,
  useMapData: R,
  usePager: x,
  useScroller: G,
  useStaticData: U,
  useUtilContext: S
}, Symbol.toStringTag, { value: "Module" }));
export {
  x as a,
  Q as e,
  P as u
};
