"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 lodash_1 = __importDefault(require("lodash"));
var prop_types_1 = __importDefault(require("prop-types"));
var Button_1 = require("../../Button");
var Icon_1 = require("../../Icon");
var Block_1 = require("../../Block");
var constants_1 = require("../../../../utils/constants");
var TimeNumberEditor = /** @class */ (function (_super) {
    __extends(TimeNumberEditor, _super);
    function TimeNumberEditor() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.handleIncrease = function () { return _this.onChangeValue(true); };
        _this.handleDecrease = function () { return _this.onChangeValue(false); };
        _this.onChangeValue = function (isIncrease) {
            var newValue = _this.getChangeValue(isIncrease);
            _this.props.onChange(newValue);
        };
        _this.handleKeyDownIncreaseButton = function (e) {
            if (e.key === constants_1.KeyNames.Tab && e.shiftKey) {
                _this.props.onShiftTabAwait();
            }
        };
        return _this;
    }
    TimeNumberEditor.prototype.getChangeValue = function (isIncrease) {
        if (isIncrease === void 0) { isIncrease = true; }
        var value = this.props.value;
        if (lodash_1.default.isString(value)) {
            value = parseInt(value);
        }
        if (isIncrease) {
            value = value + 1;
        }
        else {
            value = value - 1;
        }
        return value;
    };
    TimeNumberEditor.prototype.render = function () {
        var _a = this.props, value = _a.value, testAutomationId = _a.testAutomationId, increaseButtonLabel = _a.increaseButtonLabel, decreaseButtonLabel = _a.decreaseButtonLabel, valueDisplayFormat = _a.valueDisplayFormat;
        return (react_1.default.createElement(Block_1.Block, { testAutomationId: testAutomationId },
            react_1.default.createElement(Button_1.Button, { testAutomationId: "increase", bsStyle: "link", block: true, onClick: this.handleIncrease, onKeyDown: this.handleKeyDownIncreaseButton, title: increaseButtonLabel, "aria-label": increaseButtonLabel },
                react_1.default.createElement(Icon_1.Icon, { name: "chevron-up-big" })),
            react_1.default.createElement("div", { className: "text-center time-text" },
                react_1.default.createElement("strong", null, valueDisplayFormat(value))),
            react_1.default.createElement(Button_1.Button, { testAutomationId: "decrease", bsStyle: "link", block: true, onClick: this.handleDecrease, title: decreaseButtonLabel, "aria-label": decreaseButtonLabel },
                react_1.default.createElement(Icon_1.Icon, { name: "chevron-down-big" }))));
    };
    TimeNumberEditor.propTypes = {
        increaseButtonLabel: prop_types_1.default.string.isRequired,
        decreaseButtonLabel: prop_types_1.default.string.isRequired,
        value: prop_types_1.default.number,
        onChange: prop_types_1.default.func.isRequired,
        onShiftTabAwait: prop_types_1.default.func,
        testAutomationId: prop_types_1.default.string.isRequired,
        valueDisplayFormat: prop_types_1.default.func
    };
    TimeNumberEditor.defaultProps = {
        value: 0,
        valueDisplayFormat: function (value) { return value; },
        onShiftTabAwait: function () { return true; }
    };
    return TimeNumberEditor;
}(react_1.default.PureComponent));
exports.TimeNumberEditor = TimeNumberEditor;
//# sourceMappingURL=TimeNumberEditor.js.map