import { createApp } from 'vue'
import i18n from './i18n'
import { createVuestic, useToast } from 'vuestic-ui'
import { createGtm } from '@gtm-support/vue-gtm'
import stores from './stores'
import router from './router'
import vuesticGlobalConfig from './services/vuestic-ui/global-config'
import App from './App.vue'
import api from './api/api'
import VueAMap, {initAMapApiLoader} from '@vuemap/vue-amap';
import '@vuemap/vue-amap/dist/style.css'
initAMapApiLoader({
  key: 'a1ae930c41668c400b2b8ccc0270c5cb',
  securityJsCode: '031ab4952072e0533e9845762d120ffe', // 新版key需要配合安全密钥使用
  //Loca:{
  //  version: '2.0.0'
  //} // 如果需要使用loca组件库，需要加载Loca
})

const app = createApp(App)
app.config.globalProperties.$api = api
let toastObj = {
  success(params) {
    useToast().init({ title: '提示', message: params.message, duration: 2000, color: '#3D9209', closeable: false })
  },
  message(params) {
    useToast().init({ title: '提示', message: params.message, duration: 2000, color: '#154EC1', closeable: false })
  },
  error(params) {
    useToast().init({ title: '提示', message: params.message, duration: 2000, color: '#E42222', closeable: false })
  },
  warning(params) {
    useToast().init({ title: '提示', message: params.message, duration: 2000, color: '#FFD43A', closeable: false })
  },
}
app.config.globalProperties.$toast = toastObj
app.use(stores)
app.use(router)
app.use(i18n)
app.use(VueAMap)
app.use(createVuestic({ config: vuesticGlobalConfig }))
if (import.meta.env.VITE_APP_GTM_ENABLED) {
  app.use(
    createGtm({
      id: import.meta.env.VITE_APP_GTM_KEY,
      debug: false,
      vueRouter: router,
    }),
  )
}

app.mount('#app')
