import { jsx as o, jsxs as h } from "react/jsx-runtime";
import { useState as m } from "react";
import { isEqual as y } from "es-toolkit/predicate";
import d from "../../utils/classNames.js";
import f from "../collapse/Collapse.js";
import { hasBorderClass as I, hasRoundedClass as v } from "../../utils/hasUtilityClass.js";
const L = () => (Math.random() + 1).toString(36).toUpperCase().substring(2), u = (r) => r.map((s) => (s.id || (s.id = L()), s)), q = (r) => {
  const { items: s = [], unmountOnExit: n = !0, rounded: l = !0, bordered: N = !0, className: p = "" } = r, [c, i] = m(u(s)), [b, x] = m(s);
  y(b, s) || (i(u(s)), x(s));
  const C = (e) => {
    if (!e.body)
      return;
    const t = [...c].map((a) => (a.id === e.id && (a.onOpen && !a.open && a.onOpen(), a.onClose && a.open && a.onClose(), a.open = !a.open), a));
    i(t);
  }, g = d(
    "expander-list list-group",
    l && !v(p) && "rounded",
    N && !I(p) && "border",
    p
  );
  return /* @__PURE__ */ o("ul", { className: g, children: c.map((e) => {
    const t = e.open, a = d(
      "list-group-item",
      e.className && e.className,
      e.body ? "expandable" : "",
      t && "open"
    );
    return /* @__PURE__ */ h("li", { className: a, children: [
      /* @__PURE__ */ o(E, { item: e, onToggle: C }),
      e.body && /* @__PURE__ */ o(f, { open: t, unmountOnExit: n, children: /* @__PURE__ */ o("div", { className: "expander-list-body-wrapper", children: /* @__PURE__ */ o(O, { className: e.bodyClassName, children: e.body }) }) })
    ] }, e.id);
  }) });
}, E = ({ item: r, onToggle: s }) => {
  const n = d("expander-list-header", r.headerClassName), l = d("expander-icon", "rioglyph", "rioglyph-chevron-down");
  return /* @__PURE__ */ h(
    "div",
    {
      className: n,
      onClick: () => s(r),
      "aria-label": "expander item header",
      ...r.trackingAttributes,
      children: [
        /* @__PURE__ */ o("span", { className: "expander-list-header-content", children: r.header }),
        r.body && /* @__PURE__ */ o("span", { className: l })
      ]
    }
  );
}, O = ({ className: r, children: s }) => {
  const n = d("expander-list-body", r);
  return /* @__PURE__ */ o("div", { className: n, "aria-label": "expander item body", children: s });
};
export {
  q as default
};
//# sourceMappingURL=ExpanderList.js.map
