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 __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import * as _ from "lodash";
import * as classnames from "classnames";
import * as PropTypes from "prop-types";
import * as React from "react";
import { FlexBox } from "..";
import "./TopBarButton.less";
var propTypes = {
    active: PropTypes.bool,
    children: PropTypes.node.isRequired,
    className: PropTypes.string,
    component: PropTypes.any,
    href: PropTypes.string,
    onClick: PropTypes.func,
    round: PropTypes.bool,
};
var TopBarButton = /** @class */ (function (_super) {
    __extends(TopBarButton, _super);
    function TopBarButton() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    TopBarButton.prototype.focus = function () {
        if (this._containerRef && this._containerRef.focus) {
            this._containerRef.focus();
        }
    };
    TopBarButton.prototype.blur = function () {
        if (this._containerRef && this._containerRef.blur) {
            this._containerRef.blur();
        }
    };
    TopBarButton.prototype.render = function () {
        var _this = this;
        var _a = this.props, active = _a.active, children = _a.children, className = _a.className, href = _a.href, onClick = _a.onClick;
        var additionalProps = _.omit(this.props, Object.keys(propTypes));
        var Wrapper = this._getWrapperComponent();
        return (React.createElement(FlexBox, { className: "TopBarButton--container" },
            React.createElement(Wrapper, __assign({}, additionalProps, { className: classnames("TopBarButton", className, this.props.round ? "TopBarButton--rounded" : null), href: href, onClick: function () {
                    // Button should not stay in active/focused state after it has been invoked.
                    // Otherwise, button looks like it's still active, even after clicking it.
                    // See PRTL-3215 for example of this bug
                    _this.blur();
                    if (onClick)
                        onClick();
                }, ref: function (ref) {
                    _this._containerRef = ref;
                }, "aria-current": active && "page" }), children),
            active && React.createElement("div", { className: "TopBarButton--activeIndicator" })));
    };
    TopBarButton.prototype._getWrapperComponent = function () {
        var _a = this.props, component = _a.component, href = _a.href;
        if (component) {
            return component;
        }
        if (href) {
            return "a";
        }
        return "button";
    };
    TopBarButton.propTypes = propTypes;
    return TopBarButton;
}(React.PureComponent));
export { TopBarButton };
