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 { setAuth } from './helpers/utils';

// 获取token
promisefiyPostMessage({ api: 'getToken' }).then((res: any) => {
  console.log(res, 'res');
  const content = res.content;
  if (content?.accessToken) {
    setAuth(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);

dayjs.locale('zh-ch');

app.use(router);
app.mount('#app');
