"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 = require("@patternfly/react-icons/dist/js/icons/exclamation-circle-icon");
const TextAreaField = (_a) => {
    var { label, helperText, getErrorText, isRequired, children, idPostfix, labelIcon, groupClassName } = _a, props = tslib_1.__rest(_a, ["label", "helperText", "getErrorText", "isRequired", "children", "idPostfix", "labelIcon", "groupClassName"]);
    const [field, { touched, error }] = (0, formik_1.useField)(props.name);
    const fieldId = (0, utils_1.getFieldId)(props.name, 'input', idPostfix);
    const isValid = !(touched && error);
    const getErrorMessage = () => {
        if (!isValid && error) {
            return getErrorText ? getErrorText(error) : error;
        }
        return '';
    };
    const errorMessage = getErrorMessage();
    const { isDisabled } = props, restProps = tslib_1.__rest(props, ["isDisabled"]);
    return (React.createElement(react_core_1.FormGroup, { fieldId: fieldId, label: label, isRequired: isRequired, labelHelp: labelIcon, className: groupClassName, id: `form-control__${fieldId}` },
        children,
        React.createElement(react_core_1.TextArea, Object.assign({}, field, restProps, { id: fieldId, style: { resize: 'vertical' }, validated: isValid ? 'default' : 'error', isRequired: isRequired, "aria-describedby": `${fieldId}-helper`, onChange: (event) => {
                var _a;
                field.onChange(event);
                (_a = restProps.onChange) === null || _a === void 0 ? void 0 : _a.call(restProps, event);
            }, disabled: isDisabled })),
        (errorMessage || helperText) && (React.createElement(react_core_1.FormHelperText, null,
            React.createElement(react_core_1.HelperText, null,
                React.createElement(react_core_1.HelperTextItem, { variant: 'default', id: `${fieldId}-helper`, "data-testid": `input-textarea-${fieldId}-helper-text` }, helperText),
                errorMessage && (React.createElement(react_core_1.HelperTextItem, { icon: React.createElement(exclamation_circle_icon_1.ExclamationCircleIcon, null), variant: 'error', id: `${fieldId}-helper-error`, "data-testid": `input-textarea-${fieldId}-helper-text-error` }, errorMessage)))))));
};
exports.default = TextAreaField;
//# sourceMappingURL=TextAreaField.js.map