'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var primitives_Field = require('./primitives/Field.js');
var primitives_Switch = require('./primitives/Switch.js');
var utils = require('./utils-BhM0B89p.js');

const Switch = React.forwardRef(
  ({
    label,
    error,
    helpText,
    required = false,
    className,
    size = "default",
    disabled,
    id: idProp,
    labelProps,
    ...otherProps
  }, ref) => {
    const generatedId = React.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__ */ jsxRuntime.jsxs(
      "div",
      {
        className: utils.cn("inline-flex flex-col gap-1.5", className),
        "data-disabled": disabled || void 0,
        "data-invalid": !!error || void 0,
        children: [
          /* @__PURE__ */ jsxRuntime.jsxs(
            "div",
            {
              className: utils.cn(
                "inline-flex gap-2",
                helpText ? "items-start" : "items-center"
              ),
              children: [
                /* @__PURE__ */ jsxRuntime.jsx(
                  primitives_Switch.Switch,
                  {
                    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__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-0.5", children: [
                  label && /* @__PURE__ */ jsxRuntime.jsxs(
                    primitives_Field.FieldLabel,
                    {
                      htmlFor: id,
                      ...labelProps,
                      className: utils.cn(
                        "cursor-pointer",
                        disabled && "cursor-not-allowed opacity-50",
                        labelProps?.className
                      ),
                      children: [
                        label,
                        required && /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" })
                      ]
                    }
                  ),
                  helpText && /* @__PURE__ */ jsxRuntime.jsx("p", { id: helpTextId, className: "text-sm text-muted-foreground", children: helpText })
                ] })
              ]
            }
          ),
          error && /* @__PURE__ */ jsxRuntime.jsx("p", { id: errorId, role: "alert", className: "text-xs text-destructive", children: error })
        ]
      }
    );
  }
);
Switch.displayName = "Switch";

exports.Switch = Switch;
//# sourceMappingURL=Switch-bY6bZw78.js.map
