let modules = {};
import Vue from 'vue';
import vueInstance from './index.vue'

let configUtil = {
  vueInstance
};

// 定义插件对象
let currentMsg;
// vue的install方法，用于定义vue插件
modules = {
  install: function(Vue) {
    const MessageBoxInstance = Vue.extend(configUtil.vueInstance);
    const initInstance = () => {
      // 实例化vue实例
      currentMsg = new MessageBoxInstance({i18n: window.$vueRoot._i18n});
      let msgBoxEl = currentMsg.$mount().$el;
      document.body.appendChild(msgBoxEl);
    };

    // 在Vue的原型上添加实例方法，以全局调用
    Vue.prototype.$cnPrint = function(option) {
      if (!currentMsg) {
        initInstance();
      }
      currentMsg.option = option;
      return currentMsg.showMsgBox();
    }
  }
}

export function openCnPrint(option){
  const MessageBoxInstance = Vue.extend(configUtil.vueInstance);
  const initInstance = () => {
    // 实例化vue实例
    currentMsg = new MessageBoxInstance({i18n: window.$vueRoot._i18n});
    let msgBoxEl = currentMsg.$mount().$el;
    document.body.appendChild(msgBoxEl);
  };
  if (!currentMsg) {
    initInstance();
  }
  currentMsg.option = option;
  return currentMsg.showMsgBox();
}

export default modules;
