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

const Components = {
  inputText,
  inputDate,
  inputTextarea,
  inputCheckbox,
  inputSelect,
  keyValueTable,
  inputSearch,
  multipleSelect
};

// 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,
  inputSelect,
  keyValueTable,
  inputSearch,
  multipleSelect
}
