import './styles/index.scss'

// Basic components
import inputText from './lib/basic/Input.vue'
import inputTextarea from './lib/basic/Textarea.vue'
import inputDate from './lib/basic/Date.vue'
import inputCheckbox from './lib/basic/Checkbox.vue'
import inputSelect from './lib/basic/Select.vue'
import keyValueTable from './lib/basic/KeyValueTable.vue'
import inputSearch from './lib/basic/Search.vue'
import actions from './lib/basic/Actions.vue'
import todo from './lib/basic/Todo.vue'
import multipleSelect from './lib/basic/MultipleSelect.vue'

// Advanced components
import htmlEditor from './lib/advanced/HtmlEditor.vue'
import inputMap from './lib/advanced/Map.vue'
import advancedFilter from './lib/advanced/Filter.vue'
import userFilter from './lib/advanced/UserFilter.vue'
import signature from './lib/advanced/Signature.vue'
import document from './lib/advanced/Document.vue'
import comment from './lib/advanced/Comment.vue'
import floorPlanner from './lib/advanced/FloorPlanner'
import reportDefinition from './lib/advanced/ReportDefinition'
import reportRendering from './lib/advanced/ReportRendering'
import extraDataRetrievalTable from './lib/advanced/ExtraDataRetrievalTable.vue'
import formBuilder from './lib/advanced/FormBuilder.vue'
import colorPickerList from './lib/advanced/ColorPickerList.vue'
import formRender from './lib/advanced/FormRender.vue'
import fieldRender from './lib/advanced/FieldRender'

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

// File management
import inputAttachment from './lib/files/Attachment.vue'

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

const Components = {
  inputText,
  inputDate,
  inputTextarea,
  inputCheckbox,
  keyValueTable,
  inputSearch,
  htmlEditor,
  inputSelect,
  inputAttachment,
  inputQrcode,
  inputBarcode,
  inputMap,
  advancedFilter,
  userFilter,
  signature,
  document,
  inputScan,
  multipleSelect,
  comment,
  todo,
  floorPlanner,
  reportDefinition,
  reportRendering,
  extraDataRetrievalTable,
  formBuilder,
  colorPickerList,
  formRender,
  fieldRender
};

// 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 {
  inputText,
  inputDate,
  inputTextarea,
  inputCheckbox,
  keyValueTable,
  htmlEditor,
  inputSelect,
  inputAttachment,
  inputQrcode,
  inputBarcode,
  inputMap,
  inputSearch,
  actions,
  advancedFilter,
  userFilter,
  signature,
  document,
  inputScan,
  multipleSelect,
  comment,
  todo,
  floorPlanner,
  reportDefinition,
  reportRendering,
  extraDataRetrievalTable,
  formBuilder,
  colorPickerList,
  formRender,
  fieldRender
}
