// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import iView from 'iview'
import i18n from '@/locale'
import config from '@/config'
import importDirective from '@/directive'
import { directive as clickOutside } from 'v-click-outside-x'
import './index.less'
import '@/assets/icons/iconfont.css'
import TreeTable from 'tree-table-vue'
import VOrgTree from 'v-org-tree'
import VueClipboard from 'vue-clipboard2'
import 'v-org-tree/dist/v-org-tree.css'
import IFetch from '@/api/iFetch'
import * as apiConfig from '@/api/apiConfig'
import { apiVerify } from '@/api/apiVerify'
import { clearAdminInfo } from '@/libs/util'
// 引入quill editor
import VueQuillEditor from 'vue-quill-editor'
import Quill from 'quill'
// require styles 引入样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import BaiduMap from 'vue-baidu-map'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import vueTencentCaptcha from '@carpenter/vue-tencent-captcha'

// Vue.use(iView, {
//     i18n: (key, value) => i18n.t(key, value)
// })
Vue.use(vueTencentCaptcha)
Vue.use(iView, {
  i18n: function (path, options) {
    let value = i18n.t(path, options)

    if (value !== null && value !== undefined) {
      return value
    }
    return ''
  }
})
Vue.use(TreeTable)
Vue.use(VOrgTree)
Vue.use(VueClipboard)
Vue.use(BaiduMap, { ak: config.baiduMapAppKey })
Vue.use(ElementUI)

const notifyErrMsg = msg => {
  iView.Notice.error({
    title: msg || '服务端请求异常'
  })
}
const myFetch = new IFetch(apiConfig, apiVerify, notifyErrMsg, clearAdminInfo)
Vue.use({
  install: (Vue) => {
    Vue.prototype.api = myFetch
  }
})

// 自定义视频
const BlockEmbed = Quill.import('blots/block/embed')
class VideoBlot extends BlockEmbed {
  static create (value) {
    let node = super.create()
    node.setAttribute('src', value.url)
    node.setAttribute('controls', value.controls)
    node.setAttribute('width', value.width)
    node.setAttribute('height', value.height)
    node.setAttribute('poster', value.poster)
    node.setAttribute('webkit-playsinline', true)
    node.setAttribute('playsinline', true)
    node.setAttribute('x5-playsinline', true)
    return node
  }
  static value (node) {
    return {
      url: node.getAttribute('src'),
      controls: node.getAttribute('controls'),
      width: node.getAttribute('width'),
      height: node.getAttribute('height'),
      poster: node.getAttribute('poster')
    }
  }
}
VideoBlot.blotName = 'simpleVideo'
VideoBlot.tagName = 'video'

// 自定义编辑器图片
class ImgBlot extends BlockEmbed {
  static create (value) {
    let node = super.create()
    node.setAttribute('src', value.url)
    node.setAttribute('height', value.height)
    node.setAttribute('width', value.width)
    node.setAttribute('style', 'object-fit: contain')
    return node
  }
  static value (node) {
    return {
      url: node.getAttribute('src'),
      height: node.getAttribute('height'),
      width: node.getAttribute('width')
    }
  }
}
ImgBlot.blotName = 'simpleImg'
ImgBlot.tagName = 'img'
Quill.register(ImgBlot)

Quill.register(VideoBlot)
Vue.use(VueQuillEditor)

/**
 * @description 生产环境关掉提示
 */
Vue.config.productionTip = false
/**
     * @description 全局注册应用配置
     */
Vue.prototype.$config = config
/**
     * 注册指令
     */
importDirective(Vue)
Vue.directive('clickOutside', clickOutside)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  i18n,
  store,
  render: h => h(App)
})
