"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_router_dom_v5_compat_1 = require("react-router-dom-v5-compat");
const react_core_1 = require("@patternfly/react-core");
const common_1 = require("../../../common");
const ClusterToolbar_1 = tslib_1.__importDefault(require("../clusters/ClusterToolbar"));
const utils_1 = require("./utils");
const config_1 = require("../../config");
const ClusterDetailStatusVarieties_1 = tslib_1.__importStar(require("./ClusterDetailStatusVarieties"));
const ClusterProgress_1 = tslib_1.__importDefault(require("../../../common/components/clusterDetail/ClusterProgress"));
const fetchEvents_1 = require("../fetching/fetchEvents");
const getProgressBarAlerts_1 = require("./getProgressBarAlerts");
const apis_1 = require("../../services/apis");
const slice_1 = require("../../store/slices/current-cluster/slice");
const api_1 = require("../../../common/api");
const newFeatureSupportLevels_1 = require("../../../common/components/newFeatureSupportLevels");
const OcmClusterProgressItems_1 = tslib_1.__importDefault(require("../clusterConfiguration/OcmClusterProgressItems"));
const ClusterDetailsButtonGroup_1 = tslib_1.__importDefault(require("./ClusterDetailsButtonGroup"));
const ClusterSummaryExpandable_1 = tslib_1.__importDefault(require("./ClusterSummaryExpandable"));
const HostInventoryExpandable_1 = tslib_1.__importDefault(require("./HostInventoryExpandable"));
const use_feature_1 = require("../../hooks/use-feature");
const ClusterDetail = ({ cluster }) => {
    var _a;
    const clusterVarieties = (0, ClusterDetailStatusVarieties_1.useClusterStatusVarieties)(cluster);
    const featureSupportLevelContext = (0, newFeatureSupportLevels_1.useNewFeatureSupportLevel)();
    const isSNOExpansionAllowed = featureSupportLevelContext.isFeatureSupported('SINGLE_NODE_EXPANSION');
    const isSingleClusterFeatureEnabled = (0, use_feature_1.useFeature)('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');
    const navigate = (0, react_router_dom_v5_compat_1.useNavigate)();
    const canAddHosts = (!(0, common_1.isSNO)(cluster) || isSNOExpansionAllowed) && cluster.status === 'installed' && !api_1.isInOcm;
    const onAddHosts = react_1.default.useCallback(() => {
        const doItAsync = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
            try {
                const { data } = yield apis_1.ClustersAPI.allowAddHosts(cluster.id);
                (0, slice_1.updateCluster)(data);
                navigate(`${config_1.routeBasePath}/clusters/${cluster.id}`);
            }
            catch (e) {
                (0, api_1.handleApiError)(e);
            }
        });
        void doItAsync();
    }, [cluster.id, navigate]);
    return (react_1.default.createElement(react_core_1.Stack, { hasGutter: true },
        react_1.default.createElement(react_core_1.StackItem, null,
            react_1.default.createElement(react_core_1.Grid, { hasGutter: true },
                react_1.default.createElement(react_core_1.GridItem, null,
                    react_1.default.createElement(react_core_1.Content, { component: "h2" }, "Installation progress")),
                react_1.default.createElement(react_core_1.GridItem, { span: 6 },
                    react_1.default.createElement(ClusterProgress_1.default, { cluster: cluster, totalPercentage: ((_a = cluster.progress) === null || _a === void 0 ? void 0 : _a.totalPercentage) || 0 })),
                react_1.default.createElement(react_core_1.GridItem, { span: 6, rowSpan: 4 }),
                react_1.default.createElement(react_core_1.GridItem, { span: 6 },
                    react_1.default.createElement(OcmClusterProgressItems_1.default, { cluster: cluster, onFetchEvents: fetchEvents_1.onFetchEvents })),
                react_1.default.createElement(react_core_1.GridItem, { span: 6 }, (0, getProgressBarAlerts_1.getClusterProgressAlerts)((0, common_1.getEnabledHosts)(cluster.hosts), cluster, (0, common_1.selectOlmOperators)(cluster))),
                react_1.default.createElement(react_core_1.GridItem, { span: 6 },
                    react_1.default.createElement(ClusterDetailsButtonGroup_1.default, { cluster: cluster, credentials: clusterVarieties.credentials, credentialsError: clusterVarieties.credentialsError }),
                    react_1.default.createElement(ClusterDetailStatusVarieties_1.default, { cluster: cluster, clusterVarieties: clusterVarieties })),
                react_1.default.createElement(HostInventoryExpandable_1.default, { cluster: cluster }),
                react_1.default.createElement(ClusterSummaryExpandable_1.default, { cluster: cluster }))),
        react_1.default.createElement(react_core_1.StackItem, null,
            react_1.default.createElement(common_1.Alerts, null)),
        react_1.default.createElement(react_core_1.StackItem, null,
            react_1.default.createElement(ClusterToolbar_1.default, null,
                canAddHosts && (react_1.default.createElement(common_1.ToolbarButton, { variant: react_core_1.ButtonVariant.primary, id: (0, utils_1.getClusterDetailId)('button-add-hosts'), onClick: onAddHosts }, "Add hosts")),
                !isSingleClusterFeatureEnabled && (react_1.default.createElement(common_1.ToolbarButton, { variant: react_core_1.ButtonVariant.link, onClick: () => navigate('..'), id: (0, utils_1.getClusterDetailId)('button-back-to-all-clusters') }, "Back to all clusters"))))));
};
exports.default = ClusterDetail;
//# sourceMappingURL=ClusterDetail.js.map