import { createApp } from 'vue'
import 'normalize.css/normalize.css'
import 'nprogress/nprogress.css'
import './assets/less/index.less'
import App from './App.vue'
import router from './router/index.js'
import store from './store/index.js'
import axios from './plugins/axios.js'
import directives from './directives/index.js'
import bus, { EVENT_KEY } from './utils/bus'
import 'vant/lib/index.css'

;(window as Window).isMoved = false
;(window as Window).isMuted = true

function resetVhAndPx() {
  const vh = window.innerHeight * 0.01
  document.documentElement.style.setProperty('--vh', `${vh}px`)
}

resetVhAndPx()
window.addEventListener('resize', resetVhAndPx)

const app = createApp(App)

app.use(store)
app.use(router)
app.use(directives, { router, store })
app.use(axios as import('vue').Plugin, { router, store, opt: 'VE_API' })

app.mount('#app')

// 与 douyin-vue 一致：先静音自动播放，2 秒后取消静音
setTimeout(() => {
  ;(window as Window).isMuted = false
  bus.emit(EVENT_KEY.REMOVE_MUTED)
  bus.emit('HIDE_MUTED_NOTICE')
}, 2000)

bus.on(EVENT_KEY.REMOVE_MUTED, () => {
  ;(window as Window).isMuted = false
})
