import { createApp } from 'vue';

import App from './App';
import router from './router/index';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import 'vant/lib/index.css';
import './component-ui/index.less';
import './styles/index.less';
import { promisefiyPostMessage, postMessage } from './helpers/native-message';
import { state } from './state';
import { storage } from '@/helpers/storage';
import { ACCESS_TOKEN } from '@/store/mutation-types';
import { setupStore } from './store';
import { Lazyload, setToastDefaultOptions } from 'vant';
import useErrorLog from './hooks/useErrorLog';
setToastDefaultOptions({ duration: 3000 });

// 获取token
promisefiyPostMessage({ api: 'getToken' }).then((res: any) => {
  const content = res.content;
  if (content?.accessToken) {
    storage.set(ACCESS_TOKEN, content.tokenType + ' ' + content.accessToken);
  }
});

// 导航栏高度
postMessage({ api: 'getNavHeight' }, (res: any) => {
  const { content } = res as any;
  const dpi = content.dpi || 2;
  if (content.navHeight) {
    const navHeight = content.navHeight / dpi;
    console.log(navHeight, 'navHeight');
    state.navBarHeight = navHeight;
  }
});

// import Vconsole from 'vconsole';
// const vconsole = new Vconsole();

const app = createApp(App);

app.use(Lazyload);

// store plugin: pinia
setupStore(app);

dayjs.locale('zh-ch');

app.use(router);

// 监听错误信息
const errorLog = useErrorLog();
errorLog.startListenErrorLog();

app.mount('#app');
