var __assign = this && this.__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);
};

import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import Dialog from "./Dialog";
import Emotion from "./Emotion";
import Confirm from "./Confirm"; // eslint-disable-next-line @typescript-eslint/no-explicit-any

var createFunc = function createFunc(View, icon) {
  return function (config, context) {
    var Dg = function Dg(props) {
      var _a = React.useState(true),
          visible = _a[0],
          setVisible = _a[1];

      var onClose = function onClose() {
        setVisible(false);
      };

      var onOk = function onOk(e, value, setLoading) {
        props.onOk && props.onOk(e, onClose, value, setLoading);
      };

      var onCancel = function onCancel(e) {
        onClose();
        props.onCancel && props.onCancel(e);
      };

      return _jsx(View, __assign({}, props, {
        visible: visible,
        onOk: onOk,
        onCancel: onCancel
      }, {
        children: props.children && props.children(onClose)
      }), void 0);
    };

    var dom = document.createElement('div');
    document.body.append(dom);

    var afterClose = function afterClose() {
      ReactDOM.unmountComponentAtNode(dom);
      dom.remove(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore

      dom = undefined;
    };

    if (View.displayName === 'Emotion') {
      var ct = config;
      ct.emotion = icon ? icon : ct.emotion;
    }

    ReactDOM.render(_jsx(Dg, __assign({}, config, {
      children: context,
      afterClose: afterClose
    }), void 0), dom);
  };
};

var dialogApi = {
  open: createFunc(Dialog),
  info: createFunc(Emotion, 'info'),
  error: createFunc(Emotion, 'alert'),
  warning: createFunc(Emotion, 'help-2'),
  success: createFunc(Emotion, 'success'),
  normal: createFunc(Emotion),
  confirm: createFunc(Confirm)
};
export default dialogApi;

