"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventsModal = exports.EventsModalButton = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const exclamation_triangle_icon_1 = require("@patternfly/react-icons/dist/js/icons/exclamation-triangle-icon");
const t_global_icon_color_status_warning_default_1 = require("@patternfly/react-tokens/dist/js/t_global_icon_color_status_warning_default");
const Toolbar_1 = require("./Toolbar");
const EventListFetch_1 = require("../fetching/EventListFetch");
const ExternalLink_1 = tslib_1.__importDefault(require("./ExternalLink"));
const ErrorState_1 = tslib_1.__importDefault(require("./uiState/ErrorState"));
require("./EventsModal.css");
const use_translation_wrapper_1 = require("../../hooks/use-translation-wrapper");
const react_i18next_1 = require("react-i18next");
const hooks_1 = require("../../hooks");
const EventsModalButton = (_a) => {
    var { ButtonComponent = Toolbar_1.ToolbarButton, onFetchEvents, onClick, hostId, cluster, entityKind, children, title, fallbackEventsURL, disablePagination } = _a, props = tslib_1.__rest(_a, ["ButtonComponent", "onFetchEvents", "onClick", "hostId", "cluster", "entityKind", "children", "title", "fallbackEventsURL", "disablePagination"]);
    const [isModalOpen, setIsModalOpen] = react_1.default.useState(false);
    const closeModal = () => setIsModalOpen(false);
    const handleClick = onClick || (() => setIsModalOpen(true));
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(ButtonComponent, Object.assign({}, props, { onClick: handleClick }), children || title),
        react_1.default.createElement(exports.EventsModal, { title: title, isOpen: isModalOpen, onClose: closeModal, hostId: hostId, cluster: cluster, entityKind: entityKind, onFetchEvents: onFetchEvents, fallbackEventsURL: fallbackEventsURL, disablePagination: disablePagination })));
};
exports.EventsModalButton = EventsModalButton;
const EventsModal = (_a) => {
    var { onClose, isOpen, title, fallbackEventsURL } = _a, rest = tslib_1.__rest(_a, ["onClose", "isOpen", "title", "fallbackEventsURL"]);
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const [isLoading, setLoading] = (0, hooks_1.useStateSafely)(true);
    return (react_1.default.createElement(react_core_1.Modal, { isOpen: isOpen, "aria-label": t('ai:Displays events'), onClose: onClose, variant: react_core_1.ModalVariant.large, className: "events-modal", id: 'events-modal' },
        react_1.default.createElement(react_core_1.ModalHeader, { title: react_1.default.createElement(react_1.default.Fragment, null,
                title,
                " ",
                isLoading && react_1.default.createElement(react_core_1.Spinner, { size: "lg", "data-testid": "events-modal-spinner" })) }),
        react_1.default.createElement(react_core_1.ModalBody, { className: "events-modal__body" }, fallbackEventsURL ? (react_1.default.createElement(ErrorState_1.default, { title: t('ai:Could not load events'), content: react_1.default.createElement(react_1.default.Fragment, null,
                react_1.default.createElement(react_i18next_1.Trans, { t: t },
                    "ai:Could not load events from the standard location. You can check the events in the ",
                    react_1.default.createElement(ExternalLink_1.default, { href: fallbackEventsURL }, "raw format"),
                    ".")), icon: exclamation_triangle_icon_1.ExclamationTriangleIcon, iconColor: t_global_icon_color_status_warning_default_1.t_global_icon_color_status_warning_default.value })) : (react_1.default.createElement(EventListFetch_1.EventListFetch, Object.assign({ className: "events-modal__event-list", setLoading: setLoading }, rest)))),
        react_1.default.createElement(react_core_1.ModalFooter, null,
            react_1.default.createElement(react_core_1.Button, { key: "close", variant: react_core_1.ButtonVariant.primary, onClick: onClose, "data-testid": "close-events-modal" }, t('ai:Close')))));
};
exports.EventsModal = EventsModal;
//# sourceMappingURL=eventsModal.js.map