import { createApp } from 'vue'
import ScanOverlay from './ScanOverlay.vue'
import NativeQRCode from "src/common/nativeJSdk/native";

// ???????
let inited = false;
// ??????
let mountNode;
// ????
let scanOverlayInstance;
// ????
let vm;

// ??
function show(msg) {
  // ???
  if (!inited) {
    mountNode = document.createElement('div');
    scanOverlayInstance = createApp(ScanOverlay, {});
    scanOverlayInstance.config.globalProperties.$nativeQRCode = NativeQRCode;
    vm = scanOverlayInstance.mount(mountNode);
    document.body.appendChild(mountNode);
    inited = true;
  }
  // ??
  vm.show(msg);
}

// ??
function hide() {
  if (vm && inited) {
    vm.hide();
  }
}

// ??
function close() {
  scanOverlayInstance.unmount(mountNode);
  document.body.removeChild(mountNode);
}


export default {
  show,
  hide,
}
