"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_core_1 = require("@patternfly/react-core");
const react_1 = tslib_1.__importDefault(require("react"));
const common_1 = require("../../../common");
const external_link_alt_icon_1 = require("@patternfly/react-icons/dist/js/icons/external-link-alt-icon");
const utils_1 = require("./utils");
const ModalDialogsContext_1 = require("../hosts/ModalDialogsContext");
const utils_2 = require("../clusters/utils");
const fetchEvents_1 = require("../fetching/fetchEvents");
const ViewClusterEventsButton_1 = tslib_1.__importDefault(require("../../../common/components/ui/ViewClusterEventsButton"));
const Toolbar_1 = require("../../../common/components/ui/Toolbar");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
require("./ClusterDetailsButtonGroup.css");
const LaunchOpenshiftConsoleButton = ({ consoleUrl, isDisabled, id }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (react_1.default.createElement(Toolbar_1.ToolbarButton, { variant: react_core_1.ButtonVariant.primary, component: "a", href: consoleUrl, target: "_blank", rel: "noopener", isDisabled: isDisabled, icon: react_1.default.createElement(external_link_alt_icon_1.ExternalLinkAltIcon, null), iconPosition: "right", id: id, "data-testid": id }, t('ai:Launch OpenShift Console')));
};
const getID = (suffix) => `cluster-detail-${suffix}`;
const ClusterDetailsButtonGroup = ({ cluster, credentials, credentialsError, showKubeConfig = true, }) => {
    const { addAlert, clearAlerts } = (0, common_1.useAlerts)();
    const { cancelInstallationDialog, resetClusterDialog } = (0, ModalDialogsContext_1.useModalDialogsContext)();
    const hasConsoleUrlAndNoError = (credentials === null || credentials === void 0 ? void 0 : credentials.consoleUrl) !== undefined && !credentialsError;
    return (react_1.default.createElement(react_core_1.Flex, { className: "assisted-ui-vertical-margin", spaceItems: { default: 'spaceItemsSm' }, direction: { default: 'row' }, justifyContent: { default: 'justifyContentFlexStart' } },
        react_1.default.createElement(common_1.RenderIf, { condition: cluster.status === 'error' },
            react_1.default.createElement(react_core_1.FlexItem, null,
                react_1.default.createElement(react_core_1.Button, { id: getID('button-reset-cluster'), variant: react_core_1.ButtonVariant.danger, onClick: () => resetClusterDialog.open({ cluster }) }, "Reset Cluster"))),
        react_1.default.createElement(common_1.RenderIf, { condition: showKubeConfig && hasConsoleUrlAndNoError && (0, common_1.canOpenConsole)(cluster.status) },
            react_1.default.createElement(react_core_1.FlexItem, null,
                react_1.default.createElement(LaunchOpenshiftConsoleButton, { isDisabled: false, consoleUrl: credentials === null || credentials === void 0 ? void 0 : credentials.consoleUrl, id: getID('button-launch-console') }))),
        react_1.default.createElement(common_1.RenderIf, { condition: (0, utils_2.canAbortInstallation)(cluster) },
            react_1.default.createElement(react_core_1.FlexItem, null,
                react_1.default.createElement(react_core_1.Button, { "data-testid": "cluster-installation-abort-button", variant: react_core_1.ButtonVariant.danger, onClick: () => cancelInstallationDialog.open({ clusterId: cluster.id }), isDisabled: false }, "Abort installation"))),
        react_1.default.createElement(react_core_1.FlexItem, null,
            react_1.default.createElement(common_1.KubeconfigDownload, { status: cluster.status, clusterId: cluster.id, "data-testid": getID('button-download-kubeconfig'), id: getID('button-download-kubeconfig') })),
        react_1.default.createElement(react_core_1.FlexItem, null,
            react_1.default.createElement(ViewClusterEventsButton_1.default, { cluster: cluster, onFetchEvents: fetchEvents_1.onFetchEvents })),
        react_1.default.createElement(react_core_1.FlexItem, null,
            react_1.default.createElement(react_core_1.Button, { "data-testid": "cluster-installation-logs-button", variant: react_core_1.ButtonVariant.link, onClick: () => {
                    void (0, utils_1.downloadClusterInstallationLogs)(addAlert, cluster.id, clearAlerts);
                }, isDisabled: !(0, common_1.canDownloadClusterLogs)(cluster) }, "Download Installation Logs"))));
};
exports.default = ClusterDetailsButtonGroup;
//# sourceMappingURL=ClusterDetailsButtonGroup.js.map