import { jsx as i, jsxs as v } from "react/jsx-runtime";
import { useSlotRecipe as _ } from "@chakra-ui/react/styled-system";
import { e as p } from "./extract-style-props-BdibuNZ7.es.js";
import c, { useMemo as m, useEffect as j, forwardRef as P, createContext as $, useContext as D } from "react";
import { KeyboardArrowRight as T } from "@commercetools/nimbus-icons";
import { $ as w, a as G } from "./Button-BjcDZ5eb.es.js";
import { Flex as z } from "@chakra-ui/react/flex";
import { createSlotRecipeContext as B } from "@chakra-ui/react";
import { a as g, $ as O, e as A, g as q, d as J } from "./utils-B6pV5ewr.es.js";
import { a as L, $ as R } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as C } from "./filterDOMProps-BSVCO5jK.es.js";
import { $ as Q } from "./useControlledState-u436Wbp1.es.js";
import { $ as U, a as X } from "./useDisclosureState-CWZTR2xM.es.js";
import { $ as S } from "./useFocusRing-FPt2Rwil.es.js";
function Y(o) {
  let { allowsMultipleExpanded: e = !1, isDisabled: s = !1 } = o, [t, a] = Q(m(() => o.expandedKeys ? new Set(o.expandedKeys) : void 0, [
    o.expandedKeys
  ]), m(() => o.defaultExpandedKeys ? new Set(o.defaultExpandedKeys) : /* @__PURE__ */ new Set(), [
    o.defaultExpandedKeys
  ]), o.onExpandedChange);
  return j(() => {
    if (!e && t.size > 1) {
      let d = t.values().next().value;
      d != null && a(/* @__PURE__ */ new Set([
        d
      ]));
    }
  }), {
    allowsMultipleExpanded: e,
    isDisabled: s,
    expandedKeys: t,
    setExpandedKeys: a,
    toggleKey(d) {
      let n;
      e ? (n = new Set(t), n.has(d) ? n.delete(d) : n.add(d)) : n = new Set(t.has(d) ? [] : [
        d
      ]), a(n);
    }
  };
}
const K = /* @__PURE__ */ $(null), Z = /* @__PURE__ */ P(function(e, s) {
  let t = Y(e), a = g({
    ...e,
    defaultClassName: "react-aria-DisclosureGroup",
    values: {
      isDisabled: t.isDisabled,
      state: t
    }
  }), d = C(e, {
    global: !0
  });
  return /* @__PURE__ */ c.createElement("div", {
    ...d,
    ...a,
    ref: s,
    "data-disabled": e.isDisabled || void 0
  }, /* @__PURE__ */ c.createElement(K.Provider, {
    value: t
  }, a.children));
}), k = /* @__PURE__ */ $(null), ee = /* @__PURE__ */ $(null), N = /* @__PURE__ */ $(null), te = /* @__PURE__ */ P(function(e, s) {
  [e, s] = O(e, s, k);
  let t = D(K), { id: a, ...d } = e, n = L();
  a || (a = n);
  let l = t ? t.expandedKeys.has(a) : e.isExpanded, r = U({
    ...e,
    isExpanded: l,
    onExpandedChange(M) {
      var x;
      t && t.toggleKey(a), (x = e.onExpandedChange) === null || x === void 0 || x.call(e, M);
    }
  }), u = c.useRef(null), b = e.isDisabled || t?.isDisabled || !1, { buttonProps: F, panelProps: W } = X({
    ...e,
    isExpanded: l,
    isDisabled: b
  }, r, u), { isFocusVisible: E, focusProps: H } = S({
    within: !0
  }), y = g({
    ...e,
    id: void 0,
    defaultClassName: "react-aria-Disclosure",
    values: {
      isExpanded: r.isExpanded,
      isDisabled: b,
      isFocusVisibleWithin: E,
      state: r
    }
  }), I = C(d, {
    global: !0
  });
  return /* @__PURE__ */ c.createElement(A, {
    values: [
      [
        w,
        {
          slots: {
            [q]: {},
            trigger: F
          }
        }
      ],
      [
        N,
        {
          panelProps: W,
          panelRef: u
        }
      ],
      [
        ee,
        r
      ]
    ]
  }, /* @__PURE__ */ c.createElement("div", {
    ...R(I, y, H),
    ref: s,
    "data-expanded": r.isExpanded || void 0,
    "data-disabled": b || void 0,
    "data-focus-visible-within": E || void 0
  }, y.children));
}), oe = /* @__PURE__ */ P(function(e, s) {
  let { role: t = "group" } = e, { panelProps: a, panelRef: d } = D(N), { isFocusVisible: n, focusProps: l } = S({
    within: !0
  }), r = g({
    ...e,
    defaultClassName: "react-aria-DisclosurePanel",
    values: {
      isFocusVisibleWithin: n
    }
  }), u = C(e, {
    global: !0
  });
  return /* @__PURE__ */ c.createElement("div", {
    ...R(u, r, a, l),
    ref: J(s, d),
    role: t,
    "data-focus-visible-within": n || void 0
  }, /* @__PURE__ */ c.createElement(A, {
    values: [
      [
        w,
        null
      ]
    ]
  }, e.children));
}), { withProvider: de, withContext: f } = /* @__PURE__ */ B({
  key: "accordion"
}), ae = /* @__PURE__ */ de("div", "root"), se = /* @__PURE__ */ f("div", "disclosure"), ne = /* @__PURE__ */ f("button", "trigger"), re = /* @__PURE__ */ f("div", "panel"), ie = /* @__PURE__ */ f("div", "accordionTitle"), h = /* @__PURE__ */ f("div", "headerContentRight"), le = (o) => {
  const { ref: e, ...s } = o, t = _({ key: "accordion" }), [a, d] = t.splitVariantProps(s), [n, l] = p(d);
  return /* @__PURE__ */ i(ae, { ref: e, ...a, ...n, asChild: !0, children: /* @__PURE__ */ i(Z, { ...l }) });
};
le.displayName = "Accordion.Root";
const ce = ({
  children: o,
  value: e,
  ref: s,
  ...t
}) => {
  const [a, d] = p(t), n = {
    ...d,
    id: e
    // React Aria uses id for the key
  };
  return /* @__PURE__ */ i(
    se,
    {
      "data-value": e,
      ref: s,
      ...a,
      asChild: !0,
      children: /* @__PURE__ */ i(te, { ...n, children: o })
    }
  );
};
ce.displayName = "Accordion.Item";
const V = ({
  children: o,
  ref: e,
  ...s
}) => /* @__PURE__ */ i(h, { ref: e, ...s, children: o });
V.displayName = "Accordion.HeaderRightContent";
const fe = ({
  children: o,
  ref: e,
  ...s
}) => {
  const [t, a] = p(s), d = m(() => {
    const n = [], l = [];
    return c.Children.forEach(o, (r) => {
      c.isValidElement(r) && (r.type === V || r.type === h) ? l.push(r) : n.push(r);
    }), { main: n, rightContent: l };
  }, [o]);
  return /* @__PURE__ */ v(
    z,
    {
      justifyContent: "space-between",
      alignItems: "center",
      borderBottom: "solid-25",
      borderColor: "neutral.4",
      ...t,
      children: [
        /* @__PURE__ */ i(ne, { ref: e, slot: "trigger", asChild: !0, children: /* @__PURE__ */ v(G, { ...a, children: [
          /* @__PURE__ */ i(T, {}),
          /* @__PURE__ */ i(ie, { children: d.main })
        ] }) }),
        d.rightContent.length > 0 && /* @__PURE__ */ i(h, { children: d.rightContent })
      ]
    }
  );
};
fe.displayName = "Accordion.Header";
const ue = ({
  children: o,
  ref: e,
  ...s
}) => {
  const [t, a] = p(s);
  return /* @__PURE__ */ i(re, { ref: e, ...t, asChild: !0, children: /* @__PURE__ */ i(oe, { ...a, children: o }) });
};
ue.displayName = "Accordion.Content";
export {
  le as A,
  ce as a,
  fe as b,
  ue as c,
  V as d
};
//# sourceMappingURL=accordion.content-GGayEeqD.es.js.map
