import { jsxs, jsx } from 'react/jsx-runtime';
import { forwardRef, useId } from 'react';
import { Switch as Switch$1 } from './primitives/Switch.js';
import { Label } from './primitives/Label.js';
import { c as cn } from './utils-BJnb9o5c.js';

const Switch = forwardRef(
  ({
    label,
    error,
    helpText,
    required = false,
    className,
    size = "default",
    disabled,
    id: idProp,
    ...otherProps
  }, ref) => {
    const generatedId = useId();
    const id = idProp ?? generatedId;
    const errorId = `error_${id}`;
    const helpTextId = `helpText_${id}`;
    const ariaDescribedBy = [error ? errorId : null, helpText ? helpTextId : null].filter(Boolean).join(" ") || void 0;
    return /* @__PURE__ */ jsxs(
      "div",
      {
        className: cn("inline-flex flex-col gap-1.5", className),
        "data-disabled": disabled || void 0,
        "data-invalid": !!error || void 0,
        children: [
          /* @__PURE__ */ jsxs(
            "div",
            {
              className: cn(
                "inline-flex gap-2",
                helpText ? "items-start" : "items-center"
              ),
              children: [
                /* @__PURE__ */ jsx(
                  Switch$1,
                  {
                    ref,
                    id,
                    size,
                    disabled,
                    "aria-invalid": !!error || void 0,
                    "aria-describedby": ariaDescribedBy,
                    "aria-required": required || void 0,
                    className: helpText ? "mt-0.5" : void 0,
                    ...otherProps
                  }
                ),
                (label || helpText) && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
                  label && /* @__PURE__ */ jsxs(
                    Label,
                    {
                      htmlFor: id,
                      className: cn(
                        "cursor-pointer",
                        disabled && "cursor-not-allowed opacity-50"
                      ),
                      children: [
                        label,
                        required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" })
                      ]
                    }
                  ),
                  helpText && /* @__PURE__ */ jsx("p", { id: helpTextId, className: "text-sm text-muted-foreground", children: helpText })
                ] })
              ]
            }
          ),
          error && /* @__PURE__ */ jsx("p", { id: errorId, role: "alert", className: "text-xs text-destructive", children: error })
        ]
      }
    );
  }
);
Switch.displayName = "Switch";

export { Switch as S };
//# sourceMappingURL=Switch-OAB7pfNn.js.map
