import { _ as _extends } from '../_rollupPluginBabelHelpers-736b301a.js';
import React__default, { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import { Button } from 'antd';
import QueueAnim from 'rc-queue-anim';
import IconFont from '../IconFont/index.js';
import '@zenview/micro-utils';

const divEle = document.createElement('div');
let changeVisibel = undefined;
function Message(options) {
  return ReactDOM.render(/*#__PURE__*/React__default.createElement(View, _extends({}, options, {
    key: "message"
  })), divEle);
}
function View({
  onOk,
  content,
  title = '温馨提示',
  width = 380,
  height = 256,
  closable = true
}) {
  const [visible, setVisibel] = useState(true);
  const [loading, setLoading] = useState(false);
  useEffect(() => {
    changeVisibel = setVisibel;
    return () => changeVisibel = undefined;
  }, []);
  const onSubmit = function () {
    setLoading(true);
    onOk().then(() => {
      setLoading(false);
      setVisibel(false);
    });
  };
  return /*#__PURE__*/React__default.createElement(QueueAnim, {
    animConfig: {
      opacity: [1, 0]
    },
    duration: 200
  }, visible && /*#__PURE__*/React__default.createElement("div", {
    key: "message",
    className: "message-wrapper"
  }, /*#__PURE__*/React__default.createElement(QueueAnim, {
    type: "top"
  }, visible && /*#__PURE__*/React__default.createElement("div", {
    className: "message-layout",
    key: "message-content",
    style: {
      width,
      height
    }
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "message-title"
  }, title, closable && /*#__PURE__*/React__default.createElement(IconFont, {
    className: "close-icon",
    onClick: () => setVisibel(false),
    type: "icon-S_Edit_Close"
  })), /*#__PURE__*/React__default.createElement("div", {
    className: "message-content"
  }, content, /*#__PURE__*/React__default.createElement("div", {
    className: "message-footer"
  }, closable && /*#__PURE__*/React__default.createElement(Button, null, "\u53D6\u6D88"), /*#__PURE__*/React__default.createElement(Button, {
    loading: loading,
    type: "primary",
    onClick: onSubmit
  }, "\u786E\u8BA4")))))));
}
function notify({
  onOk,
  content,
  title,
  width,
  closable
}) {
  document.body.appendChild(divEle);
  Message({
    onOk,
    content,
    title,
    width,
    closable
  });
  changeVisibel && changeVisibel(true);
}
function destory() {
  ReactDOM.unmountComponentAtNode(divEle);
  document.body.removeChild(divEle);
}
const MessageNotice = {
  notify,
  destory
};

export { MessageNotice as default };
//# sourceMappingURL=index.js.map
