'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 __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var Navbar_1 = __importDefault(require("react-bootstrap/lib/Navbar"));
var Row_1 = __importDefault(require("react-bootstrap/lib/Row"));
var Col_1 = __importDefault(require("react-bootstrap/lib/Col"));
var Icon_1 = require("./Icon");
var Button_1 = require("./Button");
var utils_1 = require("../../utils");
var __1 = require("..");
var FocusHelper_1 = require("../utils/FocusHelper");
var index_en_US_1 = __importDefault(require("../../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_1.FocusHelper();
        return _this;
    }
    Object.defineProperty(HeaderToolbar, "contextTypes", {
        get: function () {
            return {
                history: prop_types_1.default.object,
                buttonCol: prop_types_1.default.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 || __1.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_1.default.createElement(Navbar_1.default, { fluid: true, className: "header-toolbar", "data-test-automation-id": this.props.testAutomationId, tabIndex: 0, ref: this.focusHelper.setEl, "aria-label": utils_1.translate(detailSettingForArialLabel, { detailName: title }) },
            react_1.default.createElement(Row_1.default, null,
                buttonCol > 0 && (react_1.default.createElement(Col_1.default, { xs: buttonCol },
                    react_1.default.createElement(Navbar_1.default.Form, { pullLeft: true },
                        react_1.default.createElement(Button_1.Button, { bsStyle: "link", onClick: this.handleBackIconClick.bind(this), "data-test-automation-id": this.props.backButtonTestAutomationId },
                            react_1.default.createElement(Icon_1.Icon, { name: "chevron-left-big", className: "back-icon" }),
                            utils_1.translate(this.props.backText))))),
                react_1.default.createElement(Col_1.default, { xs: textCol },
                    react_1.default.createElement(Navbar_1.default.Header, null,
                        react_1.default.createElement(Navbar_1.default.Brand, null,
                            react_1.default.createElement("h1", { "data-test-automation-id": "title" }, this.props.title)))),
                react_1.default.createElement(Col_1.default, { xsOffset: 8 }, this.props.children))));
    };
    HeaderToolbar.propTypes = {
        testAutomationId: prop_types_1.default.string,
        backButtonTestAutomationId: prop_types_1.default.string,
        title: prop_types_1.default.string,
        buttonCol: prop_types_1.default.number,
        backText: prop_types_1.default.string,
        onBackButtonClick: prop_types_1.default.func,
        backLink: prop_types_1.default.string,
        children: prop_types_1.default.node,
        autoFocus: prop_types_1.default.bool,
        detailSettingForArialLabel: prop_types_1.default.string
    };
    HeaderToolbar.defaultProps = {
        testAutomationId: 'headerToolbar',
        backButtonTestAutomationId: 'buttonBack',
        title: '',
        buttonCol: 2,
        get backText() {
            return index_en_US_1.default.BACK;
        },
        backLink: '',
        onBackButtonClick: null,
        children: null,
        autoFocus: true,
        get detailSettingForArialLabel() {
            return index_en_US_1.default.DETAIL_SETTING_FOR_ARIA_LABEL;
        }
    };
    return HeaderToolbar;
}(react_1.default.Component));
exports.HeaderToolbar = HeaderToolbar;
//# sourceMappingURL=HeaderToolbar.js.map