"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = __importStar(require("react"));
const react_jss_1 = __importDefault(require("react-jss"));
const react_key_handler_1 = __importStar(require("react-key-handler"));
const styles = (theme) => ({
    container: Object.assign({ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%' }, theme.mixins.flexbox.containerCenter, { backgroundColor: ((props) => props.backgroundOverlay ? 'rgba(0, 0, 0, .3)' : 'none'), zIndex: theme.$zIndexSupra }),
});
class ModalWrapperImpl extends React.PureComponent {
    constructor(props) {
        super(props);
        this.handleClickOutside = this.handleClickOutside.bind(this);
        this.setModalWrapperRef = this.setModalWrapperRef.bind(this);
    }
    handleClickOutside(e) {
        if (!this.modalWrapper)
            return;
        const target = e.target;
        if (e.currentTarget === target && this.props.onCancel)
            this.props.onCancel(e);
    }
    setModalWrapperRef(modalWrapper) {
        this.modalWrapper = modalWrapper;
    }
    render() {
        const { classes, onCancel, children } = this.props;
        return (React.createElement("div", { className: classes.container, ref: this.setModalWrapperRef, onClick: this.handleClickOutside },
            onCancel &&
                React.createElement(react_key_handler_1.default, { keyEventName: react_key_handler_1.KEYDOWN, keyValue: "Escape", onKeyHandle: onCancel }),
            children));
    }
}
ModalWrapperImpl.defaultProps = {
    backgroundOverlay: true,
    onCancel: () => { },
};
exports.ModalWrapper = react_jss_1.default(styles)(ModalWrapperImpl);
//# sourceMappingURL=index.js.map