"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClusterInstallationTimeout = exports.HostsInstallationSuccess = exports.HostsInstallationFailed = exports.HostInstallationWarning = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const humanize_plus_1 = require("humanize-plus");
const common_1 = require("../../../common");
const utils_1 = require("./utils");
const ModalDialogsContext_1 = require("../hosts/ModalDialogsContext");
const api_1 = require("../../../common/api");
const operatorSpecs_1 = require("../../../common/components/operators/operatorSpecs");
const getFailedHostsMessage = (failedHosts, totalHosts, message, hostsType) => {
    if (hostsType === 'worker') {
        if (api_1.isInOcm) {
            return (react_1.default.createElement(react_1.default.Fragment, null,
                "Error information for each host can be found in the host inventory table. To retry adding failed hosts, navigate to the clusters list inside OpenShift Cluster Manager, click your cluster name, and select the ",
                react_1.default.createElement("b", null, "Add hosts"),
                " tab."));
        }
        return (react_1.default.createElement(react_1.default.Fragment, null,
            "Error information for each host can be found in the host inventory table. To retry adding failed hosts, press the ",
            react_1.default.createElement("b", null, "Add hosts"),
            " button."));
    }
    return (react_1.default.createElement(react_1.default.Fragment, null,
        failedHosts,
        "/",
        totalHosts,
        " ",
        (0, humanize_plus_1.pluralize)(totalHosts, hostsType),
        " ",
        message,
        " Due to this, the cluster will be degraded. Please check the installation log for more information."));
};
const HostInstallationWarning = ({ cluster, failedHosts, totalHosts, title, hostsType, failedOperators = [], message, }) => {
    const { addAlert, clearAlerts } = (0, common_1.useAlerts)();
    const { byKey: opSpecs } = (0, operatorSpecs_1.useOperatorSpecs)();
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Alert, { isInline: true, variant: "warning", title: title, actionLinks: react_1.default.createElement(react_1.default.Fragment, null,
                react_1.default.createElement(react_core_1.AlertActionLink, { id: "cluster-installation-logs-button", onClick: () => {
                        void (0, utils_1.downloadClusterInstallationLogs)(addAlert, cluster.id, clearAlerts);
                    }, isDisabled: !(0, common_1.canDownloadClusterLogs)(cluster) }, "Download installation logs")) },
            react_1.default.createElement(common_1.RenderIf, { condition: failedHosts !== 0 },
                react_1.default.createElement("p", null, getFailedHostsMessage(failedHosts, totalHosts, message, hostsType))),
            react_1.default.createElement(common_1.RenderIf, { condition: (failedOperators === null || failedOperators === void 0 ? void 0 : failedOperators.length) > 0 },
                react_1.default.createElement("p", null,
                    failedOperators.map(({ name }) => { var _a; return ((_a = opSpecs[name || '']) === null || _a === void 0 ? void 0 : _a.title) || name; }).join(' and '),
                    ' ',
                    "failed to install. Due to this, the cluster will be degraded, but you can try to install the operator from the Operator Hub. Please check the installation log for more information.")))));
};
exports.HostInstallationWarning = HostInstallationWarning;
const HostsInstallationFailed = ({ cluster, failedHosts, totalHosts, isCriticalNumberOfWorkersFailed, }) => {
    const { addAlert, clearAlerts } = (0, common_1.useAlerts)();
    const { resetClusterDialog } = (0, ModalDialogsContext_1.useModalDialogsContext)();
    const getID = (suffix) => `cluster-install-error-${suffix}`;
    let title, message;
    if (cluster.controlPlaneCount === 1 || failedHosts > 0) {
        title = 'Control plane was not installed';
        message = `${failedHosts}/${totalHosts} control plane nodes failed to install. Please check the installation logs for more information.`;
    }
    else if (isCriticalNumberOfWorkersFailed) {
        title = 'Critical number of workers were not installed';
        message =
            'Only one worker was able to be installed. Please check the installation logs for more information.';
    }
    else {
        title = 'Initialization failed';
        message = (react_1.default.createElement(react_core_1.Content, { component: "p" },
            (0, common_1.toSentence)(cluster.statusInfo),
            react_1.default.createElement("br", null),
            "Reset the installation process to return to the configuration and try again. Some hosts may need to be re-registered by rebooting into the Discovery ISO."));
    }
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Alert, { isInline: true, variant: "danger", title: title, actionLinks: react_1.default.createElement(react_1.default.Fragment, null,
                react_1.default.createElement(react_core_1.AlertActionLink, { id: "button-reset-cluster", onClick: () => resetClusterDialog.open({ cluster }) }, "Reset Cluster"),
                react_1.default.createElement(react_core_1.AlertActionLink, { id: "cluster-installation-logs-button", onClick: () => {
                        void (0, utils_1.downloadClusterInstallationLogs)(addAlert, cluster.id, clearAlerts);
                    }, isDisabled: !(0, common_1.canDownloadClusterLogs)(cluster) }, "Download installation logs"),
                react_1.default.createElement(react_core_1.AlertActionLink, { onClick: () => window.open((0, common_1.getReportIssueLink)(), '_blank'), id: getID('button-report-bug') }, "Report a bug")) }, message)));
};
exports.HostsInstallationFailed = HostsInstallationFailed;
const HostsInstallationSuccess = () => {
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Alert, { isInline: true, variant: "success", title: 'Installation completed successfully' }, ' ')));
};
exports.HostsInstallationSuccess = HostsInstallationSuccess;
const ClusterInstallationTimeout = ({ cluster }) => {
    const { addAlert, clearAlerts } = (0, common_1.useAlerts)();
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Alert, { isInline: true, variant: "warning", title: "Cluster installation is taking too long", actionLinks: react_1.default.createElement(react_1.default.Fragment, null,
                react_1.default.createElement(react_core_1.AlertActionLink, { id: "cluster-installation-logs-button", onClick: () => {
                        void (0, utils_1.downloadClusterInstallationLogs)(addAlert, cluster.id, clearAlerts);
                    }, isDisabled: !(0, common_1.canDownloadClusterLogs)(cluster) }, "Download installation logs")) }, "Check the logs to find out why or reset the cluster to start over.")));
};
exports.ClusterInstallationTimeout = ClusterInstallationTimeout;
//# sourceMappingURL=ProgressBarAlerts.js.map