"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Modal = void 0;
var _tslib = require("tslib");
var _classnames = _interopRequireDefault(require("classnames"));
var _react = _interopRequireDefault(require("react"));
var _withDefaultProps = require("../../utils/with-default-props");
var _autoCenter = _interopRequireDefault(require("../auto-center"));
var _centerPopup = _interopRequireDefault(require("../center-popup"));
var _image = _interopRequireDefault(require("../image"));
var _space = _interopRequireDefault(require("../space"));
var _modalActionButton = require("./modal-action-button");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const defaultProps = {
  actions: [],
  closeOnAction: false,
  closeOnMaskClick: false,
  getContainer: null
};
const Modal = p => {
  const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
  const element = _react.default.createElement(_react.default.Fragment, null, !!props.image && _react.default.createElement("div", {
    className: cls('image-container')
  }, _react.default.createElement(_image.default, {
    src: props.image,
    alt: 'modal header image',
    width: '100%'
  })), !!props.header && _react.default.createElement("div", {
    className: cls('header')
  }, _react.default.createElement(_autoCenter.default, null, props.header)), !!props.title && _react.default.createElement("div", {
    className: cls('title')
  }, props.title), _react.default.createElement("div", {
    className: cls('content')
  }, typeof props.content === 'string' ? _react.default.createElement(_autoCenter.default, null, props.content) : props.content), _react.default.createElement(_space.default, {
    direction: 'vertical',
    block: true,
    className: (0, _classnames.default)(cls('footer'), props.actions.length === 0 && cls('footer-empty'))
  }, props.actions.map((action, index) => _react.default.createElement(_modalActionButton.ModalActionButton, {
    key: action.key,
    action: action,
    onAction: () => (0, _tslib.__awaiter)(void 0, void 0, void 0, function* () {
      var _a, _b, _c;
      yield Promise.all([(_a = action.onClick) === null || _a === void 0 ? void 0 : _a.call(action), (_b = props.onAction) === null || _b === void 0 ? void 0 : _b.call(props, action, index)]);
      if (props.closeOnAction) {
        (_c = props.onClose) === null || _c === void 0 ? void 0 : _c.call(props);
      }
    })
  }))));
  return _react.default.createElement(_centerPopup.default, {
    className: (0, _classnames.default)(cls(), props.className),
    style: props.style,
    afterClose: props.afterClose,
    afterShow: props.afterShow,
    showCloseButton: props.showCloseButton,
    closeOnMaskClick: props.closeOnMaskClick,
    onClose: props.onClose,
    visible: props.visible,
    getContainer: props.getContainer,
    bodyStyle: props.bodyStyle,
    bodyClassName: (0, _classnames.default)(cls('body'), props.image && cls('with-image'), props.bodyClassName),
    maskStyle: props.maskStyle,
    maskClassName: props.maskClassName,
    stopPropagation: props.stopPropagation,
    disableBodyScroll: props.disableBodyScroll,
    destroyOnClose: props.destroyOnClose,
    forceRender: props.forceRender
  }, element);
};
exports.Modal = Modal;
function cls(name = '') {
  return 'adm-modal' + (name && '-') + name;
}