"use strict";
const React = require("react");
const contextHolder = require("../../_util/contextHolder.js");
const hookModal = require("./hookModal.js");
const confirm = require("../confirm.js");
const config = require("../config.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
var __assign = globalThis && globalThis.__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);
};
function useModal() {
  var contextHolderRef = React.createRef();
  var holderEle = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(contextHolder, {
    ref: contextHolderRef
  });
  var uuid = 0;
  function addNewModal(config$1) {
    var _a;
    uuid += 1;
    var modalRef = React.createRef();
    function afterClose() {
      config$1.afterClose && config$1.afterClose();
      removeModalInstance();
    }
    var modal = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(hookModal, {
      ...__assign({
        key: uuid,
        ref: modalRef
      }, confirm.normalizeConfig(config$1), {
        afterClose
      })
    });
    (_a = contextHolderRef.current) === null || _a === void 0 ? void 0 : _a.addInstance(modal);
    function removeModalInstance() {
      var _a2;
      (_a2 = contextHolderRef.current) === null || _a2 === void 0 ? void 0 : _a2.removeInstance(modal);
    }
    function close() {
      var _a2;
      (_a2 = modalRef.current) === null || _a2 === void 0 ? void 0 : _a2.close();
    }
    function update(config2) {
      var _a2;
      (_a2 = modalRef.current) === null || _a2 === void 0 ? void 0 : _a2.update(config2);
    }
    config.destroyList.push(close);
    return {
      close,
      update
    };
  }
  var modalFuncs = {
    confirm: function(config2) {
      return addNewModal(__assign({}, config2));
    }
  };
  ["info", "success", "warning", "error"].forEach(function(type) {
    modalFuncs[type] = function(config2) {
      return addNewModal(__assign(__assign({}, config2), {
        isNotice: true,
        noticeType: type
      }));
    };
  });
  return [modalFuncs, holderEle];
}
module.exports = useModal;
//# sourceMappingURL=index.js.map
