import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import '@/mixins'
import router from './router'
import 'viewerjs/dist/viewer.css'
import Viewer from 'v-viewer'
import clickOutside from "@/directives/v-click-outside.js"
import browser from '@/utils/browser'

import "@/assets/style/my-reset.css"

console.log('v0410.1517')
if (!browser.mobile) {
  location.replace(process.env.VUE_APP_PC_URL)
}

Vue.use(Viewer, {
  defaultOptions: {
    navbar: false,
    button: false,
    maxZoomRatio: 2,
    zIndex: 99999,
    title: false
  }
})


Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(clickOutside)

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

// 访问量埋点
globalApi.reportVisit()

// 访问量（每天最多一次）埋点
const visitDailyInfo = localStorage.getItem("HDB_oneDay")
if (visitDailyInfo) {
  const data = JSON.parse(visitDailyInfo)
  const time = Date.now()
  if (time - Number(data.time) >= Number(data.sub)) {
    // 已经过了24点
    let d = new Date()
    const time = d.getHours()
    const sub = (24 - time) * 1000 * 60 * 60
    localStorage.setItem(
      "HDB_oneDay",
      JSON.stringify({ sub, time: Date.now() })
    )
    globalApi.reportVisitDaily()
  }
} else {
  let d = new Date()
  const time = d.getHours()
  const sub = (24 - time) * 1000 * 60 * 60
  localStorage.setItem(
    "HDB_oneDay",
    JSON.stringify({ sub, time: Date.now() })
  )
  globalApi.reportVisitDaily()
}

window.globalApi = globalApi