import React, { forwardRef } from "react";
import { BodyShort } from "../../typography/index.js";
import { omit, useId } from "../../utils-external/index.js";
import { cl } from "../../utils/helpers/index.js";
import { ReadOnlyIconWithTitle } from "../ReadOnlyIcon.js";
import { CheckboxInput } from "./checkbox-input/CheckboxInput.js";
import useCheckbox from "./useCheckbox.js";
export const Checkbox = forwardRef((props, forwardedRef) => {
    const { inputProps, hasError, size, readOnly, nested } = useCheckbox(props);
    const descriptionId = useId();
    const { className, description, children, indeterminate, hideLabel } = props;
    return (React.createElement("div", { className: cl(className, "aksel-checkbox", `aksel-checkbox--${size}`, {
            "aksel-checkbox--error": hasError,
            "aksel-checkbox--disabled": inputProps.disabled,
            "aksel-checkbox--readonly": readOnly,
        }), "data-color": hasError ? "danger" : props["data-color"] },
        React.createElement(CheckboxInput, Object.assign({ ref: forwardedRef }, omit(props, [
            "children",
            "size",
            "error",
            "description",
            "hideLabel",
            "indeterminate",
            "errorId",
            "readOnly",
            "className",
        ]), omit(inputProps, ["aria-invalid", "aria-describedby"]), { "aria-describedby": cl(inputProps["aria-describedby"], {
                [descriptionId]: description,
            }) || undefined, indeterminate: indeterminate !== null && indeterminate !== void 0 ? indeterminate : false, standalone: false })),
        React.createElement(BodyShort, { as: "label", htmlFor: inputProps.id, size: size, className: "aksel-checkbox__label", visuallyHidden: hideLabel },
            !nested && readOnly && React.createElement(ReadOnlyIconWithTitle, null),
            children),
        description && (React.createElement(BodyShort, { id: descriptionId, size: size, className: "aksel-form-field__subdescription aksel-checkbox__description", visuallyHidden: hideLabel }, description))));
});
export default Checkbox;
//# sourceMappingURL=Checkbox.js.map