'use strict';

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

const Checkbox = React.forwardRef(
  ({
    label,
    error,
    helpText,
    required = false,
    disabled = false,
    className,
    labelProps,
    ...otherProps
  }, ref) => {
    const generatedId = React.useId();
    const id = otherProps.id ?? generatedId;
    const errorId = `error_${id}`;
    const helpTextId = `helpText_${id}`;
    const ariaDescribedBy = [error ? errorId : null, helpText ? helpTextId : null].filter(Boolean).join(" ") || void 0;
    const hasField = !!(label || error || helpText);
    if (!hasField) {
      return /* @__PURE__ */ jsxRuntime.jsx(
        primitives_Checkbox.Checkbox,
        {
          ref,
          id,
          disabled,
          "aria-invalid": !!error || void 0,
          "aria-required": required || void 0,
          "aria-describedby": ariaDescribedBy,
          className,
          ...otherProps
        }
      );
    }
    return /* @__PURE__ */ jsxRuntime.jsxs(
      "div",
      {
        className: utils.cn("flex flex-col gap-1", className),
        "data-disabled": disabled || void 0,
        "data-invalid": !!error || void 0,
        children: [
          /* @__PURE__ */ jsxRuntime.jsxs(primitives_Field.Field, { orientation: "horizontal", children: [
            /* @__PURE__ */ jsxRuntime.jsx(
              primitives_Checkbox.Checkbox,
              {
                ref,
                id,
                disabled,
                "aria-invalid": !!error || void 0,
                "aria-required": required || void 0,
                "aria-describedby": ariaDescribedBy,
                ...otherProps
              }
            ),
            /* @__PURE__ */ jsxRuntime.jsxs(primitives_Field.FieldContent, { children: [
              label && /* @__PURE__ */ jsxRuntime.jsxs(primitives_Field.FieldLabel, { htmlFor: id, ...labelProps, children: [
                label,
                required && /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" })
              ] }),
              helpText && /* @__PURE__ */ jsxRuntime.jsx(primitives_Field.FieldDescription, { id: helpTextId, children: helpText })
            ] })
          ] }),
          error && /* @__PURE__ */ jsxRuntime.jsx(primitives_Field.FieldError, { id: errorId, children: error })
        ]
      }
    );
  }
);
Checkbox.displayName = "Checkbox";

exports.Checkbox = Checkbox;
//# sourceMappingURL=Checkbox-CymHP7QE.js.map
