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 _ from 'lodash';
import PropTypes from 'prop-types';
import { Button } from '../../Button';
import { Icon } from '../../Icon';
import { Block } from '../../Block';
import { KeyNames } from '../../../../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 === 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 (_.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.createElement(Block, { testAutomationId: testAutomationId },
            React.createElement(Button, { testAutomationId: "increase", bsStyle: "link", block: true, onClick: this.handleIncrease, onKeyDown: this.handleKeyDownIncreaseButton, title: increaseButtonLabel, "aria-label": increaseButtonLabel },
                React.createElement(Icon, { name: "chevron-up-big" })),
            React.createElement("div", { className: "text-center time-text" },
                React.createElement("strong", null, valueDisplayFormat(value))),
            React.createElement(Button, { testAutomationId: "decrease", bsStyle: "link", block: true, onClick: this.handleDecrease, title: decreaseButtonLabel, "aria-label": decreaseButtonLabel },
                React.createElement(Icon, { name: "chevron-down-big" }))));
    };
    TimeNumberEditor.propTypes = {
        increaseButtonLabel: PropTypes.string.isRequired,
        decreaseButtonLabel: PropTypes.string.isRequired,
        value: PropTypes.number,
        onChange: PropTypes.func.isRequired,
        onShiftTabAwait: PropTypes.func,
        testAutomationId: PropTypes.string.isRequired,
        valueDisplayFormat: PropTypes.func
    };
    TimeNumberEditor.defaultProps = {
        value: 0,
        valueDisplayFormat: function (value) { return value; },
        onShiftTabAwait: function () { return true; }
    };
    return TimeNumberEditor;
}(React.PureComponent));
export { TimeNumberEditor };
//# sourceMappingURL=TimeNumberEditor.js.map