"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HostsNetworkConfigurationControlGroup = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const ui_1 = require("../../../common/components/ui");
const types_1 = require("../../services/types");
const formik_1 = require("formik");
const ClusterWizardContext_1 = require("../clusterWizard/ClusterWizardContext");
const RadioFieldWithTooltip_1 = tslib_1.__importDefault(require("../../../common/components/ui/formik/RadioFieldWithTooltip"));
const featureStateUtils_1 = require("../featureSupportLevels/featureStateUtils");
const HostsNetworkConfigurationControlGroup = ({ clusterExists, isDisabled = false, }) => {
    const GROUP_NAME = 'hostsNetworkConfigurationType';
    const clusterWizardContext = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const [{ value }] = (0, formik_1.useField)(GROUP_NAME);
    const fieldId = (0, ui_1.getFieldId)(GROUP_NAME, 'radio');
    const tooltipProps = {
        hidden: !clusterExists && !isDisabled,
        content: !isDisabled ? featureStateUtils_1.clusterExistsReason : featureStateUtils_1.hostsNetworkConfigurationDisabledReason,
        position: 'top',
    };
    react_1.default.useEffect(() => {
        if (clusterExists) {
            return;
        }
        clusterWizardContext.onUpdateHostNetworkConfigType(value);
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [value, clusterExists]);
    return (react_1.default.createElement(react_core_1.FormGroup, { id: `form-control__${fieldId}`, label: "Hosts' network configuration", fieldId: fieldId, isInline: true, role: "radiogroup", "data-testid": "hosts-network-configuration-control-group" },
        react_1.default.createElement(RadioFieldWithTooltip_1.default, { name: GROUP_NAME, isDisabled: clusterExists || isDisabled, value: types_1.HostsNetworkConfigurationType.DHCP, label: "DHCP only", tooltipProps: tooltipProps, className: "pf-v6-u-mr-md" }),
        react_1.default.createElement(RadioFieldWithTooltip_1.default, { name: GROUP_NAME, isDisabled: clusterExists || isDisabled, value: types_1.HostsNetworkConfigurationType.STATIC, label: "Static IP, bridges, and bonds", tooltipProps: tooltipProps })));
};
exports.HostsNetworkConfigurationControlGroup = HostsNetworkConfigurationControlGroup;
//# sourceMappingURL=HostsNetworkConfigurationControlGroup.js.map