import { createVNode, render } from "vue";
import WlNotice from "./src/index.vue";
interface IOptions {
  message: string;
  type?: "success" | "alert" | "warning" | "error";
  duration?: number;
}
let mountNode = null;
export default (options: IOptions) => {
  const duration = options.duration | 2000;
  if (mountNode) {
    //确保只存在一个弹框
    document.body.removeChild(mountNode);
    mountNode = null;
  }
  const app = createVNode(WlNotice, {
    ...options,
    duration,
    show_toast: true,
  });
  const timer = setTimeout(() => {
    if (mountNode) {
      document.body.removeChild(mountNode);
      mountNode = null;
    }
    clearTimeout(timer);
  }, duration);
  mountNode = document.createElement("div");
  render(app, mountNode);
  document.body.appendChild(mountNode);
};
