"use client";
import { j as i } from "../../../node_modules/.pnpm/react@19.1.0/node_modules/react/jsx-runtime.mjs";
import { useState as I, useEffect as O } from "react";
import p from "../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.mjs";
import q from "../Button/index.mjs";
import D from "../Collapse/index.mjs";
import r from "./CollapseList.module.scss.mjs";
const F = {
  expandAll: "Expand All",
  collapseAll: "Collapse All"
}, Q = ({
  title: u,
  expandButton: _,
  classNames: o = {},
  isExpanded: f = !1,
  list: d = [],
  i18n: A = F
}) => {
  var L, v, B, C, T, y;
  const [h, g] = I(
    {}
  ), [x, j] = I(f);
  O(() => {
    g(
      d.reduce((t, n, l) => ({ ...t, [l]: f }), {})
    );
  }, [d]);
  const k = (t) => (n) => {
    g((e) => ({ ...e, [t]: n }));
    const l = Object.values({
      ...h,
      [t]: n
    }).every((e) => e);
    j(l);
  }, z = () => {
    j(!x), g(
      d.reduce((t, n, l) => ({ ...t, [l]: !x }), {})
    );
  };
  return /* @__PURE__ */ i.jsxs("div", { className: p(r.root, (L = o == null ? void 0 : o.collapseList) == null ? void 0 : L.root), children: [
    /* @__PURE__ */ i.jsxs(
      "div",
      {
        className: p(
          r.intro,
          u === void 0 ? r.noTitle : null,
          (v = o == null ? void 0 : o.collapseList) == null ? void 0 : v.intro,
          (B = o == null ? void 0 : o.collapseList) == null ? void 0 : B.noTitle
        ),
        children: [
          u ? /* @__PURE__ */ i.jsx("h2", { className: p("title", (C = o == null ? void 0 : o.collapseList) == null ? void 0 : C.title), children: u }) : null,
          d.length > 1 ? /* @__PURE__ */ i.jsx(
            q,
            {
              type: "tertiary",
              size: "small",
              className: p(
                r.expandAllButton,
                (T = o == null ? void 0 : o.collapseList) == null ? void 0 : T.expandButtonRoot
              ),
              onClick: z,
              ..._,
              children: x ? A.collapseAll : A.expandAll
            }
          ) : null
        ]
      }
    ),
    /* @__PURE__ */ i.jsx("div", { className: p(r.list, (y = o == null ? void 0 : o.collapseList) == null ? void 0 : y.list), children: d.map(({ content: t, ...n }, l) => {
      var e, E, S, R, b;
      return /* @__PURE__ */ i.jsx(
        D,
        {
          tabIndex: l,
          isOpen: h[l],
          onToggle: k(l),
          classNames: {
            root: p(r.collapseRoot, (e = o == null ? void 0 : o.collapse) == null ? void 0 : e.root),
            open: p(r.open, (E = o == null ? void 0 : o.collapse) == null ? void 0 : E.open),
            title: p(r.collapseTitle, (S = o == null ? void 0 : o.collapse) == null ? void 0 : S.title),
            content: p(
              r.collapseContent,
              (R = o == null ? void 0 : o.collapse) == null ? void 0 : R.content
            ),
            toggleButton: p(
              r.collapseToggleButton,
              (b = o == null ? void 0 : o.collapse) == null ? void 0 : b.toggleButton
            ),
            ...o.collapse || {}
          },
          ...n,
          children: typeof t == "string" ? t == null ? void 0 : t.trim() : t
        },
        l
      );
    }) })
  ] });
};
export {
  Q as default,
  F as defaultI81n
};
//# sourceMappingURL=index.mjs.map
