"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_redux_1 = require("react-redux");
const react_core_1 = require("@patternfly/react-core");
const formik_1 = require("formik");
const common_1 = require("../../../common");
const HostsDiscoveryTable_1 = tslib_1.__importDefault(require("../hosts/HostsDiscoveryTable"));
const DiscoveryImageModal_1 = require("./DiscoveryImageModal");
const InformationAndAlerts_1 = tslib_1.__importDefault(require("./InformationAndAlerts"));
const OcmFormFields_1 = require("../ui/OcmFormFields");
const selectors_1 = require("../../store/slices/current-cluster/selectors");
const use_feature_1 = require("../../hooks/use-feature");
const schedulableMastersTooltip = 'Workloads must be run on control plane nodes when less than 5 hosts are discovered';
const HostInventory = ({ cluster }) => {
    const isSingleClusterFeatureEnabled = (0, use_feature_1.useFeature)('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');
    const mastersMustRunWorkloads = (0, common_1.selectMastersMustRunWorkloads)(cluster);
    const { setFieldValue } = (0, formik_1.useFormikContext)();
    const { isViewerMode } = (0, react_redux_1.useSelector)(selectors_1.selectCurrentClusterPermissionsState);
    react_1.default.useEffect(() => {
        setFieldValue('schedulableMasters', (0, common_1.selectSchedulableMasters)(cluster));
    }, [cluster, mastersMustRunWorkloads, setFieldValue]); // Schedulable masters need to be recalculated only when forced status changes
    return (react_1.default.createElement(react_core_1.Stack, { hasGutter: true, "data-testid": "host-inventory" },
        react_1.default.createElement(react_core_1.StackItem, { "data-testid": "host-discovery-header" },
            react_1.default.createElement(common_1.ClusterWizardStepHeader, null, "Host discovery")),
        react_1.default.createElement(react_core_1.StackItem, { "data-testid": "discovery-image-modal-section" }, !isViewerMode && !isSingleClusterFeatureEnabled && (react_1.default.createElement(react_core_1.Content, { component: "p" },
            react_1.default.createElement(DiscoveryImageModal_1.DiscoveryImageModalButton, { ButtonComponent: react_core_1.Button, cluster: cluster, idPrefix: "host-inventory" })))),
        react_1.default.createElement(react_core_1.StackItem, { "data-testid": "schedulable-masters-section" },
            react_1.default.createElement(react_core_1.Split, null,
                react_1.default.createElement(react_core_1.SplitItem, null,
                    react_1.default.createElement(OcmFormFields_1.OcmSwitchField, { tooltipProps: {
                            hidden: !mastersMustRunWorkloads,
                            content: schedulableMastersTooltip,
                        }, isDisabled: mastersMustRunWorkloads, name: 'schedulableMasters', label: "Run workloads on control plane nodes\u00A0", "data-testid": "schedulable-masters-switch" })),
                react_1.default.createElement(react_core_1.SplitItem, null,
                    react_1.default.createElement(common_1.PopoverIcon, { bodyContent: react_1.default.createElement("p", null, "Enables your control plane nodes to be used for running applications."), buttonStyle: { marginTop: '4px' }, "data-testid": "schedulable-masters-popover" })))),
        react_1.default.createElement(react_core_1.StackItem, { "data-testid": "information-and-alerts" },
            react_1.default.createElement(InformationAndAlerts_1.default, { cluster: cluster })),
        react_1.default.createElement(react_core_1.StackItem, { "data-testid": "host-inventory-title" },
            react_1.default.createElement(react_core_1.Content, { component: "h3" }, "Host Inventory")),
        react_1.default.createElement(react_core_1.StackItem, { "data-testid": "hosts-discovery-table-wrapper" },
            react_1.default.createElement(HostsDiscoveryTable_1.default, { cluster: cluster, hosts: cluster.hosts || [] }))));
};
exports.default = HostInventory;
//# sourceMappingURL=HostInventory.js.map