"use strict";
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 __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TopBar = exports.TopBarThemes = void 0;
var classnames = require("classnames");
var React = require("react");
var Logo_1 = require("../Logo");
var flex_1 = require("../flex");
var TopBarButton_1 = require("./TopBarButton");
require("./index.less");
var Menu_1 = require("../Menu");
// Defined as an array first as a convenience to make automatic enumeration of all themes easier in
// the demo code.
exports.TopBarThemes = ["default", "plain", "a11y"];
/**
 * Global page-level header component.
 */
var TopBar = /** @class */ (function (_super) {
    __extends(TopBar, _super);
    function TopBar() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    TopBar.prototype.render = function () {
        var _a = this.props, children = _a.children, className = _a.className, title = _a.title, customLogo = _a.customLogo, theme = _a.theme;
        // If the last element is a "rounded" TopBarButton we need to add some additional padding to the right side.
        // To determine this we need to inspect the children;
        var needsRightPadding = false;
        var childrenArray = React.Children.toArray(children);
        if (childrenArray.length) {
            var lastItem = childrenArray[childrenArray.length - 1];
            var lastTrigger = lastItem.type === Menu_1.default ? lastItem.props.trigger : lastItem;
            if (lastTrigger && lastTrigger.type === TopBarButton_1.TopBarButton && lastTrigger.props.round) {
                needsRightPadding = true;
            }
        }
        return (React.createElement(flex_1.FlexBox, { alignItems: "center", role: "banner", className: classnames("dewey--TopBar", className, needsRightPadding && "dewey--TopBar--rightPadding", "dewey--TopBar--theme--" + theme) },
            React.createElement(TopBarButton_1.TopBarButton, { "aria-label": this.props.logoAriaLabel, href: this.props.logoHref, onClick: this.props.onLogoClick, className: "dewey-TopBar--logoLink", "data-testid": "topBarLogoLink" }, customLogo || (React.createElement(Logo_1.default, { className: "dewey--TopBar--logo", svgClassName: "dewey--TopBar--logo--mobile" }))),
            title && (React.createElement("h1", { className: "dewey--TopBar--title", title: title }, title)),
            React.createElement(flex_1.FlexBox, { alignItems: "center", justify: flex_1.Justify.END, grow: true }, children)));
    };
    TopBar.defaultProps = {
        theme: "default",
        logoAriaLabel: "Clever Home",
    };
    TopBar.Button = TopBarButton_1.TopBarButton;
    return TopBar;
}(React.PureComponent));
exports.TopBar = TopBar;
