import { o as k } from "./rolldown-runtime.js";
import { i as q, t as y } from "./vendor/react.js";
import { s as I, t as M } from "./useRenderElement.js";
import { n as V } from "./useIsoLayoutEffect.js";
import { t as N } from "./useButton.js";
import { t as O } from "./useBaseUiId.js";
import { g as U, t as z } from "./createBaseUIEventDetails.js";
import { t as A } from "./useControlled.js";
import { t as D } from "./CompositeItem.js";
var n = /* @__PURE__ */ k(q()), F = /* @__PURE__ */ n.createContext(void 0);
function H(i = !0) {
  const t = n.useContext(F);
  if (t === void 0 && !i) throw new Error(I(7));
  return t;
}
var J = y(), re = /* @__PURE__ */ n.forwardRef(function(t, m) {
  const { className: c, defaultPressed: g = !1, disabled: v = !1, form: K, onPressedChange: C, pressed: P, render: x, type: L, value: b, nativeButton: _ = !0, style: E, ...h } = t, r = O(b || void 0), e = H(), T = e?.value ?? [], B = e ? void 0 : g, u = (v || e?.disabled) ?? !1, [a, j] = A({
    controlled: e ? r !== void 0 && T.indexOf(r) > -1 : P,
    default: B,
    name: "Toggle",
    state: "pressed"
  }), w = V((s, o) => {
    r && e?.setGroupValue?.(r, s, o), C?.(s, o);
  }), { getButtonProps: G, buttonRef: R } = N({
    disabled: u,
    native: _
  }), d = {
    disabled: u,
    pressed: a
  }, l = [R, m], p = [
    {
      "aria-pressed": a,
      onClick(s) {
        const o = !a, f = z(U, s.nativeEvent);
        w(o, f), !f.isCanceled && j(o);
      }
    },
    h,
    G
  ], S = M("button", t, {
    enabled: !e,
    state: d,
    ref: l,
    props: p
  });
  return e ? /* @__PURE__ */ (0, J.jsx)(D, {
    tag: "button",
    render: x,
    className: c,
    style: E,
    state: d,
    refs: l,
    props: p
  }) : S;
});
export {
  F as n,
  re as t
};

//# sourceMappingURL=Toggle.js.map