import { jsx as r } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { memo as h } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/compat/dist/compat.module.js";
import { useState as w, useMemo as i } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import y from "../../../../internal/ExpandableCard/ExpandableCard.js";
import { TransactionTotalItem as f } from "../TransactionTotalItem/TransactionTotalItem.js";
import { useMaxWidthsState as T } from "../../hooks/useMaxWidths.js";
import $ from "../../../../../core/Context/preact/useCoreContext.js";
import { Fragment as C } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
import v from "../../../../../utils/random/uniqueId.js";
const z = h(({ totals: p, isLoading: o, hiddenField: t, fullWidth: I, ...x }) => {
  const { i18n: n } = $(), [a, l] = T(), [m, c] = w(!1), d = i(() => n.get("transactions.overview.totals.currency.label"), [n]), [s, ...u] = i(() => p.map((e) => ({
    ...e,
    key: e.currency,
    expensesElemId: v("elem"),
    incomingsElemId: v("elem")
  })), [p]), E = i(() => {
    switch (t) {
      case "expenses":
        return n.get("transactions.overview.totals.lists.incoming");
      case "incomings":
        return n.get("transactions.overview.totals.lists.outgoing");
      default:
        return n.get("transactions.overview.totals.lists.default");
    }
  }, [n, t]), g = i(
    () => /* @__PURE__ */ r(
      "div",
      {
        role: "listitem",
        "aria-label": s ? `${d}: ${s.currency}` : void 0,
        "aria-describedby": s ? `${s.incomingsElemId} ${s.expensesElemId}` : void 0,
        children: /* @__PURE__ */ r(
          f,
          {
            showLabelUnderline: m,
            total: s,
            hiddenField: t,
            widths: a,
            isHeader: !0,
            isSkeleton: o,
            isLoading: o,
            onWidthsSet: l,
            expensesElemId: s?.expensesElemId,
            incomingsElemId: s?.incomingsElemId
          }
        )
      }
    ),
    [m, s, t, a, o, l, d]
  ), b = i(() => !o && u.length ? /* @__PURE__ */ r(C, { children: u.map((e) => /* @__PURE__ */ r(
    "div",
    {
      role: "listitem",
      "aria-label": `${d}: ${e.currency}`,
      "aria-describedby": `${e.incomingsElemId} ${e.expensesElemId}`,
      children: /* @__PURE__ */ r(
        f,
        {
          showLabelUnderline: m,
          total: e,
          hiddenField: t,
          widths: a,
          onWidthsSet: l,
          expensesElemId: e.expensesElemId,
          incomingsElemId: e.incomingsElemId
        }
      )
    },
    e.key
  )) }) : void 0, [o, u, m, t, a, l, d]);
  return /* @__PURE__ */ r(
    y,
    {
      renderContent: ({ collapsibleContent: e }) => /* @__PURE__ */ r("div", { role: "list", "aria-label": E, children: [
        g,
        e
      ] }),
      fullWidth: I,
      onMouseEnter: () => c(!0),
      onFocus: () => c(!0),
      onMouseLeave: () => c(!1),
      onBlur: () => c(!1),
      ...x,
      children: b
    }
  );
});
export {
  z as TotalsCard
};
