var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import React from 'react';
import PropTypes from 'prop-types';
import { Block } from './Block';
import { TabItem } from './TabItem';
import classnames from 'classnames';
import { NavDropdown } from './NavDropdown';
import { Icon } from './Icon';
import { ExternalLink } from './ExternalLink';
import lang from '../../lang/common/index-en_US';
var ToolsMenu = /** @class */ (function (_super) {
    __extends(ToolsMenu, _super);
    function ToolsMenu() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.renderMenuItem = function (item) {
            if (_this.props.isExternalLink(item.href)) {
                return (React.createElement(ExternalLink, { id: item.menuTitle, key: item.menuTitle, href: item.href, title: item.title, tabIndex: -1, onClick: item.onClick, role: "menuitem", onKeyDown: _this.props.onKeyDown, withIcon: true }));
            }
            var router = _this.context.router;
            var isCurrentPage = router ? router.isActive(item.href) : false;
            var labelForScreenReader = isCurrentPage ? (React.createElement("span", { className: "sr-only" }, ", " + _this.props.current)) : null;
            return (React.createElement(TabItem, { role: "menuitem", to: item.href, key: item.menuTitle, testAutomationId: item.menuTitle, tabIndex: -1, activeKey: item.menuTitle, className: classnames({ active: isCurrentPage }), onKeyDown: _this.props.onKeyDown, onSelect: _this.props.onSelect },
                item.title,
                labelForScreenReader));
        };
        _this.renderCategory = function (category) {
            var title = category.title, items = category.items, id = category.id;
            return (React.createElement(Block, { key: id + "Category", testAutomationId: id + "Category", className: "tools-category", role: "group", "aria-labelledby": id + "CategoryTitle" },
                React.createElement("legend", { "data-test-automation-id": "categoryName", className: "tools-category-title", id: id + "CategoryTitle" }, title),
                items.map(_this.renderMenuItem)));
        };
        _this.renderColumn = function (categories, index) {
            return (React.createElement("div", { key: "column" + index, className: "tools-menu-column" }, categories.map(_this.renderCategory)));
        };
        return _this;
    }
    ToolsMenu.prototype.render = function () {
        return (React.createElement("div", { "data-test-automation-id": "toolsMenu", className: "tools-menu" }, this.props.columns.map(this.renderColumn)));
    };
    ToolsMenu.contextTypes = {
        router: PropTypes.object
    };
    ToolsMenu.propTypes = {
        columns: PropTypes.array.isRequired,
        onKeyDown: PropTypes.func,
        onSelect: PropTypes.func,
        isExternalLink: PropTypes.func,
        current: PropTypes.string
    };
    ToolsMenu.defaultProps = {
        onKeyDown: function (e) { },
        onSelect: function (e) { },
        isExternalLink: function (url) { return /^(?:https?:)?\/\//.test(url); },
        get current() {
            return lang.CURRENT;
        }
    };
    return ToolsMenu;
}(React.Component));
export { ToolsMenu };
var ToolsDropdown = /** @class */ (function (_super) {
    __extends(ToolsDropdown, _super);
    function ToolsDropdown() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ToolsDropdown.prototype.render = function () {
        var _a = this.props, id = _a.id, title = _a.title, className = _a.className, items = _a.items, isExternalLink = _a.isExternalLink;
        var titleElement = (React.createElement("span", null,
            title,
            React.createElement(Icon, { name: "chevron-down-small" })));
        var NavDropdownTS = NavDropdown;
        return (React.createElement(NavDropdownTS, { noCaret: true, role: "menu", id: id, key: id, className: className, "data-test-automation-id": id, activeKey: id, title: titleElement },
            React.createElement(ToolsMenu, { columns: items, isExternalLink: isExternalLink })));
    };
    ToolsDropdown.contextTypes = {
        router: PropTypes.object
    };
    ToolsDropdown.propTypes = {
        title: PropTypes.string.isRequired,
        id: PropTypes.string.isRequired,
        items: PropTypes.array.isRequired,
        className: PropTypes.string,
        isExternalLink: PropTypes.func
    };
    ToolsDropdown.defaultProps = {
        className: '',
        isExternalLink: function (url) { return /^(?:https?:)?\/\//.test(url); }
    };
    return ToolsDropdown;
}(React.Component));
export { ToolsDropdown };
//# sourceMappingURL=ToolsMenu.js.map