"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OcmRadio = exports.OcmRadioField = exports.OcmSwitchField = exports.OcmCodeField = exports.OcmCheckboxField = exports.OcmCheckbox = exports.OcmRichInputField = exports.OcmInputField = void 0;
exports.RefFormFieldDisabler = RefFormFieldDisabler;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_redux_1 = require("react-redux");
const react_core_1 = require("@patternfly/react-core");
const selectors_1 = require("../../store/slices/current-cluster/selectors");
const common_1 = require("../../../common");
function FormFieldDisabler(FormComponent) {
    return function WrapperHoc(props) {
        const { isViewerMode } = (0, react_redux_1.useSelector)(selectors_1.selectCurrentClusterPermissionsState);
        const isDisabled = props.isDisabled || isViewerMode;
        return React.createElement(FormComponent, Object.assign({}, props, { isDisabled: isDisabled }));
    };
}
function RefFormFieldDisabler(FormComponent) {
    return React.forwardRef(function useInputRef(props, ref) {
        const { isViewerMode } = (0, react_redux_1.useSelector)(selectors_1.selectCurrentClusterPermissionsState);
        const isDisabled = props.isDisabled || isViewerMode;
        return React.createElement(FormComponent, Object.assign({ ref: ref }, props, { isDisabled: isDisabled }));
    });
}
// Formik Fields
const OcmInputField = FormFieldDisabler(common_1.InputField);
exports.OcmInputField = OcmInputField;
const OcmCheckboxField = FormFieldDisabler(common_1.CheckboxField);
exports.OcmCheckboxField = OcmCheckboxField;
const OcmSwitchField = FormFieldDisabler(common_1.SwitchField);
exports.OcmSwitchField = OcmSwitchField;
const OcmRadioField = FormFieldDisabler(common_1.RadioField);
exports.OcmRadioField = OcmRadioField;
const OcmCodeField = FormFieldDisabler(common_1.CodeField);
exports.OcmCodeField = OcmCodeField;
// Patternfly components
const OcmCheckbox = FormFieldDisabler(react_core_1.Checkbox);
exports.OcmCheckbox = OcmCheckbox;
const OcmRadio = FormFieldDisabler(react_core_1.Radio);
exports.OcmRadio = OcmRadio;
// With forwardRef
const OcmRichInputField = RefFormFieldDisabler(common_1.RichInputField);
exports.OcmRichInputField = OcmRichInputField;
//# sourceMappingURL=OcmFormFields.js.map