"use client";
import { jsx as o, jsxs as R } from "react/jsx-runtime";
import { forwardRef as _, createContext as B, useContext as D } from "react";
import { c as u } from "./cn-ct4n7r74mh8y0f48.js";
import { F as G } from "./field-ftrgblg9mbmz9eo3.js";
import { P as K, Q as O, b2 as F, b3 as I } from "./vendor-base-ui-kxxocm122zr4pipe.js";
const y = {
  size: {
    sm: {
      classes: "h-5.5 w-8.5",
      description: "Small switch for compact UIs"
    },
    base: {
      classes: "h-6.5 w-10.5",
      description: "Default switch size"
    },
    lg: {
      classes: "h-7.5 w-12.5",
      description: "Large switch for prominent toggles"
    }
  },
  variant: {
    default: {
      classes: "",
      description: "Default switch appearance"
    },
    error: {
      classes: "ring-kumo-danger",
      description: "Error state for validation failures"
    }
  }
}, C = {
  size: "base",
  variant: "default"
};
function P({
  size: a = C.size,
  variant: l = C.variant
} = {}) {
  return u(
    y.size[a].classes,
    y.variant[l].classes
  );
}
const A = B({
  controlFirst: !0
}), T = _(
  ({
    className: a,
    checked: l,
    disabled: e,
    size: d = "base",
    variant: r = "default",
    label: t,
    labelTooltip: h,
    required: n,
    controlFirst: f = !0,
    onCheckedChange: k,
    transitioning: i,
    ...c
  }, w) => {
    const b = typeof t == "string" ? t : "Switch", m = /* @__PURE__ */ o(
      F,
      {
        ref: w,
        checked: l,
        disabled: e,
        onCheckedChange: k,
        nativeButton: !0,
        render: (N, s) => {
          const {
            ref: g,
            className: x,
            role: p,
            "aria-checked": v,
            "aria-pressed": E,
            ...j
          } = N, L = u(
            "interactive flex items-center gap-2 rounded-full border border-transparent bg-kumo-recessed p-1 transition-colors",
            P({ size: d, variant: r }),
            {
              "bg-kumo-brand": s.checked && !e && r !== "error",
              "bg-kumo-danger": s.checked && !e && r === "error",
              "hover:bg-kumo-brand-hover": s.checked && !i && !e && r !== "error",
              "hover:bg-kumo-danger/90": s.checked && !i && !e && r === "error",
              "hover:bg-kumo-interact": !s.checked && !i && !e,
              "cursor-not-allowed opacity-50": e
            },
            i ? "cursor-wait" : e ? "" : "cursor-pointer",
            a,
            x
          ), S = c.role ?? p ?? "switch", U = S === "switch" ? { "aria-checked": s.checked } : { "aria-pressed": s.checked };
          return /* @__PURE__ */ o(
            "button",
            {
              ...j,
              ...c,
              ref: g,
              type: "button",
              role: S,
              ...U,
              "aria-busy": i || void 0,
              "aria-label": c["aria-label"] ?? b,
              className: L,
              children: /* @__PURE__ */ o(
                I,
                {
                  className: u(
                    "pointer-events-none aspect-square h-full rounded-full bg-white transition-all",
                    {
                      "translate-x-full rtl:translate-x-[-100%]": s.checked
                    }
                  )
                }
              )
            }
          );
        }
      }
    );
    return t ? /* @__PURE__ */ o(
      G,
      {
        label: t,
        required: n,
        labelTooltip: h,
        controlFirst: f,
        children: m
      }
    ) : m;
  }
);
T.displayName = "Switch";
const z = _(
  ({
    className: a,
    checked: l,
    disabled: e,
    size: d = "base",
    variant: r = "default",
    label: t,
    onCheckedChange: h,
    transitioning: n
  }, f) => {
    const { controlFirst: k } = D(A);
    return /* @__PURE__ */ R(
      "label",
      {
        className: u(
          "m-0 relative inline-flex items-center gap-2",
          // Control first (default): switch before label
          // Label first: label before switch using flex-row-reverse
          !k && "flex-row-reverse justify-end",
          e ? "cursor-not-allowed opacity-50" : "cursor-pointer",
          a
        ),
        children: [
          /* @__PURE__ */ o(
            F,
            {
              ref: f,
              checked: l,
              disabled: e,
              onCheckedChange: h,
              nativeButton: !0,
              render: (i, c) => {
                const {
                  ref: w,
                  className: b,
                  role: m,
                  "aria-checked": N,
                  "aria-pressed": s,
                  ...g
                } = i, x = u(
                  "interactive flex items-center gap-2 rounded-full border border-transparent bg-kumo-recessed p-1 transition-colors",
                  P({ size: d, variant: r }),
                  {
                    "bg-kumo-brand": c.checked && !e && r !== "error",
                    "bg-kumo-danger": c.checked && !e && r === "error",
                    "hover:bg-kumo-brand-hover": c.checked && !n && !e && r !== "error",
                    "hover:bg-kumo-danger/90": c.checked && !n && !e && r === "error",
                    "hover:bg-kumo-interact": !c.checked && !n && !e,
                    "cursor-not-allowed opacity-50": e
                  },
                  n ? "cursor-wait" : e ? "" : "cursor-pointer",
                  b
                ), p = m ?? "switch", v = p === "switch" ? { "aria-checked": c.checked } : { "aria-pressed": c.checked };
                return /* @__PURE__ */ o(
                  "button",
                  {
                    ...g,
                    ref: w,
                    type: "button",
                    role: p,
                    ...v,
                    "aria-busy": n || void 0,
                    className: x,
                    children: /* @__PURE__ */ o(
                      I,
                      {
                        className: u(
                          "pointer-events-none aspect-square h-full rounded-full bg-white transition-all",
                          {
                            "translate-x-full rtl:translate-x-[-100%]": c.checked
                          }
                        )
                      }
                    )
                  }
                );
              }
            }
          ),
          /* @__PURE__ */ o("span", { className: "text-base font-medium text-kumo-default", children: t })
        ]
      }
    );
  }
);
z.displayName = "Switch.Item";
function V({
  legend: a,
  children: l,
  error: e,
  description: d,
  disabled: r,
  controlFirst: t = !0,
  className: h
}) {
  return /* @__PURE__ */ o(A.Provider, { value: { controlFirst: t }, children: /* @__PURE__ */ R(
    K,
    {
      className: u(
        "flex flex-col gap-4 rounded-lg border border-kumo-line p-4",
        h
      ),
      disabled: r,
      children: [
        /* @__PURE__ */ o(O, { className: "text-lg font-medium text-kumo-default", children: a }),
        /* @__PURE__ */ o("div", { className: "flex flex-col gap-2", children: l }),
        e && /* @__PURE__ */ o("p", { className: "text-sm text-kumo-danger", children: e }),
        d && /* @__PURE__ */ o("p", { className: "text-sm text-kumo-subtle", children: d })
      ]
    }
  ) });
}
const q = Object.assign(T, {
  Item: z,
  Group: V
});
q.displayName = "Switch";
export {
  y as K,
  q as S,
  C as a
};
//# sourceMappingURL=switch-b0xo8fxsfzv87krj.js.map
