import Vue from 'vue'
//import '@babel/polyfill'
import i18n from '@/locale'
import router from './router/index'
import store from './store'
import { sync } from 'vuex-router-sync'
import App from './components/app-root'
import { FontAwesomeIcon } from './icons'
import ViewUI from 'view-design'
import 'view-design/dist/styles/iview.css'
import tools from '@/utils/public.js'
import evTools from '@/utils/evTools.js'
import editorTools from '@/utils/editorTools.js'
import jsFn from '@/utils/js-fn.js'
import apiTools from '@/api'
import mockTools from '@/mock'
import axios from 'axios'
import { fetch, post } from '@/api/http'
import jwtDecode from 'jwt-decode'
import FileSaver from "file-saver";
import JSONPath from 'jsonpath'
import GLOBAL from '@/static/Global.js'
import BaseChangeLine from '@/components/student-analysis/total/BaseChangeLine.vue'
import echarts from 'echarts'
import vuescroll from 'vuescroll/dist/vuescroll-native'
import { Tree, Cascader } from 'element-ui' // 按需引入element Tree组件
import 'element-ui/lib/theme-chalk/tree.css'
import 'element-ui/lib/theme-chalk/icon.css'
import animated from 'animate.css'
import VueLogger from 'vuejs-logger'
import access from './access/index';
import _ from 'lodash'
import Icon from './icons/index.js'
import commonComponents from '@/common/index.js'
import evaluationComponents from '@/view/evaluation/components/index.js'
import '@/assets/iconfont/iconfont.css'
import "videojs-markers/dist/videojs.markers.css"
import vueAudioNative from 'vue-audio-native'
import konva from 'konva'
import "@/assets/student-web/component_styles/common.css";
import "@/assets/student-web/icons";
import { User } from '@/service/User'
import htmlToPdf from './utils/html2pdf'
Vue.use(htmlToPdf);
import { firestorePlugin } from "vuefire";
Vue.use(firestorePlugin);
import VueClipBoard from 'vue-clipboard2';
Vue.use(VueClipBoard);

var getfinishedtime = function () {
    var currentdate = new Date();
    var datetime =
        "今天 " +
        currentdate.getHours() +
        ":" +
        currentdate.getMinutes() +
        ":" +
        currentdate.getSeconds();

    return datetime;
};

Vue.use(konva)
Vue.use(vueAudioNative)

require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.use(animated)
Vue.use(commonComponents)
Vue.use(evaluationComponents)
Vue.use(Tree)
Vue.use(Cascader)

const logoptions = {
    isEnabled: true,
    logLevel: process.env.NODE_ENV === 'production' ? 'error' : 'debug',
    stringifyArguments: false, // 這個要不要自動JSON，自行選擇
    showLogLevel: true,
    showMethodName: true,
    separator: '|',
    showConsoleColors: true
}
Vue.use(VueLogger, logoptions)

// 设置全局VueScroll配置
Vue.use(vuescroll, {
    ops: tools.vueScrollOpt, // 在这里设置全局默认配置
    name: 'vuescroll'
})

Vue.prototype.$EventBus = new Vue()

// 全局API请求
Vue.prototype.$api = apiTools
Vue.prototype.$post = post
Vue.prototype.$get = fetch
Vue.prototype.$axios = axios
Vue.prototype.$User = User

// 工具类
Vue.prototype.$Mock = mockTools
// Vue.prototype.$GLOBAL = GLOBAL
Vue.use(GLOBAL, {
    i18n: (key, value) => i18n.t(key, value)
})
Vue.prototype.$FileSaver = FileSaver
Vue.prototype.$jwtDecode = jwtDecode
Vue.prototype.$JSONPath = JSONPath
Vue.prototype.$echarts = echarts
Vue.prototype.$tools = tools
Vue.prototype.$evTools = evTools
Vue.prototype.$editorTools = editorTools
Vue.prototype.$jsFn = jsFn //常用工具方法
Vue.prototype._ = _

// Registration of global components
Vue.component('icon', FontAwesomeIcon)

store.dispatch('user/checkSchoolCode');// 設定登入成功的學校簡碼
store.dispatch('user/checkUserProfile');// 檢查使用者個人詳細資訊
store.dispatch('user/checkStudentProfile');// 檢查學生的詳細資訊
store.dispatch('config/checkSrvAdr');// 檢查現在站的位置
store.dispatch('user/checkSchoolProfile').then(res=>{
    if(res) {
        User.freshLogin()
    }
});// 檢查使用者在學校的詳細資訊

router.beforeEach((to, from, next) => {
    document.body.scrollTop = 0
    next()
})

router.afterEach((to, from, next) => {
    document.body.scrollTop = 0
})

Vue.use(ViewUI, {
    i18n: (key, value) => i18n.t(key, value)
})

sync(store, router)

const app = new Vue({
    access,
    store,
    router,
    i18n,
    Icon,
    //利用LocalStorage保存設定
    created() {
        if (localStorage.getItem("local")) {
            console.log(localStorage.getItem("local"));
            store.commit("setLanguage", localStorage.getItem("local"));
        }
        if (localStorage.getItem("hintNextItem")) {
            store.commit("sethintNextItem", localStorage.getItem("hintNextItem"));
        }
    },
    ...App
})

export {
    app
}