import { useMemo as p } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
const b = (e, t) => {
  let o = t?.get(e);
  return o === void 0 && (o = {
    balances: { currency: e, reservedValue: 0, value: 0 },
    totals: {
      currency: e,
      expenses: 0,
      incomings: 0,
      total: 0,
      breakdown: {
        expenses: [],
        incomings: []
      }
    }
  }, t?.set(e, o)), o;
}, f = ({ defaultCurrency: e, balances: t, totals: o }) => {
  const c = p(() => {
    const r = new Map(
      e ? [[e, b(e)]] : []
    );
    for (const s of t) {
      const n = b(s.currency, r);
      n.balances = s;
    }
    for (const s of o) {
      const n = b(s.currency, r);
      n.totals = s;
    }
    const a = [...r.entries()].sort(
      ([s], [n]) => s.localeCompare(n)
    );
    return Object.freeze(Object.fromEntries(a));
  }, [e, t, o]), i = p(() => Object.freeze(Object.keys(c)), [c]), k = p(
    () => Object.freeze(
      [...i].sort((r, a) => {
        if (e) {
          if (r === e) return -1;
          if (a === e) return 1;
        }
        return 0;
      })
    ),
    [i, e]
  );
  return p(
    () => ({ currenciesDictionary: c, defaultCurrency: e, defaultCurrencySortedCurrencies: k, sortedCurrencies: i }),
    [c, e, k, i]
  );
};
export {
  f as default
};
