import { $ as m, a as x } from "./utils-B6pV5ewr.es.js";
import { $ as C, a as E } from "./SelectionIndicator-B27AsfqE.es.js";
import { e as F, $ as f } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as D } from "./filterDOMProps-BSVCO5jK.es.js";
import n, { useMemo as g, forwardRef as h, createContext as $, useContext as B } from "react";
import { $ as T } from "./useControlledState-u436Wbp1.es.js";
import { $ as H } from "./useButton-CiPiehgC.es.js";
import { $ as V } from "./useToolbar-CbJkugif.es.js";
import { $ as z } from "./useToggleState-Uh0wTgdI.es.js";
import { $ as G } from "./useFocusRing-FPt2Rwil.es.js";
import { $ as N } from "./useHover-BQRSM3qT.es.js";
function K(d, e, s) {
  const { isSelected: t } = e, { isPressed: i, buttonProps: o } = H({
    ...d,
    onPress: F(e.toggle, d.onPress)
  }, s);
  return {
    isPressed: i,
    isSelected: t,
    isDisabled: d.isDisabled || !1,
    buttonProps: f(o, {
      "aria-pressed": t
    })
  };
}
function O(d, e, s) {
  let { isDisabled: t } = d, { toolbarProps: i } = V(d, s);
  return {
    groupProps: {
      ...i,
      role: e.selectionMode === "single" ? "radiogroup" : i.role,
      "aria-disabled": t
    }
  };
}
function R(d, e, s) {
  let t = {
    isSelected: e.selectedKeys.has(d.id),
    defaultSelected: !1,
    setSelected(c) {
      e.setSelected(d.id, c);
    },
    toggle() {
      e.toggleKey(d.id);
    }
  }, { isPressed: i, isSelected: o, isDisabled: a, buttonProps: l } = K({
    ...d,
    id: void 0,
    isDisabled: d.isDisabled || e.isDisabled
  }, t, s);
  return e.selectionMode === "single" && (l.role = "radio", l["aria-checked"] = t.isSelected, delete l["aria-pressed"]), {
    isPressed: i,
    isSelected: o,
    isDisabled: a,
    buttonProps: l
  };
}
function _(d) {
  let { selectionMode: e = "single", disallowEmptySelection: s, isDisabled: t = !1 } = d, [i, o] = T(g(() => d.selectedKeys ? new Set(d.selectedKeys) : void 0, [
    d.selectedKeys
  ]), g(() => d.defaultSelectedKeys ? new Set(d.defaultSelectedKeys) : /* @__PURE__ */ new Set(), [
    d.defaultSelectedKeys
  ]), d.onSelectionChange);
  return {
    selectionMode: e,
    isDisabled: t,
    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 t = _(e), { groupProps: i } = O(e, t, s), o = x({
    ...e,
    values: {
      isDisabled: t.isDisabled,
      state: t
    },
    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: t
  }, /* @__PURE__ */ n.createElement(C, null, o.children)));
}), q = /* @__PURE__ */ $({}), ee = /* @__PURE__ */ h(function(e, s) {
  [e, s] = m(e, s, q);
  let t = B(v), i = z(t && e.id != null ? {
    isSelected: t.selectedKeys.has(e.id),
    onChange(M) {
      t.setSelected(e.id, M);
    }
  } : e), { buttonProps: o, isPressed: a, isSelected: l, isDisabled: c } = t && e.id != null ? R({
    ...e,
    id: e.id
  }, t, 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-BqW-X6iJ.es.js.map
