"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 __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModalButton = void 0;
var React = require("react");
var PropTypes = require("prop-types");
var classnames = require("classnames");
var Button_1 = require("../Button/Button");
var Modal_1 = require("../Modal/Modal");
var utils_1 = require("../utils");
var excludeModalProps = ["closeModal", "children"];
var excludedButtonProps = ["children"];
// inherit properties from Button and Modal except closeModal; don't prefix children,
// but prefix the rest of Modal's keys.
var modalPropTypes = utils_1.prefixKeys(utils_1.omitKeys.apply(void 0, __spreadArrays([Modal_1.Modal.propTypes], excludeModalProps)), "modal");
var propTypes = __assign(__assign(__assign({}, Button_1.Button.propTypes), modalPropTypes), { children: Modal_1.Modal.propTypes.children, onClose: PropTypes.func });
// closeModal has no default, so no need to filter out of defaultProps
var defaultProps = __assign(__assign({}, Button_1.Button.defaultProps), utils_1.prefixKeys(Modal_1.Modal.defaultProps, "modal"));
var ModalButton = /** @class */ (function (_super) {
    __extends(ModalButton, _super);
    function ModalButton(props) {
        var _this = _super.call(this, props) || this;
        _this.state = { showingModal: false };
        _this.showModal = _this.showModal.bind(_this);
        _this.hideModal = _this.hideModal.bind(_this);
        return _this;
    }
    ModalButton.prototype.showModal = function () {
        this.setState({ showingModal: true });
    };
    ModalButton.prototype.hideModal = function () {
        this.setState({ showingModal: false });
    };
    ModalButton.prototype.render = function () {
        var _this = this;
        var buttonProps = utils_1.omitKeys.apply(void 0, __spreadArrays([utils_1.propsFor(Button_1.Button, this.props)], excludedButtonProps));
        var modalProps = utils_1.propsFor(Modal_1.Modal, utils_1.unprefixKeys(this.props, "modal"));
        return (React.createElement("div", { className: classnames("ModalButton", this.props.className) },
            React.createElement(Button_1.Button, __assign({}, buttonProps, { onClick: function (e) {
                    if (_this.props.onClick)
                        _this.props.onClick(e);
                    _this.showModal();
                } })),
            this.state.showingModal ? (React.createElement(Modal_1.Modal, __assign({}, modalProps, { closeModal: function () {
                    if (_this.props.onClose)
                        _this.props.onClose();
                    _this.hideModal();
                } }), this.props.children)) : null));
    };
    ModalButton.propTypes = propTypes;
    ModalButton.defaultProps = defaultProps;
    return ModalButton;
}(React.Component));
exports.ModalButton = ModalButton;
