import { createRef } from "react";
import ContextHolderElement from "../../_util/contextHolder.js";
import HookModal from "./hookModal.js";
import { normalizeConfig } from "../confirm.js";
import { destroyList } from "../config.js";
import { jsx } from "../../../../../../../@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 = createRef();
  var holderEle = /* @__PURE__ */ jsx(ContextHolderElement, {
    ref: contextHolderRef
  });
  var uuid = 0;
  function addNewModal(config) {
    var _a;
    uuid += 1;
    var modalRef = createRef();
    function afterClose() {
      config.afterClose && config.afterClose();
      removeModalInstance();
    }
    var modal = /* @__PURE__ */ jsx(HookModal, {
      ...__assign({
        key: uuid,
        ref: modalRef
      }, normalizeConfig(config), {
        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);
    }
    destroyList.push(close);
    return {
      close,
      update
    };
  }
  var modalFuncs = {
    confirm: function(config) {
      return addNewModal(__assign({}, config));
    }
  };
  ["info", "success", "warning", "error"].forEach(function(type) {
    modalFuncs[type] = function(config) {
      return addNewModal(__assign(__assign({}, config), {
        isNotice: true,
        noticeType: type
      }));
    };
  });
  return [modalFuncs, holderEle];
}
export {
  useModal as default
};
//# sourceMappingURL=index.js.map
