import { jsx as i, jsxs as g } from "react/jsx-runtime";
import { useState as h, useCallback as e } from "react";
import { A as j } from "./accordion-basic.js";
import { A as B } from "./accordion-body.js";
import { A as H } from "./accordion-header.js";
import { A as L } from "./accordion-item.js";
const N = function(f) {
  const {
    alwaysOpen: p,
    as: A = "div",
    collapsing: w,
    onChange: r,
    options: u,
    ...C
  } = f, k = (u ?? []).map((o, s) => ({
    ...o,
    collapsed: o.collapsed === void 0 ? !1 : o.collapsed,
    id: o.id ?? s,
    show: o.show === void 0 ? !0 : o.show
  })), [t, v] = h(k), [c, b] = h(
    t.find((o) => !o.collapsed && o.show)
  ), m = e((o) => {
    b(o);
  }, []), y = e(
    (o) => {
      v((s) => s.map((l, d) => {
        let n, a;
        return d === o ? (n = !l.collapsed, a = !l.show) : p ? (n = l.collapsed, a = l.show) : (n = d !== o, a = d === o), {
          ...l,
          collapsed: n,
          show: a
        };
      }));
    },
    [p]
  ), O = e(
    (o) => {
      const s = c == null ? void 0 : c.id;
      s !== void 0 && (r == null || r(s, o));
    },
    [c == null ? void 0 : c.id, r]
  );
  return /* @__PURE__ */ i(j, { as: A, ...C, children: t.map((o, s) => /* @__PURE__ */ g(L, { children: [
    /* @__PURE__ */ i(
      H,
      {
        buttonProps: {
          onClick: () => {
            m(o), y(s);
          }
        },
        collapsed: o.collapsed,
        children: o.header
      }
    ),
    /* @__PURE__ */ i(B, { collapsing: w, onChange: O, show: o.show, children: o.body })
  ] }, o.id)) });
};
N.displayName = "BRL.Accordion";
export {
  N as A
};
//# sourceMappingURL=accordion.js.map
