import { jsx as O, jsxs as Ne } from "react/jsx-runtime";
import { a as F } from "../index-BmAFn37q.mjs";
import * as s from "react";
import { createContext as Re, useContext as Ee } from "react";
import { a as ee } from "../Slot-C98rL4yy.mjs";
import { w as te, d as ve, c as Ie, u as Me, C as Oe, a as ne, t as Ae, b as Pe } from "../useCollapsiblePanel-kbMNl4Z4.mjs";
import { c as V, m as J, a as P, f as oe, j as L, d as we, n as ye, i as Se, g as De, k as ke, l as Te } from "../useOpenChangeComplete-RUbg6RBw.mjs";
import { a as Q } from "../useTransitionStatus-CktVVKxz.mjs";
import { ArrowHorizontalDown as _e } from "@spark-ui/icons/ArrowHorizontalDown";
import { I as Ve } from "../Icon-D1RueiPY.mjs";
import { s as Ue, A as re, a as se, b as ie, c as ae, H as Fe, E as He } from "../composite-Br3kM5N9.mjs";
const W = /* @__PURE__ */ s.createContext({
  register: () => {
  },
  unregister: () => {
  },
  subscribeMapChange: () => () => {
  },
  elementsRef: {
    current: []
  },
  nextIndexRef: {
    current: 0
  }
});
process.env.NODE_ENV !== "production" && (W.displayName = "CompositeListContext");
function Le() {
  return s.useContext(W);
}
function ze(e) {
  const {
    children: o,
    elementsRef: n,
    labelsRef: i,
    onMapChange: m
  } = e, r = V(m), l = s.useRef(0), h = J(Be).current, b = J(We).current, [R, N] = s.useState(0), p = s.useRef(R), E = V((t, u) => {
    b.set(t, u ?? null), p.current += 1, N(p.current);
  }), f = V((t) => {
    b.delete(t), p.current += 1, N(p.current);
  }), d = s.useMemo(() => {
    const t = /* @__PURE__ */ new Map();
    return Array.from(b.keys()).filter((c) => c.isConnected).sort(je).forEach((c, x) => {
      const a = b.get(c) ?? {};
      t.set(c, {
        ...a,
        index: x
      });
    }), t;
  }, [b, R]);
  P(() => {
    if (typeof MutationObserver != "function" || d.size === 0)
      return;
    const t = new MutationObserver((u) => {
      const c = /* @__PURE__ */ new Set(), x = (a) => c.has(a) ? c.delete(a) : c.add(a);
      u.forEach((a) => {
        a.removedNodes.forEach(x), a.addedNodes.forEach(x);
      }), c.size === 0 && (p.current += 1, N(p.current));
    });
    return d.forEach((u, c) => {
      c.parentElement && t.observe(c.parentElement, {
        childList: !0
      });
    }), () => {
      t.disconnect();
    };
  }, [d]), P(() => {
    p.current === R && (n.current.length !== d.size && (n.current.length = d.size), i && i.current.length !== d.size && (i.current.length = d.size), l.current = d.size), r(d);
  }, [r, d, n, i, R]), P(() => () => {
    n.current = [];
  }, [n]), P(() => () => {
    i && (i.current = []);
  }, [i]);
  const g = V((t) => (h.add(t), () => {
    h.delete(t);
  }));
  P(() => {
    h.forEach((t) => t(d));
  }, [h, d]);
  const v = s.useMemo(() => ({
    register: E,
    unregister: f,
    subscribeMapChange: g,
    elementsRef: n,
    labelsRef: i,
    nextIndexRef: l
  }), [E, f, g, n, i, l]);
  return /* @__PURE__ */ O(W.Provider, {
    value: v,
    children: o
  });
}
function We() {
  return /* @__PURE__ */ new Map();
}
function Be() {
  return /* @__PURE__ */ new Set();
}
function je(e, o) {
  const n = e.compareDocumentPosition(o);
  return n & Node.DOCUMENT_POSITION_FOLLOWING || n & Node.DOCUMENT_POSITION_CONTAINED_BY ? -1 : n & Node.DOCUMENT_POSITION_PRECEDING || n & Node.DOCUMENT_POSITION_CONTAINS ? 1 : 0;
}
const ce = /* @__PURE__ */ s.createContext(void 0);
process.env.NODE_ENV !== "production" && (ce.displayName = "DirectionContext");
function Ge() {
  return s.useContext(ce)?.direction ?? "ltr";
}
const B = /* @__PURE__ */ s.createContext(void 0);
process.env.NODE_ENV !== "production" && (B.displayName = "AccordionRootContext");
function j() {
  const e = s.useContext(B);
  if (e === void 0)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: AccordionRootContext is missing. Accordion parts must be placed within <Accordion.Root>." : oe(10));
  return e;
}
const Ke = {
  value: () => null
}, de = /* @__PURE__ */ s.forwardRef(function(o, n) {
  const {
    render: i,
    className: m,
    disabled: r = !1,
    hiddenUntilFound: l,
    keepMounted: h,
    loopFocus: b = !0,
    onValueChange: R,
    multiple: N = !1,
    orientation: p = "vertical",
    value: E,
    defaultValue: f,
    ...d
  } = o, g = Ge();
  process.env.NODE_ENV !== "production" && P(() => {
    l && h === !1 && te("The `keepMounted={false}` prop on a Accordion.Root will be ignored when using `hiddenUntilFound` since it requires Panels to remain mounted when closed.");
  }, [l, h]);
  const v = s.useMemo(() => {
    if (E === void 0)
      return f ?? [];
  }, [E, f]), t = V(R), u = s.useRef([]), [c, x] = ve({
    controlled: E,
    default: v,
    name: "Accordion",
    state: "value"
  }), a = V((S, _) => {
    const I = we(ye);
    if (N)
      if (_) {
        const C = c.slice();
        if (C.push(S), t(C, I), I.isCanceled)
          return;
        x(C);
      } else {
        const C = c.filter((A) => A !== S);
        if (t(C, I), I.isCanceled)
          return;
        x(C);
      }
    else {
      const C = c[0] === S ? [] : [S];
      if (t(C, I), I.isCanceled)
        return;
      x(C);
    }
  }), y = s.useMemo(() => ({
    value: c,
    disabled: r,
    orientation: p
  }), [c, r, p]), T = s.useMemo(() => ({
    accordionItemRefs: u,
    direction: g,
    disabled: r,
    handleValueChange: a,
    hiddenUntilFound: l ?? !1,
    keepMounted: h ?? !1,
    loopFocus: b,
    orientation: p,
    state: y,
    value: c
  }), [g, r, a, l, h, b, p, y, c]), k = L("div", o, {
    state: y,
    ref: n,
    props: [{
      dir: g,
      role: "region"
    }, d],
    stateAttributesMapping: Ke
  });
  return /* @__PURE__ */ O(B.Provider, {
    value: T,
    children: /* @__PURE__ */ O(ze, {
      elementsRef: u,
      children: k
    })
  });
});
process.env.NODE_ENV !== "production" && (de.displayName = "AccordionRoot");
let qe = /* @__PURE__ */ (function(e) {
  return e[e.None = 0] = "None", e[e.GuessFromOrder = 1] = "GuessFromOrder", e;
})({});
function $e(e = {}) {
  const {
    label: o,
    metadata: n,
    textRef: i,
    indexGuessBehavior: m,
    index: r
  } = e, {
    register: l,
    unregister: h,
    subscribeMapChange: b,
    elementsRef: R,
    labelsRef: N,
    nextIndexRef: p
  } = Le(), E = s.useRef(-1), [f, d] = s.useState(r ?? (m === qe.GuessFromOrder ? () => {
    if (E.current === -1) {
      const t = p.current;
      p.current += 1, E.current = t;
    }
    return E.current;
  } : -1)), g = s.useRef(null), v = s.useCallback((t) => {
    if (g.current = t, f !== -1 && t !== null && (R.current[f] = t, N)) {
      const u = o !== void 0;
      N.current[f] = u ? o : i?.current?.textContent ?? t.textContent;
    }
  }, [f, R, N, o, i]);
  return P(() => {
    if (r != null)
      return;
    const t = g.current;
    if (t)
      return l(t, n), () => {
        h(t);
      };
  }, [r, l, h, n]), P(() => {
    if (r == null)
      return b((t) => {
        const u = g.current ? t.get(g.current)?.index : null;
        u != null && d(u);
      });
  }, [r, b, d]), s.useMemo(() => ({
    ref: v,
    index: f
  }), [f, v]);
}
const G = /* @__PURE__ */ s.createContext(void 0);
process.env.NODE_ENV !== "production" && (G.displayName = "AccordionItemContext");
function ue() {
  const e = s.useContext(G);
  if (e === void 0)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: AccordionItemContext is missing. Accordion parts must be placed within <Accordion.Item>." : oe(9));
  return e;
}
let Ye = /* @__PURE__ */ (function(e) {
  return e.index = "data-index", e.disabled = "data-disabled", e.open = "data-open", e;
})({});
const le = {
  ...Ie,
  index: (e) => Number.isInteger(e) ? {
    [Ye.index]: String(e)
  } : null,
  ...Se,
  value: () => null
}, pe = /* @__PURE__ */ s.forwardRef(function(o, n) {
  const {
    className: i,
    disabled: m = !1,
    onOpenChange: r,
    render: l,
    value: h,
    ...b
  } = o, {
    ref: R,
    index: N
  } = $e(), p = De(n, R), {
    disabled: E,
    handleValueChange: f,
    state: d,
    value: g
  } = j(), v = Q(), t = h ?? v, u = m || E, c = s.useMemo(() => {
    if (!g)
      return !1;
    for (let A = 0; A < g.length; A += 1)
      if (g[A] === t)
        return !0;
    return !1;
  }, [g, t]), x = V((A, D) => {
    r?.(A, D), !D.isCanceled && f(t, A);
  }), a = Me({
    open: c,
    onOpenChange: x,
    disabled: u
  }), y = s.useMemo(() => ({
    open: a.open,
    disabled: a.disabled,
    hidden: !a.mounted,
    transitionStatus: a.transitionStatus
  }), [a.open, a.disabled, a.mounted, a.transitionStatus]), T = s.useMemo(() => ({
    ...a,
    onOpenChange: x,
    state: y
  }), [a, y, x]), k = s.useMemo(() => ({
    ...d,
    index: N,
    disabled: u,
    open: c
  }), [u, N, c, d]), [S, _] = s.useState(Q()), I = s.useMemo(() => ({
    open: c,
    state: k,
    setTriggerId: _,
    triggerId: S
  }), [c, k, _, S]), C = L("div", o, {
    state: k,
    ref: p,
    props: b,
    stateAttributesMapping: le
  });
  return /* @__PURE__ */ O(Oe.Provider, {
    value: T,
    children: /* @__PURE__ */ O(G.Provider, {
      value: I,
      children: C
    })
  });
});
process.env.NODE_ENV !== "production" && (pe.displayName = "AccordionItem");
function X(e) {
  return e == null || e.hasAttribute("disabled") || e.getAttribute("aria-disabled") === "true";
}
const Je = /* @__PURE__ */ new Set([re, se, ie, ae, Fe, He]);
function Qe(e) {
  const {
    current: o
  } = e, n = [];
  for (let i = 0; i < o.length; i += 1) {
    const m = o[i];
    if (!X(m)) {
      const r = m?.querySelector('[type="button"]');
      X(r) || n.push(r);
    }
  }
  return n;
}
const fe = /* @__PURE__ */ s.forwardRef(function(o, n) {
  const {
    disabled: i,
    className: m,
    id: r,
    render: l,
    nativeButton: h = !0,
    ...b
  } = o, {
    panelId: R,
    open: N,
    handleTrigger: p,
    disabled: E
  } = ne(), f = i ?? E, {
    getButtonProps: d,
    buttonRef: g
  } = ke({
    disabled: f,
    focusableWhenDisabled: !0,
    native: h
  }), {
    accordionItemRefs: v,
    direction: t,
    loopFocus: u,
    orientation: c
  } = j(), x = t === "rtl", a = c === "horizontal", {
    state: y,
    setTriggerId: T,
    triggerId: k
  } = ue();
  P(() => (r && T(r), () => {
    T(void 0);
  }), [r, T]);
  const S = s.useMemo(() => ({
    "aria-controls": N ? R : void 0,
    "aria-expanded": N,
    disabled: f,
    id: k,
    onClick: p,
    onKeyDown(I) {
      if (!Je.has(I.key))
        return;
      Ue(I);
      const C = Qe(v), D = C.length - 1;
      let M = -1;
      const w = C.indexOf(I.target);
      function H() {
        u ? M = w + 1 > D ? 0 : w + 1 : M = Math.min(w + 1, D);
      }
      function U() {
        u ? M = w === 0 ? D : w - 1 : M = w - 1;
      }
      switch (I.key) {
        case re:
          a || H();
          break;
        case se:
          a || U();
          break;
        case ie:
          a && (x ? U() : H());
          break;
        case ae:
          a && (x ? H() : U());
          break;
        case "Home":
          M = 0;
          break;
        case "End":
          M = D;
          break;
      }
      M > -1 && C[M].focus();
    }
  }), [v, f, p, k, a, x, u, N, R]);
  return L("button", o, {
    state: y,
    ref: [n, g],
    props: [S, b, d],
    stateAttributesMapping: Ae
  });
});
process.env.NODE_ENV !== "production" && (fe.displayName = "AccordionTrigger");
let Z = /* @__PURE__ */ (function(e) {
  return e.accordionPanelHeight = "--accordion-panel-height", e.accordionPanelWidth = "--accordion-panel-width", e;
})({});
const me = /* @__PURE__ */ s.forwardRef(function(o, n) {
  const {
    className: i,
    hiddenUntilFound: m,
    keepMounted: r,
    id: l,
    render: h,
    ...b
  } = o, {
    hiddenUntilFound: R,
    keepMounted: N
  } = j(), {
    abortControllerRef: p,
    animationTypeRef: E,
    height: f,
    mounted: d,
    onOpenChange: g,
    open: v,
    panelId: t,
    panelRef: u,
    runOnceAnimationsFinish: c,
    setDimensions: x,
    setHiddenUntilFound: a,
    setKeepMounted: y,
    setMounted: T,
    setOpen: k,
    setVisible: S,
    transitionDimensionRef: _,
    visible: I,
    width: C,
    setPanelIdState: A,
    transitionStatus: D
  } = ne(), M = m ?? R, w = r ?? N;
  process.env.NODE_ENV !== "production" && P(() => {
    r === !1 && M && te("The `keepMounted={false}` prop on a Accordion.Panel will be ignored when using `contextHiddenUntilFound` on the Panel or the Root since it requires the panel to remain mounted when closed.");
  }, [M, r]), P(() => {
    if (l)
      return A(l), () => {
        A(void 0);
      };
  }, [l, A]), P(() => {
    a(M);
  }, [a, M]), P(() => {
    y(w);
  }, [y, w]), Te({
    open: v && D === "idle",
    ref: u,
    onComplete() {
      v && x({
        width: void 0,
        height: void 0
      });
    }
  });
  const {
    props: H
  } = Pe({
    abortControllerRef: p,
    animationTypeRef: E,
    externalRef: n,
    height: f,
    hiddenUntilFound: M,
    id: l ?? t,
    keepMounted: w,
    mounted: d,
    onOpenChange: g,
    open: v,
    panelRef: u,
    runOnceAnimationsFinish: c,
    setDimensions: x,
    setMounted: T,
    setOpen: k,
    setVisible: S,
    transitionDimensionRef: _,
    visible: I,
    width: C
  }), {
    state: U,
    triggerId: be
  } = ue(), xe = s.useMemo(() => ({
    ...U,
    transitionStatus: D
  }), [U, D]), Ce = L("div", o, {
    state: xe,
    ref: [n, u],
    props: [H, {
      "aria-labelledby": be,
      role: "region",
      style: {
        [Z.accordionPanelHeight]: f === void 0 ? "auto" : `${f}px`,
        [Z.accordionPanelWidth]: C === void 0 ? "auto" : `${C}px`
      }
    }, b],
    stateAttributesMapping: le
  });
  return w || M || !w && d ? Ce : null;
});
process.env.NODE_ENV !== "production" && (me.displayName = "AccordionPanel");
function z(e, o) {
  const n = e ? ee : o;
  return e ? ({ ...i }) => /* @__PURE__ */ O(n, { ...i }) : void 0;
}
const ge = Re(null), he = ({
  asChild: e = !1,
  children: o,
  design: n = "outlined",
  hiddenUntilFound: i = !0,
  multiple: m = !1,
  className: r,
  ref: l,
  ...h
}) => {
  const b = z(e, "div");
  return /* @__PURE__ */ O(ge.Provider, { value: { design: n }, children: /* @__PURE__ */ O(
    de,
    {
      "data-spark-component": "accordion",
      ref: l,
      multiple: m,
      hiddenUntilFound: i,
      className: F("bg-surface h-fit rounded-lg", r),
      render: b,
      ...h,
      children: o
    }
  ) });
};
he.displayName = "Accordion";
const Xe = () => {
  const e = Ee(ge);
  if (!e)
    throw Error("useAccordionContext must be used within a Accordion provider");
  return e;
}, K = ({
  asChild: e = !1,
  className: o,
  children: n,
  ref: i,
  ...m
}) => {
  const r = Xe(), l = z(e, "div");
  return /* @__PURE__ */ O(
    pe,
    {
      ref: i,
      "data-spark-component": "accordion-item",
      render: l,
      className: F(
        "relative first:rounded-t-lg last:rounded-b-lg",
        "not-last:border-b-0",
        { "border-sm border-outline": r.design === "outlined" },
        o
      ),
      ...m,
      children: n
    }
  );
};
K.displayName = "Accordion.Item";
const q = ({
  asChild: e = !1,
  className: o,
  children: n,
  ref: i,
  ...m
}) => {
  const r = z(e, "div");
  return /* @__PURE__ */ O(
    me,
    {
      ref: i,
      "data-spark-component": "accordion-item-content",
      className: F(
        "[&>:first-child]:p-lg overflow-hidden",
        "h-[var(--accordion-panel-height)] transition-all duration-200 data-[ending-style]:h-0 data-[starting-style]:h-0",
        "text-body-1 text-on-surface",
        o
      ),
      render: r,
      ...m,
      children: n
    }
  );
};
q.displayName = "Accordion.ItemContent";
const $ = ({
  asChild: e = !1,
  children: o,
  className: n,
  ref: i
}) => /* @__PURE__ */ O(
  e ? ee : "h3",
  {
    ref: i,
    "data-spark-component": "accordion-item-header",
    className: F("rounded-[inherit]", n),
    children: o
  }
);
$.displayName = "Accordion.ItemHeader";
const Y = ({
  asChild: e = !1,
  children: o,
  className: n,
  ref: i,
  ...m
}) => {
  const r = z(e, "button");
  return /* @__PURE__ */ Ne(
    fe,
    {
      ref: i,
      "data-spark-component": "accordion-item-trigger",
      render: r,
      className: F(
        "group",
        "gap-lg min-h-sz-48 relative flex items-center justify-between",
        "px-lg py-md text-headline-2 text-on-surface data-[panel-open]:rounded-b-0 w-full rounded-[inherit] text-left",
        "hover:enabled:bg-surface-hovered focus:bg-surface-hovered",
        "focus-visible:u-outline focus-visible:z-raised focus-visible:outline-hidden",
        "disabled:opacity-dim-3 cursor-pointer disabled:cursor-not-allowed",
        n
      ),
      ...m,
      children: [
        /* @__PURE__ */ O("div", { className: "gap-lg flex grow items-center", children: o }),
        /* @__PURE__ */ O(
          Ve,
          {
            intent: "neutral",
            className: F(
              "shrink-0 rotate-0 duration-100 ease-in motion-reduce:transition-none",
              "group-data-[panel-open]:rotate-180"
            ),
            size: "sm",
            children: /* @__PURE__ */ O(_e, {})
          }
        )
      ]
    }
  );
};
Y.displayName = "Accordion.ItemTrigger";
const Ze = Object.assign(he, {
  Item: K,
  ItemHeader: $,
  ItemTrigger: Y,
  ItemContent: q
});
Ze.displayName = "Accordion";
K.displayName = "Item";
$.displayName = "ItemHeader";
Y.displayName = "Accordion.Trigger";
q.displayName = "Accordion.Content";
export {
  Ze as Accordion
};
//# sourceMappingURL=index.mjs.map
