import p from "react";
import { createContextScope as y } from "../../../../../@radix-ui_react-context@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-context/dist/index.js";
import { Primitive as G } from "../../../../../@radix-ui_react-primitive@2.0.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_rea_bdcf182289a3a76356f07e550726e479/node_modules/@radix-ui/react-primitive/dist/index.js";
import { createRovingFocusGroupScope as T, Item as S, Root as V } from "../../../../../@radix-ui_react-roving-focus@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types__089b118f90c2a8e34e48dd885dbeaf66/node_modules/@radix-ui/react-roving-focus/dist/index.js";
import { Toggle as A } from "../../../../../@radix-ui_react-toggle@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@_395ede09337370dd5d655f0c82bcdf7c/node_modules/@radix-ui/react-toggle/dist/index.js";
import { useControllableState as P } from "../../../../../@radix-ui_react-use-controllable-state@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
import { useDirection as E } from "../../../../../@radix-ui_react-direction@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-direction/dist/index.js";
import { j as s } from "../../../../../../../_virtual/jsx-runtime.js";
var v = "ToggleGroup", [_, z] = y(v, [
  T
]), C = T(), f = p.forwardRef((e, r) => {
  const { type: a, ...t } = e;
  if (a === "single") {
    const l = t;
    return /* @__PURE__ */ s.jsx(F, { ...l, ref: r });
  }
  if (a === "multiple") {
    const l = t;
    return /* @__PURE__ */ s.jsx(M, { ...l, ref: r });
  }
  throw new Error(`Missing prop \`type\` expected on \`${v}\``);
});
f.displayName = v;
var [I, h] = _(v), F = p.forwardRef((e, r) => {
  const {
    value: a,
    defaultValue: t,
    onValueChange: l = () => {
    },
    ...u
  } = e, [n, o] = P({
    prop: a,
    defaultProp: t,
    onChange: l
  });
  return /* @__PURE__ */ s.jsx(
    I,
    {
      scope: e.__scopeToggleGroup,
      type: "single",
      value: n ? [n] : [],
      onItemActivate: o,
      onItemDeactivate: p.useCallback(() => o(""), [o]),
      children: /* @__PURE__ */ s.jsx(j, { ...u, ref: r })
    }
  );
}), M = p.forwardRef((e, r) => {
  const {
    value: a,
    defaultValue: t,
    onValueChange: l = () => {
    },
    ...u
  } = e, [n = [], o] = P({
    prop: a,
    defaultProp: t,
    onChange: l
  }), c = p.useCallback(
    (i) => o((g = []) => [...g, i]),
    [o]
  ), d = p.useCallback(
    (i) => o((g = []) => g.filter((b) => b !== i)),
    [o]
  );
  return /* @__PURE__ */ s.jsx(
    I,
    {
      scope: e.__scopeToggleGroup,
      type: "multiple",
      value: n,
      onItemActivate: c,
      onItemDeactivate: d,
      children: /* @__PURE__ */ s.jsx(j, { ...u, ref: r })
    }
  );
});
f.displayName = v;
var [w, D] = _(v), j = p.forwardRef(
  (e, r) => {
    const {
      __scopeToggleGroup: a,
      disabled: t = !1,
      rovingFocus: l = !0,
      orientation: u,
      dir: n,
      loop: o = !0,
      ...c
    } = e, d = C(a), i = E(n), g = { role: "group", dir: i, ...c };
    return /* @__PURE__ */ s.jsx(w, { scope: a, rovingFocus: l, disabled: t, children: l ? /* @__PURE__ */ s.jsx(
      V,
      {
        asChild: !0,
        ...d,
        orientation: u,
        dir: i,
        loop: o,
        children: /* @__PURE__ */ s.jsx(G.div, { ...g, ref: r })
      }
    ) : /* @__PURE__ */ s.jsx(G.div, { ...g, ref: r }) });
  }
), m = "ToggleGroupItem", R = p.forwardRef(
  (e, r) => {
    const a = h(m, e.__scopeToggleGroup), t = D(m, e.__scopeToggleGroup), l = C(e.__scopeToggleGroup), u = a.value.includes(e.value), n = t.disabled || e.disabled, o = { ...e, pressed: u, disabled: n }, c = p.useRef(null);
    return t.rovingFocus ? /* @__PURE__ */ s.jsx(
      S,
      {
        asChild: !0,
        ...l,
        focusable: !n,
        active: u,
        ref: c,
        children: /* @__PURE__ */ s.jsx(x, { ...o, ref: r })
      }
    ) : /* @__PURE__ */ s.jsx(x, { ...o, ref: r });
  }
);
R.displayName = m;
var x = p.forwardRef(
  (e, r) => {
    const { __scopeToggleGroup: a, value: t, ...l } = e, u = h(m, a), n = { role: "radio", "aria-checked": e.pressed, "aria-pressed": void 0 }, o = u.type === "single" ? n : void 0;
    return /* @__PURE__ */ s.jsx(
      A,
      {
        ...o,
        ...l,
        ref: r,
        onPressedChange: (c) => {
          c ? u.onItemActivate(t) : u.onItemDeactivate(t);
        }
      }
    );
  }
), H = f, J = R;
export {
  J as Item,
  H as Root,
  f as ToggleGroup,
  R as ToggleGroupItem,
  z as createToggleGroupScope
};
//# sourceMappingURL=index.js.map
