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 _ from 'lodash';
import { KeyCodes } from '../../utils/constants';
var KeyDownable = /** @class */ (function (_super) {
    __extends(KeyDownable, _super);
    function KeyDownable() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.onClick = function (e) {
            var onClick = _this.props.onClick;
            if (_.isFunction(onClick)) {
                onClick(e);
            }
        };
        _this.onKeyDown = function (e) {
            var _a = _this.props, preventDefaultKeyDown = _a.preventDefaultKeyDown, stopPropagation = _a.stopPropagation, onKeyDown = _a.onKeyDown;
            if (_.isFunction(onKeyDown)) {
                return onKeyDown(e);
            }
            if (e.keyCode === KeyCodes.SPACE || e.keyCode === KeyCodes.ENTER) {
                if (preventDefaultKeyDown) {
                    e.preventDefault();
                }
                if (stopPropagation) {
                    e.stopPropagation();
                }
                _this.onClick(e);
            }
        };
        /* prevent focus style always there after click */
        _this.onMouseDown = function (e) {
            var _a = _this.props, preventDefaultMouseDown = _a.preventDefaultMouseDown, onMouseDown = _a.onMouseDown;
            if (preventDefaultMouseDown) {
                e.preventDefault();
            }
            if (_.isFunction(onMouseDown)) {
                onMouseDown(e);
            }
        };
        return _this;
    }
    KeyDownable.prototype.render = function () {
        var children = this.props.children;
        var renderChildren = children;
        return renderChildren({
            tabIndex: this.props.tabIndex,
            onClick: this.onClick,
            onKeyDown: this.onKeyDown,
            onMouseDown: this.onMouseDown
        });
    };
    KeyDownable.propTypes = {
        children: PropTypes.func.isRequired,
        preventDefaultKeyDown: PropTypes.bool,
        preventDefaultMouseDown: PropTypes.bool,
        tabIndex: PropTypes.number,
        stopPropagation: PropTypes.bool,
        onClick: PropTypes.func,
        onKeyDown: PropTypes.func,
        onMouseDown: PropTypes.func
    };
    KeyDownable.defaultProps = {
        preventDefaultKeyDown: true,
        preventDefaultMouseDown: true,
        tabIndex: 0,
        stopPropagation: false,
        onClick: null,
        onKeyDown: null,
        onMouseDown: null
    };
    return KeyDownable;
}(React.Component));
export { KeyDownable };
//# sourceMappingURL=KeyDownable.js.map