import { $ as m, a as x } from "./utils-CrjF8U_E.es.js";
import { $ as C, a as E } from "./SelectionIndicator-B27AsfqE.es.js";
import { d as F, $ as f } from "./mergeProps-B-cqsBhL.es.js";
import { $ as D } from "./filterDOMProps-Cxz9cAAv.es.js";
import n, { useMemo as g, forwardRef as h, createContext as $, useContext as B } from "react";
import { $ as T } from "./useControlledState-3TGZUXux.es.js";
import { $ as z } from "./useButton-C0YxSZ4p.es.js";
import { $ as H } from "./useToolbar-NGUPId3z.es.js";
import { $ as V } from "./useToggleState-DWm4nWJh.es.js";
import { $ as G } from "./useFocusRing-CZQUsztf.es.js";
import { $ as N } from "./useHover-BiPYlZr_.es.js";
function K(t, e, s) {
  const { isSelected: d } = e, { isPressed: i, buttonProps: o } = z({
    ...t,
    onPress: F(e.toggle, t.onPress)
  }, s);
  return {
    isPressed: i,
    isSelected: d,
    isDisabled: t.isDisabled || !1,
    buttonProps: f(o, {
      "aria-pressed": d
    })
  };
}
function O(t, e, s) {
  let { isDisabled: d } = t, { toolbarProps: i } = H(t, s);
  return {
    groupProps: {
      ...i,
      role: e.selectionMode === "single" ? "radiogroup" : i.role,
      "aria-disabled": d
    }
  };
}
function R(t, e, s) {
  let d = {
    isSelected: e.selectedKeys.has(t.id),
    defaultSelected: !1,
    setSelected(c) {
      e.setSelected(t.id, c);
    },
    toggle() {
      e.toggleKey(t.id);
    }
  }, { isPressed: i, isSelected: o, isDisabled: a, buttonProps: l } = K({
    ...t,
    id: void 0,
    isDisabled: t.isDisabled || e.isDisabled
  }, d, s);
  return e.selectionMode === "single" && (l.role = "radio", l["aria-checked"] = d.isSelected, delete l["aria-pressed"]), {
    isPressed: i,
    isSelected: o,
    isDisabled: a,
    buttonProps: l
  };
}
function _(t) {
  let { selectionMode: e = "single", disallowEmptySelection: s, isDisabled: d = !1 } = t, [i, o] = T(g(() => t.selectedKeys ? new Set(t.selectedKeys) : void 0, [
    t.selectedKeys
  ]), g(() => t.defaultSelectedKeys ? new Set(t.defaultSelectedKeys) : /* @__PURE__ */ new Set(), [
    t.defaultSelectedKeys
  ]), t.onSelectionChange);
  return {
    selectionMode: e,
    isDisabled: d,
    selectedKeys: i,
    setSelectedKeys: o,
    toggleKey(a) {
      let l;
      e === "multiple" ? (l = new Set(i), l.has(a) && (!s || l.size > 1) ? l.delete(a) : l.add(a)) : l = new Set(i.has(a) && !s ? [] : [
        a
      ]), o(l);
    },
    setSelected(a, l) {
      l !== i.has(a) && this.toggleKey(a);
    }
  };
}
const j = /* @__PURE__ */ $({}), v = /* @__PURE__ */ $(null), p = /* @__PURE__ */ h(function(e, s) {
  [e, s] = m(e, s, j);
  let d = _(e), { groupProps: i } = O(e, d, s), o = x({
    ...e,
    values: {
      orientation: e.orientation || "horizontal",
      isDisabled: d.isDisabled,
      state: d
    },
    defaultClassName: "react-aria-ToggleButtonGroup"
  }), a = D(e, {
    global: !0
  });
  return /* @__PURE__ */ n.createElement("div", {
    ...f(a, o, i),
    ref: s,
    slot: e.slot || void 0,
    "data-orientation": e.orientation || "horizontal",
    "data-disabled": e.isDisabled || void 0
  }, /* @__PURE__ */ n.createElement(v.Provider, {
    value: d
  }, /* @__PURE__ */ n.createElement(C, null, o.children)));
}), q = /* @__PURE__ */ $({}), ee = /* @__PURE__ */ h(function(e, s) {
  [e, s] = m(e, s, q);
  let d = B(v), i = V(d && e.id != null ? {
    isSelected: d.selectedKeys.has(e.id),
    onChange(M) {
      d.setSelected(e.id, M);
    }
  } : e), { buttonProps: o, isPressed: a, isSelected: l, isDisabled: c } = d && e.id != null ? R({
    ...e,
    id: e.id
  }, d, s) : K({
    ...e,
    id: e.id != null ? String(e.id) : void 0
  }, i, s), { focusProps: y, isFocused: u, isFocusVisible: b } = G(e), { hoverProps: w, isHovered: S } = N(e), P = x({
    ...e,
    id: void 0,
    values: {
      isHovered: S,
      isPressed: a,
      isFocused: u,
      isSelected: i.isSelected,
      isFocusVisible: b,
      isDisabled: c,
      state: i
    },
    defaultClassName: "react-aria-ToggleButton"
  }), r = D(e, {
    global: !0
  });
  return delete r.id, delete r.onClick, /* @__PURE__ */ n.createElement("button", {
    ...f(r, P, o, y, w),
    ref: s,
    slot: e.slot || void 0,
    "data-focused": u || void 0,
    "data-disabled": c || void 0,
    "data-pressed": a || void 0,
    "data-selected": l || void 0,
    "data-hovered": S || void 0,
    "data-focus-visible": b || void 0
  }, /* @__PURE__ */ n.createElement(E.Provider, {
    value: {
      isSelected: l
    }
  }, P.children));
});
export {
  ee as $,
  p as a
};
//# sourceMappingURL=ToggleButton-BwI1d60i.es.js.map
