import { jsx as B } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { createContext as G } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
import { INITIAL_FILTERS as H } from "../constants.js";
import { TransactionsView as f } from "../types.js";
import { useState as v, useMemo as F, useCallback as _, useContext as D } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import j from "../hooks/useTransactionsList.js";
import E from "../hooks/useTransactionsTotals.js";
import q from "../hooks/useTransactionsViewSwitcher.js";
import M from "../../../../hooks/useAccountBalances.js";
import J from "../hooks/useCurrenciesLookup.js";
import { useFilterBarState as K } from "../../../internal/FilterBar/FilterBar.js";
const U = /* @__PURE__ */ new Set(["balanceAccount", "createdDate"]), W = (t) => t, X = ({ balanceAccountId: t, createdSince: r, createdUntil: o }) => ({
  balanceAccountId: t,
  createdSince: r,
  createdUntil: o
}), L = G(void 0), ct = () => {
  const t = D(L);
  if (t) return t;
  throw new Error("useTransactionsOverviewContext must be used within TransactionsOverviewProvider");
}, it = ({
  allowLimitSelection: t,
  balanceAccounts: r,
  children: o,
  dataCustomization: c,
  hideInsights: a,
  hideTitle: p,
  isLoadingBalanceAccount: S,
  mode: i = "overview",
  onContactSupport: C,
  onFiltersChanged: P,
  onRecordSelection: b,
  preferredLimit: R,
  showDetails: I
}) => {
  const [e, V] = v(H), [s, N] = v(() => Date.now()), [x, O] = v(), g = K(), d = F(() => {
    if (i === "insights") return f.INSIGHTS;
    if (a) return f.TRANSACTIONS;
  }, [a, i]), u = q({ view: d }), n = u.activeView !== f.INSIGHTS, l = !!e.balanceAccount?.id, A = _((k) => {
    N(Date.now()), V(k);
  }, []), m = M({ balanceAccount: e.balanceAccount }), T = E({
    fetchEnabled: !n && l,
    getQueryParams: X,
    applicableFilters: U,
    now: s,
    filters: e
  }), w = E({
    fetchEnabled: n && l,
    getQueryParams: W,
    now: s,
    filters: e
  }), h = j({
    fetchEnabled: i !== "insights" && l,
    now: s,
    allowLimitSelection: t,
    dataCustomization: c,
    onFiltersChanged: P,
    preferredLimit: R,
    filters: e
  }), y = J({
    defaultCurrency: e.balanceAccount?.defaultCurrencyCode,
    balances: m.balances,
    totals: (n ? w : T).totals
  }), Q = F(
    () => ({
      accountBalancesResult: m,
      balanceAccounts: r,
      currenciesLookupResult: y,
      dataCustomization: c,
      filterBarState: g,
      filters: e,
      hideInsights: a,
      hideTitle: p,
      insightsCurrency: x,
      insightsTotalsResult: T,
      isLoadingBalanceAccount: S,
      isTransactionsView: n,
      lastFiltersChangeTimestamp: s,
      onContactSupport: C,
      onFiltersChange: A,
      onRecordSelection: b,
      setInsightsCurrency: O,
      showDetails: I,
      transactionsListResult: h,
      transactionsTotalsResult: w,
      transactionsViewState: u
    }),
    [
      m,
      r,
      y,
      c,
      g,
      e,
      a,
      p,
      x,
      T,
      S,
      n,
      s,
      C,
      A,
      b,
      I,
      h,
      w,
      u
    ]
  );
  return /* @__PURE__ */ B(L.Provider, { value: Q, children: o });
};
export {
  it as TransactionsOverviewProvider,
  ct as useTransactionsOverviewContext
};
