"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const formik_1 = require("formik");
const react_core_1 = require("@patternfly/react-core");
const utils_1 = require("./utils");
const exclamation_circle_icon_1 = tslib_1.__importDefault(require("@patternfly/react-icons/dist/js/icons/exclamation-circle-icon"));
const CheckboxField = (_a) => {
    var { label, helperText, onChange, validate, idPostfix } = _a, props = tslib_1.__rest(_a, ["label", "helperText", "onChange", "validate", "idPostfix"]);
    const [field, { touched, error }] = (0, formik_1.useField)({ name: props.name, validate });
    const fieldId = (0, utils_1.getFieldId)(props.name, 'checkbox', idPostfix);
    const isValid = !(touched && error);
    const errorMessage = !isValid ? error : '';
    const fieldHelperText = React.createElement(react_core_1.HelperText, null, helperText);
    return (React.createElement(react_core_1.FormGroup, { fieldId: fieldId, id: `form-control__${fieldId}` },
        React.createElement(react_core_1.Checkbox, Object.assign({}, field, props, { id: fieldId, label: label, "aria-describedby": `${fieldId}-helper`, description: fieldHelperText, isValid: isValid, isChecked: field.value, onChange: (event, value) => {
                field.onChange(event);
                onChange && onChange(value, event);
            } })),
        errorMessage && (React.createElement(react_core_1.FormHelperText, null,
            React.createElement(react_core_1.HelperText, null,
                React.createElement(react_core_1.HelperTextItem, { icon: React.createElement(exclamation_circle_icon_1.default, null), variant: "error", id: `${fieldId}-helper-error`, "data-testid": "checkbox-field-helper-text" }, errorMessage))))));
};
exports.default = CheckboxField;
//# sourceMappingURL=CheckboxField.js.map