import { useState as y, useMemo as i, useRef as L, useCallback as p, useEffect as O } from "../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import _ from "./useAnalytics/useFilterAnalyticsEvent.js";
import h from "../core/Context/preact/useCoreContext.js";
import { capitalize as N } from "../utils/value/string.js";
import T from "../utils/random/uniqueId.js";
const B = T(), k = ({
  allowAllSelection: r = !1,
  balanceAccounts: c,
  eventCategory: I,
  eventSubCategory: C,
  eventLabel: v = "Balance account filter",
  onUpdateSelection: u
}) => {
  const { i18n: l } = h(), { logEvent: d } = _({ category: I, subCategory: C, label: v }), [f, m] = y(0), e = i(
    () => c && [
      ...c,
      ...r && c.length > 1 ? [
        {
          ...c[0] ?? {},
          id: B,
          description: void 0
        }
      ] : []
    ],
    [r, c]
  ), a = i(() => e?.[f], [e, f]), n = a?.id, A = L(), x = i(
    () => Object.freeze(
      e?.map(({ description: t, id: s }) => {
        const o = s === B ? l.get("common.filters.types.account.options.all") : N(t);
        return { id: s, name: o };
      }) ?? []
    ),
    [e, l]
  ), E = p(
    ({ target: t }) => {
      const s = t?.value, o = e?.findIndex(({ id: g }) => g === s);
      o !== void 0 && o >= 0 && m(o);
    },
    [e]
  ), S = p(() => m(0), []);
  return O(() => {
    const t = A.current;
    t !== n && (A.current = n, t && n && d?.("update", n), u?.(a));
  }, [a, n, d, u]), { activeBalanceAccount: a, balanceAccountSelectionOptions: x, onBalanceAccountSelection: E, resetBalanceAccountSelection: S };
};
export {
  B as ALL_BALANCE_ACCOUNTS_SELECTION_ID,
  k as default
};
