"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MenuComponent = void 0;
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
var type_guards_1 = require("../utils/type-guards");
var toolbar_1 = require("./toolbar");
var icon_1 = require("./icon");
var core_1 = require("@blueprintjs/core");
var MENU_ITEM_HEIGHT = 30;
/**
 * A generic menu component
 * @param props
 */
var MenuComponent = function (props) {
    var onClick = function (item) {
        var _a, _b;
        if ((0, toolbar_1.getEnabled)(item)) {
            (_a = item === null || item === void 0 ? void 0 : item.invoke) === null || _a === void 0 ? void 0 : _a.call(item);
            (_b = props.onInvoked) === null || _b === void 0 ? void 0 : _b.call(props);
        }
    };
    return React.createElement(core_1.Menu, { className: "bp3-elevation-1" }, props.items.map(function (item, index) {
        if (item.isSeparator) {
            return React.createElement(core_1.MenuDivider, { key: index });
        }
        else if ((0, type_guards_1.isMenu)(item)) {
            var text = "";
            if (typeof (item.label) == 'function') {
                text = item.label();
            }
            else {
                text = item.label || "";
            }
            return React.createElement(core_1.MenuItem, { key: index, text: text, icon: "menu-open" },
                React.createElement(exports.MenuComponent, { items: item.childItems, onInvoked: props.onInvoked }));
        }
        else {
            var height = MENU_ITEM_HEIGHT;
            var enabled = true;
            if (item.enabled != null) {
                if (typeof (item.enabled) == 'function') {
                    enabled = item.enabled();
                }
                else {
                    enabled = item.enabled;
                }
            }
            var imgStyle = tslib_1.__assign({ marginRight: 5 }, (0, toolbar_1.getIconStyle)(enabled, height));
            var text = item.label || "";
            //NOTE: Not using MenuItem here as we want fine control over the item content
            return React.createElement("li", { key: index },
                React.createElement("a", { className: "bp3-menu-item", onClick: function () { return onClick(item); } },
                    React.createElement(icon_1.ImageIcon, { style: imgStyle, url: item.icon, spriteClass: item.iconClass }),
                    " ",
                    text));
        }
    }));
};
exports.MenuComponent = MenuComponent;
//# sourceMappingURL=menu.js.map