import { jsx, jsxs } from 'react/jsx-runtime';
import { forwardRef, useId } from 'react';
import { c as cn } from './utils-DdHUxIdC.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(" ") || undefined;
    const hasField = !!(label || error || helpText);
    if (!hasField) {
        return (jsx(Checkbox$1, { ref: ref, id: id, disabled: disabled, "aria-invalid": !!error || undefined, "aria-required": required || undefined, "aria-describedby": ariaDescribedBy, className: className, ...otherProps }));
    }
    return (jsxs("div", { className: cn("flex flex-col gap-1", className), "data-disabled": disabled || undefined, "data-invalid": !!error || undefined, children: [jsxs(Field, { orientation: "horizontal", children: [jsx(Checkbox$1, { ref: ref, id: id, disabled: disabled, "aria-invalid": !!error || undefined, "aria-required": required || undefined, "aria-describedby": ariaDescribedBy, ...otherProps }), jsxs(FieldContent, { children: [label && (jsxs(FieldLabel, { htmlFor: id, children: [label, required && (jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" }))] })), helpText && (jsx(FieldDescription, { id: helpTextId, children: helpText }))] })] }), error && jsx(FieldError, { id: errorId, children: error })] }));
});
Checkbox.displayName = "Checkbox";

export { Checkbox as C };
//# sourceMappingURL=Checkbox-zCxgcZiC.js.map
