import { createPopover } from '@/utils/frontend/vueHelper';
import { Component } from 'vue';
import { PopoverSetting } from './types';

let isShow = false;
// 节流变量
const mask: any = {};
// 延时id数列
const list: any = [];
export const showPopover = (settings: PopoverSetting, component?: Component) => {
  isShow = true;
  mask.tID = setTimeout(() => {
    if (isShow === true) {
      createPopover(component, settings);
    }
  }, 500);
  list.push(mask.tID);
};

export const hidePopover = () => {
  isShow = false;
  // 每次取消操作的时候就去掉第一个队员
  clearTimeout(list[0]);
  list.splice(0, 1);
  if (document.body.getElementsByClassName('popover-content')[0])
    document.body.getElementsByClassName('popover-content')[0].remove();
};
