import { jsx, jsxs } from 'react/jsx-runtime';
import { forwardRef, useId } from 'react';
import { c as cn } from './utils-BJnb9o5c.js';
import { Checkbox as Checkbox$1 } from './primitives/Checkbox.js';
import { Field, FieldContent, FieldLabel, FieldDescription, FieldError } from './primitives/Field.js';

const Checkbox = forwardRef(
  ({
    label,
    error,
    helpText,
    required = false,
    disabled = false,
    className,
    ...otherProps
  }, ref) => {
    const generatedId = 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__ */ jsx(
        Checkbox$1,
        {
          ref,
          id,
          disabled,
          "aria-invalid": !!error || void 0,
          "aria-required": required || void 0,
          "aria-describedby": ariaDescribedBy,
          className,
          ...otherProps
        }
      );
    }
    return /* @__PURE__ */ jsxs(
      "div",
      {
        className: cn("flex flex-col gap-1", className),
        "data-disabled": disabled || void 0,
        "data-invalid": !!error || void 0,
        children: [
          /* @__PURE__ */ jsxs(Field, { orientation: "horizontal", children: [
            /* @__PURE__ */ jsx(
              Checkbox$1,
              {
                ref,
                id,
                disabled,
                "aria-invalid": !!error || void 0,
                "aria-required": required || void 0,
                "aria-describedby": ariaDescribedBy,
                ...otherProps
              }
            ),
            /* @__PURE__ */ jsxs(FieldContent, { children: [
              label && /* @__PURE__ */ jsxs(FieldLabel, { htmlFor: id, children: [
                label,
                required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" })
              ] }),
              helpText && /* @__PURE__ */ jsx(FieldDescription, { id: helpTextId, children: helpText })
            ] })
          ] }),
          error && /* @__PURE__ */ jsx(FieldError, { id: errorId, children: error })
        ]
      }
    );
  }
);
Checkbox.displayName = "Checkbox";

export { Checkbox as C };
//# sourceMappingURL=Checkbox-C_Rd2-8Z.js.map
