"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 ModalProgress_1 = tslib_1.__importDefault(require("../ui/ModalProgress"));
const utils_1 = require("../../utils");
const use_translation_wrapper_1 = require("../../hooks/use-translation-wrapper");
const MassDeleteHostModal = ({ isOpen, onClose, onDelete, reloadCluster, hosts, children, }) => {
    const [progress, setProgress] = React.useState(null);
    const [error, setError] = React.useState();
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const onClick = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        setError(undefined);
        const i = 0;
        try {
            for (const host of hosts) {
                setProgress((100 * (i + 1)) / hosts.length);
                yield onDelete(host);
            }
            setProgress(null);
            reloadCluster && reloadCluster();
            onClose();
        }
        catch (e) {
            setError({
                title: t('ai:Failed to delete host'),
                message: (0, utils_1.getErrorMessage)(e),
            });
            setProgress(null);
        }
    });
    return (React.createElement(react_core_1.Modal, { "aria-label": t('ai:Remove hosts dialog'), isOpen: isOpen, onClose: onClose, id: "mass-delete-modal", variant: "medium" },
        React.createElement(react_core_1.ModalHeader, { title: t('ai:Remove hosts?'), titleIconVariant: "warning" }),
        React.createElement(react_core_1.ModalBody, null,
            React.createElement(react_core_1.Stack, { hasGutter: true },
                React.createElement(react_core_1.StackItem, null, t('ai:All of the listed hosts will be removed.')),
                React.createElement(react_core_1.StackItem, null, children),
                React.createElement(react_core_1.StackItem, null,
                    React.createElement(ModalProgress_1.default, { error: error, progress: progress })))),
        React.createElement(react_core_1.ModalFooter, null,
            React.createElement(react_core_1.Button, { onClick: () => void onClick(), isDisabled: progress !== null, variant: react_core_1.ButtonVariant.danger }, t('ai:Remove hosts')),
            React.createElement(react_core_1.Button, { onClick: onClose, variant: react_core_1.ButtonVariant.secondary, isDisabled: progress !== null }, t('ai:Cancel')))));
};
exports.default = MassDeleteHostModal;
//# sourceMappingURL=MassDeleteHostModal.js.map