import { jsx as r } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { INITIAL_FILTERS as J, TRANSACTION_CATEGORIES as W, TRANSACTION_ANALYTICS_CATEGORY as X, TRANSACTION_ANALYTICS_SUBCATEGORY_LIST as $, TRANSACTION_ANALYTICS_SUBCATEGORY_INSIGHTS as ee } from "../../constants.js";
import { compareTransactionsFilters as D } from "../utils.js";
import { useRef as f, useState as s, useMemo as a, useCallback as te, useEffect as y } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useTransactionsOverviewContext as re } from "../../context/TransactionsOverviewContext.js";
import { useResponsiveContainer as ne, containerQueries as ce } from "../../../../../hooks/useResponsiveContainer.js";
import oe from "../../../../../hooks/useBalanceAccountSelection.js";
import U from "./TransactionMultiSelectionFilter.js";
import se from "./TransactionPspReferenceFilter.js";
import ae from "../../hooks/useCurrencySelection.js";
import ie from "./TransactionDateFilter.js";
import le from "../../../../../core/Context/preact/useCoreContext.js";
import { selectionOptionsFor as Y } from "../MultiSelectionFilter/useMultiSelectionFilter/utils.js";
import ue from "../../../../internal/FormFields/Select/BalanceAccountSelector/BalanceAccountSelector.js";
import { Fragment as x } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
import fe from "../../../../internal/FormFields/Select/Select.js";
import { FilterBar as pe } from "../../../../internal/FilterBar/FilterBar.js";
const i = X, me = /* @__PURE__ */ (() => {
  const p = /* @__PURE__ */ new Set(["balanceAccount"]);
  return () => {
    let l = {};
    return (m) => D(l, l = m, p);
  };
})(), _e = () => {
  const {
    filterBarState: p,
    isTransactionsView: l,
    balanceAccounts: m,
    currenciesLookupResult: G,
    insightsCurrency: k,
    onFiltersChange: g,
    setInsightsCurrency: C
  } = re(), { i18n: u } = le(), { setShowingFilters: Ce, ...M } = p, n = G.sortedCurrencies, c = l ? $ : ee, e = f({ ...J }), j = ne(ce.down.xs), [h, q] = s(() => e.current.statuses), [A, R] = s(() => e.current.categories), [S, d] = s(() => e.current.currencies), [F, v] = s(() => e.current.createdDate), [T, I] = s(() => e.current.paymentPspReference), [o, O] = s(() => e.current.balanceAccount), t = a(
    () => ({ balanceAccount: o, categories: A, createdDate: F, currencies: S, paymentPspReference: T, statuses: h }),
    [o, A, F, S, T, h]
  ), N = f(), L = f(), z = a(() => D(t, e.current), [t]), H = te(() => {
    q(e.current.statuses), R(e.current.categories), d(e.current.currencies), v(e.current.createdDate), I(e.current.paymentPspReference), O(e.current.balanceAccount);
  }, []), K = a(() => Y(W), []), Q = a(() => u.get("transactions.overview.filters.types.category.label"), [u]), V = a(() => Y(n ?? []), [n]), b = a(() => u.get("transactions.overview.filters.types.currency.label"), [u]), w = "Currency filter", B = f(me()).current, { resetBalanceAccountSelection: Ae, ...P } = oe({
    allowAllSelection: !1,
    onUpdateSelection: O,
    balanceAccounts: m,
    eventCategory: i,
    eventSubCategory: c
  }), { activeCurrency: _, currencySelectionOptions: E, onCurrencySelection: Z } = ae({
    eventLabel: w,
    onUpdateSelection: C,
    selectedCurrency: k ?? o?.defaultCurrencyCode,
    availableCurrencies: n,
    eventCategory: i,
    eventSubCategory: c
  });
  return y(() => {
    N.current !== n && (B(t) && (d(e.current.currencies), C?.(t.balanceAccount?.defaultCurrencyCode)), N.current = n);
  }, [n, t, B, C]), y(() => {
    L.current !== t && (L.current = t, g?.(t));
  }, [g, t]), y(() => {
    !e.current.balanceAccount && o && (e.current.balanceAccount = o);
  }, [o]), /* @__PURE__ */ r(
    pe,
    {
      ...M,
      ariaLabelKey: "transactions.overview.filters.label",
      canResetFilters: z && !1,
      resetFilters: H,
      children: [
        /* @__PURE__ */ r(ue, { ...P }),
        /* @__PURE__ */ r(
          ie,
          {
            createdDate: F,
            eventCategory: i,
            eventSubCategory: c,
            setCreatedDate: v,
            timezone: P.activeBalanceAccount?.timeZone
          }
        ),
        l ? /* @__PURE__ */ r(x, { children: [
          /* @__PURE__ */ r(
            U,
            {
              eventLabel: "Category filter",
              eventCategory: i,
              eventSubCategory: c,
              placeholder: Q,
              selectionOptions: K,
              selection: A,
              onUpdateFilter: R
            }
          ),
          /* @__PURE__ */ r(
            U,
            {
              eventCategory: i,
              eventSubCategory: c,
              eventLabel: w,
              placeholder: b,
              selectionOptions: V,
              selection: S,
              onUpdateFilter: d
            }
          ),
          /* @__PURE__ */ r(
            se,
            {
              eventCategory: i,
              eventSubCategory: c,
              onChange: I,
              value: T
            }
          )
        ] }) : /* @__PURE__ */ r(x, { children: E.length > 1 ? /* @__PURE__ */ r(
          fe,
          {
            filterable: !1,
            multiSelect: !1,
            items: E,
            onChange: Z,
            selected: _,
            "aria-label": b,
            placeholder: _ || b,
            showOverlay: j,
            withoutCollapseIndicator: !0
          }
        ) : null })
      ]
    }
  );
};
export {
  _e as default
};
