/*
 * Copyright 2020 The Kubernetes Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import React from 'react';
import Icons from '../../spi/Icons';
import ToolbarButton from './ToolbarButton';
import Markdown from '../../Content/Markdown';
/** helper to ensure exhaustiveness of the switch statement below */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function assertUnreachable(x) {
    throw new Error('Did not expect to get here');
}
export default class Toolbar extends React.PureComponent {
    icon() {
        if (this.props.toolbarText) {
            const { type } = this.props.toolbarText;
            switch (type) {
                case 'info':
                    return React.createElement(Icons, { icon: "Info" });
                case 'success':
                    return React.createElement(Icons, { icon: "Checkmark" });
                case 'warning':
                    return React.createElement(Icons, { icon: "Warning" });
                case 'error':
                    return React.createElement(Icons, { icon: "Error" });
            }
            // this bit of magic ensures exhaustiveness of the switch;
            // reference: https://stackoverflow.com/a/39419171
            return assertUnreachable(type);
        }
    }
    buttons() {
        if (this.props.buttons) {
            return this.props.buttons
                .sort() // sort alphabetically first
                .sort((a, b) => {
                return (a.order || 0) - (b.order || 0);
            })
                .map((button, idx) => (React.createElement(ToolbarButton, { tab: this.props.tab, execUUID: this.props.execUUID, button: button, response: this.props.response, args: this.props.args, key: idx })));
        }
    }
    render() {
        try {
            return (React.createElement("div", { className: "sidecar-bottom-stripe-toolbar" },
                React.createElement("div", { className: "sidecar-toolbar-text", "data-location-bottom": this.props.bottom || undefined, "data-type": this.props.toolbarText && this.props.toolbarText.type },
                    React.createElement("div", { className: "sidecar-toolbar-text-icon" }, this.icon()),
                    this.props.toolbarText &&
                        (typeof this.props.toolbarText.text === 'string' ? (React.createElement(Markdown, { source: this.props.toolbarText.text, className: "sidecar-toolbar-text-content" })) : (React.createElement("div", { className: "sidecar-toolbar-text-content", dangerouslySetInnerHTML: {
                                __html: this.props.toolbarText.text.innerHTML
                            } })))),
                React.createElement("div", { className: "sidecar-bottom-stripe-mode-bits sidecar-bottom-stripe-button-container", "data-location-bottom": this.props.bottom || undefined },
                    React.createElement("div", { className: "fill-container flex-layout flush-right flex-align-stretch" }, this.buttons()))));
        }
        catch (err) {
            console.error(err);
            return React.createElement("div", null);
        }
    }
}
//# sourceMappingURL=Toolbar.js.map