import { useState as B, useMemo as r, useCallback as g, useEffect as F } from "../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useFetch as d } from "./useFetch.js";
import { useConfigContext as C } from "../core/ConfigContext/preact/context.js";
import { isFunction as A } from "../utils/value/is.js";
import { EMPTY_OBJECT as k } from "../utils/value/constants.js";
const i = /* @__PURE__ */ new WeakMap(), x = (e, u) => {
  const { getBalanceAccounts: t } = C().endpoints, [n, f] = B(() => t && i.get(t)), l = r(
    () => !n && A(t) && u !== !1,
    [n, u, t]
  ), { data: c, isFetching: m, error: h } = d({
    queryFn: g(async () => t?.(k), [t]),
    fetchOptions: { enabled: l, keepPrevData: !0 }
  }), s = n ?? c?.data, o = r(
    () => s?.filter((a) => !e || e === a.id),
    [s, e]
  ), p = r(
    () => !!e && !!s?.length && o?.length === 0,
    [s, e, o]
  );
  return F(() => {
    if (c?.data && t) {
      const a = c.data;
      i.set(t, a), f(a);
    }
  }, [c, t]), { balanceAccounts: o, isBalanceAccountIdWrong: p, isFetching: m, error: h };
};
export {
  x as default
};
