import { createApp } from 'vue'
import App from './App.vue'
import router from '../router/index'
// import { postMessage } from '@/helpers/native-message'
import 'vant/lib/index.css';
import 'normalize.css'

import '../styles/index.less'
import { promisefiyPostMessage } from '@/helpers/native-message';
import { setAuth } from './music-group/layout/utils';
import { browser } from '@/helpers/utils';
import { state } from '@/state';

// 获取token
promisefiyPostMessage({ api: 'getToken' }).then((res: any) => {
  console.log(res, 'res')
  const content = res.content
  if (content?.accessToken) {
    setAuth(content.tokenType + ' ' + content.accessToken)
  }
})

const paymentType = (window as any).paymentType // 浏览器设置
if (browser().isTeacher || paymentType === 'TEACHER') {
  state.platformType = 'TEACHER'
} else if (browser().isStudent || paymentType === 'STUDENT') {
  state.platformType = 'STUDENT'
} else if (browser().isSchool || paymentType === 'SCHOOL') {
  state.platformType = 'SCHOOL'
} else {
  state.platformType = 'STUDENT'
}
if (state.platformType === 'TEACHER') {
  state.platformApi = '/api-teacher'
} else if (state.platformType === 'SCHOOL') {
  state.platformApi = '/api-school'
} else if (state.platformType === 'STUDENT') {
  state.platformApi = '/api-student'
} else {
  state.platformApi = '/api-student'
}


// import Vconsole from 'vconsole'
// const vconsole = new Vconsole()
const app = createApp(App)
app.use(router)

app.mount('#app')
