import { createApp } from 'vue'
import router from './router'
import App from './App.vue'
import 'lib-flexible/flexible'
// import Bugsnag from '@bugsnag/js'
// import BugsnagPluginVue from '@bugsnag/plugin-vue'
import detaistate from '/src/pages/detail/state'
import appstate, { IAuthKey } from './state'
import 'vant/lib/index.css'
import './app.less'
import './base.css'
import './index.css'
import { setTongjiTag } from '/src/helpers/utils'

// Bugsnag.start({
//   apiKey: 'c19866301f731dce31111f3915dc2a0b',
//   plugins: [new BugsnagPluginVue()]
// })

// const bugsnagVue: any = Bugsnag.getPlugin('vue')

router.beforeEach((to, from, next) => {
  const title: string = (to.meta as any).title || '管乐迷'
  if (title) {
    document.title = title
  }
  next()
})

createApp(App)
  // .use(bugsnagVue)
  .use(router)
  .mixin({
    methods: {
      authBefore(key: IAuthKey, cb: () => void) {
        if (appstate.modular[key]) {
          return () => {
            setTongjiTag(['_trackEvent', '云练习', '操作', appstate.modularDetail[key]?.name])
            cb()
          }
        } else {
          return () => {
            setTongjiTag(['_trackEvent', '云练习', '提示无权限', appstate.modularDetail[key]?.name])
            detaistate.feeShow = true
            appstate.openKey = key
          }
        }
      },
    },
  })
  .mount('#app')
