'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 __());
    };
})();
import React from 'react';
import PropTypes from 'prop-types';
import { Row, Col, Navbar } from 'react-bootstrap';
import { Icon } from './Icon';
import { Button } from './Button';
import { translate } from '../../utils';
import { getSilentRouterHistory } from '..';
import { FocusHelper } from '../utils/FocusHelper';
import lang from '../../lang/common/index-en_US';
var HeaderToolbar = /** @class */ (function (_super) {
    __extends(HeaderToolbar, _super);
    function HeaderToolbar() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.focusHelper = new FocusHelper();
        return _this;
    }
    Object.defineProperty(HeaderToolbar, "contextTypes", {
        get: function () {
            return {
                history: PropTypes.object,
                buttonCol: PropTypes.number
            };
        },
        enumerable: true,
        configurable: true
    });
    HeaderToolbar.prototype.componentDidMount = function () {
        if (this.props.autoFocus) {
            this.focusHelper.focus();
        }
    };
    HeaderToolbar.prototype.handleBackIconClick = function () {
        var history = this.context.history || getSilentRouterHistory();
        var handleHistory = true;
        if (this.props.onBackButtonClick) {
            handleHistory = this.props.onBackButtonClick();
        }
        if (handleHistory === false) {
            return;
        }
        if (this.props.backLink) {
            history.push(this.props.backLink);
        }
        else {
            history.goBack();
        }
    };
    HeaderToolbar.prototype.render = function () {
        var buttonCol = this.props.buttonCol;
        var textCol = 12 - buttonCol * 2;
        var _a = this.props, title = _a.title, detailSettingForArialLabel = _a.detailSettingForArialLabel;
        return (React.createElement(Navbar, { fluid: true, className: "header-toolbar", "data-test-automation-id": this.props.testAutomationId, tabIndex: 0, ref: this.focusHelper.setEl, "aria-label": translate(detailSettingForArialLabel, { detailName: title }) },
            React.createElement(Row, null,
                buttonCol > 0 && (React.createElement(Col, { xs: buttonCol },
                    React.createElement(Navbar.Form, { pullLeft: true },
                        React.createElement(Button, { bsStyle: "link", onClick: this.handleBackIconClick.bind(this), "data-test-automation-id": this.props.backButtonTestAutomationId },
                            React.createElement(Icon, { name: "chevron-left-big", className: "back-icon" }),
                            translate(this.props.backText))))),
                React.createElement(Col, { xs: textCol },
                    React.createElement(Navbar.Header, null,
                        React.createElement(Navbar.Brand, null,
                            React.createElement("h1", { "data-test-automation-id": "title" }, this.props.title)))),
                React.createElement(Col, { xsOffset: 8 }, this.props.children))));
    };
    HeaderToolbar.propTypes = {
        testAutomationId: PropTypes.string,
        backButtonTestAutomationId: PropTypes.string,
        title: PropTypes.string,
        buttonCol: PropTypes.number,
        backText: PropTypes.string,
        onBackButtonClick: PropTypes.func,
        backLink: PropTypes.string,
        children: PropTypes.node,
        autoFocus: PropTypes.bool,
        detailSettingForArialLabel: PropTypes.string
    };
    HeaderToolbar.defaultProps = {
        testAutomationId: 'headerToolbar',
        backButtonTestAutomationId: 'buttonBack',
        title: '',
        buttonCol: 2,
        get backText() {
            return lang.BACK;
        },
        backLink: '',
        onBackButtonClick: null,
        children: null,
        autoFocus: true,
        get detailSettingForArialLabel() {
            return lang.DETAIL_SETTING_FOR_ARIA_LABEL;
        }
    };
    return HeaderToolbar;
}(React.Component));
export { HeaderToolbar };
//# sourceMappingURL=HeaderToolbar.js.map