"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.clear = exports.show = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var React = _interopRequireWildcard(require("react"));

var _dom = require("../utils/dom");

var _Modal = _interopRequireDefault(require("./Modal"));

var closeFn = new Set();

var show = function show(props) {
  var content = props.content,
      rest = (0, _objectWithoutProperties2.default)(props, ["content"]);
  var handler = (0, _dom.renderImperatively)( /*#__PURE__*/React.createElement(_Modal.default, (0, _extends2.default)({}, rest, {
    afterClose: function afterClose() {
      var _props$afterClose;

      closeFn.delete(handler.close);
      (_props$afterClose = props.afterClose) === null || _props$afterClose === void 0 ? void 0 : _props$afterClose.call(props);
    }
  }), content));
  closeFn.add(handler.close);
  return handler;
};

exports.show = show;

var clear = function clear() {
  closeFn.forEach(function (close) {
    return close();
  });
};

exports.clear = clear;