"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_core_1 = require("@patternfly/react-core");
const common_1 = require("../../../common");
const utils_1 = require("../clusters/utils");
const OdfLvmDisksManualFormattingHint_1 = tslib_1.__importDefault(require("./OdfLvmDisksManualFormattingHint"));
const DisksTable_1 = require("../../../common/components/storage/DisksTable");
const StorageAlerts = ({ cluster }) => {
    var _a, _b;
    const showFormattingHint = ((0, common_1.hasEnabledOperators)(cluster.monitoredOperators, common_1.OPERATOR_NAME_ODF) ||
        (0, common_1.hasEnabledOperators)(cluster.monitoredOperators, common_1.OPERATOR_NAME_LVM)) &&
        !(0, utils_1.isAddHostsCluster)(cluster);
    const someDisksAreSkipFormatting = (0, utils_1.isSomeDisksSkipFormatting)(cluster);
    const diskLimitations = (_b = (_a = [...cluster.hosts]) === null || _a === void 0 ? void 0 : _a.sort((a, b) => (a.requestedHostname && a.requestedHostname.localeCompare(b.requestedHostname)) ||
        0)) === null || _b === void 0 ? void 0 : _b.map((host) => {
        const disks = (0, common_1.getInventory)(host).disks || [];
        const installationDisk = disks.find((disk) => disk.id === host.installationDiskId);
        if (installationDisk) {
            const holder = disks.find((d) => { var _a; return (_a = installationDisk.holders) === null || _a === void 0 ? void 0 : _a.split(',').includes(d.name); });
            if (holder) {
                return (0, DisksTable_1.getDiskLimitation)(installationDisk.name, host.requestedHostname, holder);
            }
        }
    }).filter(Boolean);
    return (React.createElement(react_core_1.Stack, { hasGutter: true },
        !!diskLimitations.length && (React.createElement(react_core_1.StackItem, null, (diskLimitations === null || diskLimitations === void 0 ? void 0 : diskLimitations.length) === 1 ? (React.createElement(react_core_1.Alert, { title: diskLimitations[0], isInline: true, variant: react_core_1.AlertVariant.warning, "data-testid": "diskLimitationsAlert" })) : (React.createElement(react_core_1.Alert, { title: "Installation disk limitations", isInline: true, variant: react_core_1.AlertVariant.warning, "data-testid": "diskLimitationsAlert" },
            React.createElement(react_core_1.List, null, diskLimitations.map((warning, index) => (React.createElement(react_core_1.ListItem, { key: `installationWarning-${index}` }, warning)))))))),
        showFormattingHint && (React.createElement(react_core_1.StackItem, null,
            React.createElement(OdfLvmDisksManualFormattingHint_1.default, null))),
        React.createElement(react_core_1.StackItem, null,
            React.createElement(common_1.FormatDiskWarning, { someDisksAreSkipFormatting: someDisksAreSkipFormatting }))));
};
exports.default = StorageAlerts;
//# sourceMappingURL=StorageAlerts.js.map