import { jsx as o, jsxs as l } from "react/jsx-runtime";
import { forwardRef as N, useState as b, useCallback as A } from "react";
import { cx as h } from "../../utils/classNames.js";
import { useArrowTheme as I } from "../../hooks/useArrowTheme.js";
import { Divider as w } from "../divider/Divider.js";
function y({
  item: e,
  isExpanded: r,
  onToggle: a,
  HeadingTag: s,
  hasDivider: i,
  isInverse: c,
  className: t
}) {
  return /* @__PURE__ */ l(
    "div",
    {
      className: h("tdds-accordion", t),
      "data-inverse": c ? "true" : void 0,
      children: [
        /* @__PURE__ */ o(s, { className: "tdds-accordion__heading", children: /* @__PURE__ */ l(
          "button",
          {
            type: "button",
            className: h("tdds-accordion__headline", {
              "force-focus": !!e.focused,
              "force-hover": !!e.hover
            }),
            "aria-expanded": !!r,
            "aria-controls": e.id,
            onClick: a,
            children: [
              e.icon ?? null,
              /* @__PURE__ */ o("span", { className: "tdds-accordion__headline--text", children: e.heading })
            ]
          }
        ) }),
        /* @__PURE__ */ o("div", { id: e.id, className: "tdds-accordion__body", children: e.content }),
        i && /* @__PURE__ */ o(w, { inverse: c })
      ]
    }
  );
}
const S = N(
  ({
    items: e,
    allowMultiple: r = !1,
    defaultExpandedIds: a = [],
    heading: s = "h2",
    hasDivider: i = !0,
    inverse: c,
    className: t
  }, f) => {
    const p = I(), u = c ?? p.inverse, [m, v] = b(
      () => new Set(a)
    ), x = A(
      (d) => {
        v((_) => {
          const n = new Set(_);
          return n.has(d) ? n.delete(d) : (r || n.clear(), n.add(d)), n;
        });
      },
      [r]
    ), g = s;
    return /* @__PURE__ */ o("div", { ref: f, children: e.map((d) => /* @__PURE__ */ o(
      y,
      {
        item: d,
        isExpanded: m.has(d.id),
        onToggle: () => x(d.id),
        HeadingTag: g,
        hasDivider: i,
        isInverse: u,
        className: t
      },
      d.id
    )) });
  }
);
S.displayName = "Accordion";
export {
  S as Accordion
};
//# sourceMappingURL=Accordion.js.map
