// Scanners
import inputQrcode from './QRCode.vue'
import inputBarcode from './BarCode.vue'
import inputScan from './ScanInput.vue'

// const inputText = () => import(/* webpackChunkName: "basic" */ './lib/basic/Input.vue')

const Components = {
  inputQrcode,
  inputBarcode,
  inputScan,
};

// Declare install function executed by Vue.use()
export function install(Vue) {
  if (install.installed) return;
  install.installed = true;

  Object.keys(Components).forEach(name => {
    Vue.component(name, Components[name]);
  })
}

// Create module definition for Vue.use()
const plugin = {
  install,
};

// Auto-install when vue is found (eg. in browser via <script> tag)
let GlobalVue = null;
if (typeof window !== 'undefined') {
  GlobalVue = window.Vue;
} else if (typeof global !== 'undefined') {
  GlobalVue = global.Vue;
}
if (GlobalVue) {
  GlobalVue.use(plugin);
}

// To allow use as module (npm/webpack/etc.) export component
export {
  inputQrcode,
  inputBarcode,
  inputScan,
}
