"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StaticTextField = exports.FormikStaticField = exports.StaticField = void 0;
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 formik_2 = require("./formik");
const exclamation_circle_icon_1 = tslib_1.__importDefault(require("@patternfly/react-icons/dist/js/icons/exclamation-circle-icon"));
const StaticField = ({ label, name, children, helperText, helperTextInvalid, isRequired, isValid = true, }) => {
    const fieldId = (0, formik_2.getFieldId)(name, 'static');
    return (React.createElement(react_core_1.FormGroup, { id: `form-control__${fieldId}`, fieldId: fieldId, label: label, isRequired: isRequired },
        children,
        (helperText || helperTextInvalid) && (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: isValid ? 'default' : 'error', id: isValid ? `${fieldId}-helper` : `${fieldId}-helper-error`, "data-testid": "static-text-field-helper-text" }, isValid ? helperText : helperTextInvalid))))));
};
exports.StaticField = StaticField;
const FormikStaticField = (_a) => {
    var { value } = _a, props = tslib_1.__rest(_a, ["value"]);
    const [, , helpers] = (0, formik_1.useField)({ name: props.name });
    React.useEffect(() => {
        helpers.setValue(value);
    }, [value]); // eslint-disable-line react-hooks/exhaustive-deps
    return React.createElement(exports.StaticField, Object.assign({}, props));
};
exports.FormikStaticField = FormikStaticField;
/**
 * Simplified form component for rendering static text.
 * Does not reflect field value from formik.
 */
const StaticTextField = (_a) => {
    var { children } = _a, props = tslib_1.__rest(_a, ["children"]);
    const fieldId = (0, formik_2.getFieldId)(props.name, 'static');
    return (React.createElement(exports.StaticField, Object.assign({}, props),
        React.createElement(react_core_1.Content, { component: "p", id: fieldId, "aria-describedby": `${fieldId}-helper` }, children)));
};
exports.StaticTextField = StaticTextField;
//# sourceMappingURL=StaticTextField.js.map