"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 utils_1 = require("../../../../common/utils");
const use_translation_wrapper_1 = require("../../../../common/hooks/use-translation-wrapper");
const RemoveNodePoolModal = ({ onClose, onRemove, nodePool }) => {
    var _a;
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const [isRemoving, setIsRemoving] = React.useState(false);
    const [error, setError] = React.useState();
    return (React.createElement(react_core_1.Modal, { "aria-label": "remove node pool dialog", isOpen: true, onClose: onClose, variant: react_core_1.ModalVariant.small },
        React.createElement(react_core_1.ModalHeader, { titleIconVariant: "warning", title: t('ai:Remove nodepool') }),
        React.createElement(react_core_1.ModalBody, null,
            React.createElement(react_core_1.Stack, { hasGutter: true },
                React.createElement(react_core_1.StackItem, null, t('ai:Removing {{name}} will remove the association with {{count}} host. These hosts will become available for other nodepools.', { name: ((_a = nodePool.metadata) === null || _a === void 0 ? void 0 : _a.name) || '', count: nodePool.spec.replicas })),
                error && (React.createElement(react_core_1.StackItem, null,
                    React.createElement(react_core_1.Alert, { variant: "danger", isInline: true, title: error }))))),
        React.createElement(react_core_1.ModalFooter, null,
            React.createElement(react_core_1.Button, { onClick: () => {
                    const remove = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
                        try {
                            setError(undefined);
                            setIsRemoving(true);
                            yield onRemove(nodePool);
                            onClose();
                        }
                        catch (err) {
                            setError((0, utils_1.getErrorMessage)(err));
                        }
                        finally {
                            setIsRemoving(false);
                        }
                    });
                    void remove();
                }, isDisabled: isRemoving, variant: "danger", icon: isRemoving ? React.createElement(react_core_1.Spinner, { size: "md" }) : undefined }, t('ai:Remove')),
            React.createElement(react_core_1.Button, { variant: "link", onClick: onClose }, t('ai:Cancel')))));
};
exports.default = RemoveNodePoolModal;
//# sourceMappingURL=RemoveNodePoolModal.js.map