import * as n from "react";
import { composeEventHandlers as j } from "../../../../../@radix-ui_primitive@1.1.0/node_modules/@radix-ui/primitive/dist/index.js";
import { useComposedRefs as T } from "../../../../../@radix-ui_react-compose-refs@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { createContextScope as _ } 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 { useControllableState as B } 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 { usePrevious as H } from "../../../../../@radix-ui_react-use-previous@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-use-previous/dist/index.js";
import { useSize as I } from "../../../../../@radix-ui_react-use-size@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-use-size/dist/index.js";
import { Primitive as w } 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 { j as p } from "../../../../../../../_virtual/jsx-runtime.js";
var v = "Switch", [M, G] = _(v), [N, q] = M(v), C = n.forwardRef(
  (e, a) => {
    const {
      __scopeSwitch: t,
      name: o,
      checked: r,
      defaultChecked: u,
      required: i,
      disabled: c,
      value: d = "on",
      onCheckedChange: m,
      ...S
    } = e, [s, f] = n.useState(null), R = T(a, (h) => f(h)), b = n.useRef(!1), k = s ? !!s.closest("form") : !0, [l = !1, E] = B({
      prop: r,
      defaultProp: u,
      onChange: m
    });
    return /* @__PURE__ */ p.jsxs(N, { scope: t, checked: l, disabled: c, children: [
      /* @__PURE__ */ p.jsx(
        w.button,
        {
          type: "button",
          role: "switch",
          "aria-checked": l,
          "aria-required": i,
          "data-state": y(l),
          "data-disabled": c ? "" : void 0,
          disabled: c,
          value: d,
          ...S,
          ref: R,
          onClick: j(e.onClick, (h) => {
            E((g) => !g), k && (b.current = h.isPropagationStopped(), b.current || h.stopPropagation());
          })
        }
      ),
      k && /* @__PURE__ */ p.jsx(
        z,
        {
          control: s,
          bubbles: !b.current,
          name: o,
          value: d,
          checked: l,
          required: i,
          disabled: c,
          style: { transform: "translateX(-100%)" }
        }
      )
    ] });
  }
);
C.displayName = v;
var x = "SwitchThumb", P = n.forwardRef(
  (e, a) => {
    const { __scopeSwitch: t, ...o } = e, r = q(x, t);
    return /* @__PURE__ */ p.jsx(
      w.span,
      {
        "data-state": y(r.checked),
        "data-disabled": r.disabled ? "" : void 0,
        ...o,
        ref: a
      }
    );
  }
);
P.displayName = x;
var z = (e) => {
  const { control: a, checked: t, bubbles: o = !0, ...r } = e, u = n.useRef(null), i = H(t), c = I(a);
  return n.useEffect(() => {
    const d = u.current, m = window.HTMLInputElement.prototype, s = Object.getOwnPropertyDescriptor(m, "checked").set;
    if (i !== t && s) {
      const f = new Event("click", { bubbles: o });
      s.call(d, t), d.dispatchEvent(f);
    }
  }, [i, t, o]), /* @__PURE__ */ p.jsx(
    "input",
    {
      type: "checkbox",
      "aria-hidden": !0,
      defaultChecked: t,
      ...r,
      tabIndex: -1,
      ref: u,
      style: {
        ...e.style,
        ...c,
        position: "absolute",
        pointerEvents: "none",
        opacity: 0,
        margin: 0
      }
    }
  );
};
function y(e) {
  return e ? "checked" : "unchecked";
}
var J = C, K = P;
export {
  J as Root,
  C as Switch,
  P as SwitchThumb,
  K as Thumb,
  G as createSwitchScope
};
//# sourceMappingURL=index.js.map
