import s from "react";
import { createContextScope as Q } from "../../../../../@radix-ui_react-context@1.1.2_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-context/dist/index.js";
import { createCollection as W } from "../../../../../@radix-ui_react-collection@1.1.7_@types_react-dom@19.1.6_@types_react@19.1.6__@types_re_773c2f41d00caf3f92b3d7605949da61/node_modules/@radix-ui/react-collection/dist/index.js";
import { useComposedRefs as X } from "../../../../../@radix-ui_react-compose-refs@1.1.2_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { composeEventHandlers as Z } from "../../../../../@radix-ui_primitive@1.1.2/node_modules/@radix-ui/primitive/dist/index.js";
import { useControllableState as O } from "../../../../../@radix-ui_react-use-controllable-state@1.2.2_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
import { Primitive as T } from "../../../../../@radix-ui_react-primitive@2.1.3_@types_react-dom@19.1.6_@types_react@19.1.6__@types_rea_ec571b14c8dc7e1c1fa1383d9a1e10bd/node_modules/@radix-ui/react-primitive/dist/index.js";
import { createCollapsibleScope as M, Root as $, Trigger as ee, Content as oe } from "../../../../../@radix-ui_react-collapsible@1.1.11_@types_react-dom@19.1.6_@types_react@19.1.6__@types__4a84ef457ec365b76d5b35ae363501b4/node_modules/@radix-ui/react-collapsible/dist/index.js";
import { useId as re } from "../../../../../@radix-ui_react-id@1.1.1_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-id/dist/index.js";
import { useDirection as te } from "../../../../../@radix-ui_react-direction@1.1.1_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-direction/dist/index.js";
import { jsx as n } from "react/jsx-runtime";
var d = "Accordion", ne = ["Home", "End", "ArrowDown", "ArrowUp", "ArrowLeft", "ArrowRight"], [y, ce, ie] = W(d), [b, we] = Q(d, [
  ie,
  M
]), E = M(), V = s.forwardRef(
  (o, c) => {
    const { type: e, ...t } = o, i = t, r = t;
    return /* @__PURE__ */ n(y.Provider, { scope: o.__scopeAccordion, children: e === "multiple" ? /* @__PURE__ */ n(de, { ...r, ref: c }) : /* @__PURE__ */ n(se, { ...i, ref: c }) });
  }
);
V.displayName = d;
var [H, ae] = b(d), [K, le] = b(
  d,
  { collapsible: !1 }
), se = s.forwardRef(
  (o, c) => {
    const {
      value: e,
      defaultValue: t,
      onValueChange: i = () => {
      },
      collapsible: r = !1,
      ...l
    } = o, [a, p] = O({
      prop: e,
      defaultProp: t ?? "",
      onChange: i,
      caller: d
    });
    return /* @__PURE__ */ n(
      H,
      {
        scope: o.__scopeAccordion,
        value: s.useMemo(() => a ? [a] : [], [a]),
        onItemOpen: p,
        onItemClose: s.useCallback(() => r && p(""), [r, p]),
        children: /* @__PURE__ */ n(K, { scope: o.__scopeAccordion, collapsible: r, children: /* @__PURE__ */ n(L, { ...l, ref: c }) })
      }
    );
  }
), de = s.forwardRef((o, c) => {
  const {
    value: e,
    defaultValue: t,
    onValueChange: i = () => {
    },
    ...r
  } = o, [l, a] = O({
    prop: e,
    defaultProp: t ?? [],
    onChange: i,
    caller: d
  }), p = s.useCallback(
    (v) => a((u = []) => [...u, v]),
    [a]
  ), m = s.useCallback(
    (v) => a((u = []) => u.filter((h) => h !== v)),
    [a]
  );
  return /* @__PURE__ */ n(
    H,
    {
      scope: o.__scopeAccordion,
      value: l,
      onItemOpen: p,
      onItemClose: m,
      children: /* @__PURE__ */ n(K, { scope: o.__scopeAccordion, collapsible: !0, children: /* @__PURE__ */ n(L, { ...r, ref: c }) })
    }
  );
}), [pe, I] = b(d), L = s.forwardRef(
  (o, c) => {
    const { __scopeAccordion: e, disabled: t, dir: i, orientation: r = "vertical", ...l } = o, a = s.useRef(null), p = X(a, c), m = ce(e), u = te(i) === "ltr", h = Z(o.onKeyDown, (A) => {
      if (!ne.includes(A.key)) return;
      const F = A.target, x = m().filter((N) => !N.ref.current?.disabled), C = x.findIndex((N) => N.ref.current === F), D = x.length;
      if (C === -1) return;
      A.preventDefault();
      let f = C;
      const _ = 0, w = D - 1, R = () => {
        f = C + 1, f > w && (f = _);
      }, P = () => {
        f = C - 1, f < _ && (f = w);
      };
      switch (A.key) {
        case "Home":
          f = _;
          break;
        case "End":
          f = w;
          break;
        case "ArrowRight":
          r === "horizontal" && (u ? R() : P());
          break;
        case "ArrowDown":
          r === "vertical" && R();
          break;
        case "ArrowLeft":
          r === "horizontal" && (u ? P() : R());
          break;
        case "ArrowUp":
          r === "vertical" && P();
          break;
      }
      const J = f % D;
      x[J].ref.current?.focus();
    });
    return /* @__PURE__ */ n(
      pe,
      {
        scope: e,
        disabled: t,
        direction: i,
        orientation: r,
        children: /* @__PURE__ */ n(y.Slot, { scope: e, children: /* @__PURE__ */ n(
          T.div,
          {
            ...l,
            "data-orientation": r,
            ref: p,
            onKeyDown: t ? void 0 : h
          }
        ) })
      }
    );
  }
), g = "AccordionItem", [fe, k] = b(g), z = s.forwardRef(
  (o, c) => {
    const { __scopeAccordion: e, value: t, ...i } = o, r = I(g, e), l = ae(g, e), a = E(e), p = re(), m = t && l.value.includes(t) || !1, v = r.disabled || o.disabled;
    return /* @__PURE__ */ n(
      fe,
      {
        scope: e,
        open: m,
        disabled: v,
        triggerId: p,
        children: /* @__PURE__ */ n(
          $,
          {
            "data-orientation": r.orientation,
            "data-state": B(m),
            ...a,
            ...i,
            ref: c,
            disabled: v,
            open: m,
            onOpenChange: (u) => {
              u ? l.onItemOpen(t) : l.onItemClose(t);
            }
          }
        )
      }
    );
  }
);
z.displayName = g;
var G = "AccordionHeader", U = s.forwardRef(
  (o, c) => {
    const { __scopeAccordion: e, ...t } = o, i = I(d, e), r = k(G, e);
    return /* @__PURE__ */ n(
      T.h3,
      {
        "data-orientation": i.orientation,
        "data-state": B(r.open),
        "data-disabled": r.disabled ? "" : void 0,
        ...t,
        ref: c
      }
    );
  }
);
U.displayName = G;
var S = "AccordionTrigger", j = s.forwardRef(
  (o, c) => {
    const { __scopeAccordion: e, ...t } = o, i = I(d, e), r = k(S, e), l = le(S, e), a = E(e);
    return /* @__PURE__ */ n(y.ItemSlot, { scope: e, children: /* @__PURE__ */ n(
      ee,
      {
        "aria-disabled": r.open && !l.collapsible || void 0,
        "data-orientation": i.orientation,
        id: r.triggerId,
        ...a,
        ...t,
        ref: c
      }
    ) });
  }
);
j.displayName = S;
var Y = "AccordionContent", q = s.forwardRef(
  (o, c) => {
    const { __scopeAccordion: e, ...t } = o, i = I(d, e), r = k(Y, e), l = E(e);
    return /* @__PURE__ */ n(
      oe,
      {
        role: "region",
        "aria-labelledby": r.triggerId,
        "data-orientation": i.orientation,
        ...l,
        ...t,
        ref: c,
        style: {
          "--radix-accordion-content-height": "var(--radix-collapsible-content-height)",
          "--radix-accordion-content-width": "var(--radix-collapsible-content-width)",
          ...o.style
        }
      }
    );
  }
);
q.displayName = Y;
function B(o) {
  return o ? "open" : "closed";
}
var Re = V, Pe = z, Ne = U, Se = j, ye = q;
export {
  V as Accordion,
  q as AccordionContent,
  U as AccordionHeader,
  z as AccordionItem,
  j as AccordionTrigger,
  ye as Content,
  Ne as Header,
  Pe as Item,
  Re as Root,
  Se as Trigger,
  we as createAccordionScope
};
//# sourceMappingURL=index.js.map
