"use client";
import { jsx as v } from "react/jsx-runtime";
import { c as O } from "../../../index-UgeK3A8s.js";
import { cn as k } from "../../../lib/utils.js";
import * as u from "react";
import { u as D } from "../../../useStableCallback-CudqoENs.js";
import { u as R } from "../../../useControlled-Sx-_x7Sz.js";
import { u as j } from "../../../useIsoLayoutEffect-DpJo20by.js";
import { e as S, a as U } from "../../../useButton-JYPKQKj4.js";
import { u as A } from "../../../useBaseUiId-C8Dq0BQq.js";
import { f as L, u as M } from "../../../useRenderElement-DNB2vtF1.js";
import { C as $ } from "../../../CompositeItem-CniPsjzP.js";
import { c as q, n as F } from "../../../createBaseUIEventDetails-CqidROtw.js";
const h = /* @__PURE__ */ u.createContext(void 0);
process.env.NODE_ENV !== "production" && (h.displayName = "ToggleGroupContext");
function H(n = !0) {
  const t = u.useContext(h);
  if (t === void 0 && !n)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: ToggleGroupContext is missing. ToggleGroup parts must be placed within <ToggleGroup>." : L(7));
  return t;
}
const b = /* @__PURE__ */ u.forwardRef(function(t, a) {
  const {
    className: i,
    defaultPressed: x = !1,
    disabled: T = !1,
    form: K,
    // never participates in form validation
    onPressedChange: C,
    pressed: w,
    render: E,
    type: Q,
    // cannot change button type
    value: d,
    nativeButton: P = !0,
    ...N
  } = t, s = A(d || void 0), e = H(), G = e?.value ?? [], V = e ? void 0 : x, p = (T || e?.disabled) ?? !1;
  process.env.NODE_ENV !== "production" && j(() => {
    e && d === void 0 && e.isValueInitialized && S("A `<Toggle>` component rendered in a `<ToggleGroup>` has no explicit `value` prop.", "This will cause issues between the Toggle Group and Toggle values.", "Provide the `<Toggle>` with a `value` prop matching the `<ToggleGroup>` values prop type.");
  }, [e, d, e?.isValueInitialized]);
  const [l, y] = R({
    controlled: e ? s !== void 0 && G.indexOf(s) > -1 : w,
    default: V,
    name: "Toggle",
    state: "pressed"
  }), _ = D((r, o) => {
    s && e?.setGroupValue?.(s, r, o), C?.(r, o);
  }), {
    getButtonProps: z,
    buttonRef: I
  } = U({
    disabled: p,
    native: P
  }), c = {
    disabled: p,
    pressed: l
  }, g = [I, a], f = [{
    "aria-pressed": l,
    onClick(r) {
      const o = !l, m = q(F, r.nativeEvent);
      _(o, m), !m.isCanceled && y(o);
    }
  }, N, z], B = M("button", t, {
    enabled: !e,
    state: c,
    ref: g,
    props: f
  });
  return e ? /* @__PURE__ */ v($, {
    tag: "button",
    render: E,
    className: i,
    state: c,
    refs: g,
    props: f
  }) : B;
});
process.env.NODE_ENV !== "production" && (b.displayName = "Toggle");
const J = O(
  "group/toggle inline-flex items-center justify-center gap-1 whitespace-nowrap rounded-md font-medium text-sm outline-none transition-[color,box-shadow] hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-pressed:bg-muted aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
  {
    variants: {
      variant: {
        default: "bg-transparent",
        outline: "border border-input bg-transparent shadow-xs hover:bg-muted"
      },
      size: {
        default: "h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
        sm: "h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
        lg: "h-10 min-w-10 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2"
      }
    },
    defaultVariants: {
      variant: "default",
      size: "default"
    }
  }
);
function ie({
  className: n,
  variant: t = "default",
  size: a = "default",
  ...i
}) {
  return /* @__PURE__ */ v(
    b,
    {
      className: k(J({ variant: t, size: a, className: n })),
      "data-slot": "toggle",
      ...i
    }
  );
}
export {
  ie as Toggle,
  J as toggleVariants
};
