import less from 'less'
import ViewUI from 'view-design'
import 'view-design/dist/styles/iview.css'
import i18n from '@/locale'

const plugin = {
  less,
  ViewUI,
  // 配置自定义插件，bebouncePlugin可以是对象，也可以是函数，函数不能配置options参数
  bebouncePlugin: {
    install(Vue, options) {
      // 防抖
      Vue.prototype.$bebounce = function(fn) {
        clearTimeout(this.fun)
        this.fun = setTimeout(() => {
          fn.call(this, arguments[1])
        }, 500)
      }
    },
    options: {
      name: 'debouncePlugin'
    }
  }
}

export default Vue => {
  Vue.use(ViewUI, {
    i18n: (key, value) => i18n.t(key, value)
  })
  for (const name in plugin) {
    const value = plugin[name]
    Vue.use(value, typeof value === 'object' ? value : undefined)
  }
}
