import { App, Component } from 'vue';
// import { IGlobalPopup } from '@/components/popup/types';

// type GlobalPopupMethod = (component?: Component, options?: any) => IGlobalPopup;
type GlobalPopoverMethod = (component?: Component, options?: any) => void;
// export interface IGlobalProperties {
//   $popup: GlobalPopupMethod;
//   $popover: GlobalPopoverMethod;
//   [func: string]: any;
// }

let curApp: App;

export function setGlobalApp(app: App): void {
  curApp = app;
}

export function getGlobal()/* : IGlobalProperties */ {
  if (!curApp) {
    throw new Error('没有正确注册全局app');
  }
  return curApp.config.globalProperties/*  as IGlobalProperties */;
}

// export function createPopup<T = any>(component?: Component, options?: T): IGlobalPopup {
//   return getGlobal().$popup(component, options);
// }
export function createPopover<T = any>(component?: Component, options?: T): void {
  return getGlobal().$popover(component, options);
}
