"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 });
/* @flow */
const React = __importStar(require("react"));
{
    ModalProps;
}
from;
'./types';
const prop_types_1 = __importDefault(require("prop-types"));
const classnames_1 = __importDefault(require("classnames"));
const react_portal_1 = require("react-portal");
const ButtonBase_1 = __importDefault(require("@material-ui/core/ButtonBase"));
const withStyles_1 = __importDefault(require("components/hoc/withStyles"));
const types_1 = require("components/config/types");
const ErrorBoundary_1 = __importDefault(require("components/hoc/ErrorBoundary"));
const Button_1 = __importDefault(require("components/bosons/Button"));
const styles_1 = __importDefault(require("./styles"));
class Modal extends React.Component {
    _defaultContentRender() {
        const { classes, title, description, buttons, theme, showCloseButton, onClose, } = this.props;
        return (React.createElement("div", { className: classes.content },
            React.createElement("div", { className: classes.contentInnerWrapper },
                showCloseButton && (React.createElement(ButtonBase_1.default, { classes: { root: classes.closeButton }, onClick: onClose },
                    React.createElement("i", { className: "ion ion-close" }))),
                title && React.createElement("div", { className: classes.title }, title),
                description && (React.createElement("div", { className: classes.description }, description)),
                buttons &&
                    buttons.length > 0 && (React.createElement("div", { className: classes.buttons }, buttons.map((buttonProps, index) => (React.createElement(Button_1.default, Object.assign({ key: index, classes: {
                        component: classnames_1.default(classes.button, {
                            cancel: buttonProps.type === 'cancel',
                        }),
                        text: classnames_1.default({
                            [classes.cancelButtonText]: buttonProps.type === 'cancel',
                        }),
                    }, buttonColor: theme.palette.primary.color2 }, buttonProps)))))))));
    }
    render() {
        const { classes, visible, renderContent } = this.props;
        if (!visible) {
            return null;
        }
        return (React.createElement(ErrorBoundary_1.default, null,
            React.createElement(react_portal_1.Portal, null,
                React.createElement("div", { className: classes.component }, renderContent ? renderContent() : this._defaultContentRender()))));
    }
}
Modal.propTypes = Object.assign({ visible: prop_types_1.default.bool, overlayColor: prop_types_1.default.string, onClose: prop_types_1.default.func, title: prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.node]), description: prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.node]), titleColor: prop_types_1.default.string, buttons: prop_types_1.default.arrayOf(prop_types_1.default.any), renderContent: prop_types_1.default.func, showCloseButton: prop_types_1.default.bool }, types_1.withStylesProps);
Modal.defaultProps = {
    visible: false,
    onClose: () => { },
    overlayColor: 'rgba(0,0,0,0.5)',
    buttons: [],
    title: '',
    description: '',
    showCloseButton: false,
};
exports.default = withStyles_1.default(styles_1.default)(Modal);
//# sourceMappingURL=index.js.map