import { createApp } from 'vue';
import App from './App.vue';
import './registerServiceWorker';
import router from './router';
import store from './store';
import Vant from 'vant';
import { ConfigProvider } from 'vant';
import 'vant/lib/index.css';
import './styles/app.less';
import './styles/font.less';
import http from './plugins/http';
// import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
import PageTitle from './components/PageTitle';
import LikeButton from './components/LikeButton.vue';
import Driver from './components/Driver.vue';
import common from './mixins/common';
import VueClipboard from 'vue-clipboard2';
import queryString from 'query-string';
// import VConsole from 'vconsole';
// const vConsole = new VConsole();
store.commit('setFirstUrl', location.href);

http.http
    .get('/wx/jsapiSign', { url: location.href })
    .then(res => {
        wx.config({
            debug: false,
            appId: res.appId,
            timestamp: res.timestamp,
            nonceStr: res.nonceStr,
            signature: res.signature,
            jsApiList: [
                'chooseWXPay',
                'updateAppMessageShareData',
                'updateTimelineShareData',
                'hideAllNonBaseMenuItem',
                'scanQRCode'
            ]
        });
        wx.error(function (res) {
            console.log(res);
        });
        wx.ready(function () {
            wx.updateAppMessageShareData({
                title: '第九空间',
                desc: '全球首个基于区块链的游戏资产集换中心',
                link: location.origin + '/9th',
                imgUrl: 'https://9space-2021.oss-cn-shenzhen.aliyuncs.com/nft/2021-11-05-15-58-30YwqLzMjy.jpg'
            });
            wx.updateTimelineShareData({
                title: '第九空间-全球首个基于区块链的游戏资产集换中心',
                link: location.origin + '/9th',
                imgUrl: 'https://9space-2021.oss-cn-shenzhen.aliyuncs.com/nft/2021-11-05-15-58-30YwqLzMjy.jpg'
            });
        });
    })
    .catch(e => {});

createApp(App)
    .use(Vant)
    .use(http)
    // .use(ElementUI)
    .use(ConfigProvider)
    .use(VueClipboard)
    .mixin(common)
    .component('page-title', PageTitle)
    .component('like-button', LikeButton)
    .component('driver', Driver)
    .use(store)
    .use(router)
    .mount('#app');

let query = queryString.parse(location.search);
if (query.code) {
    http.http.post('/user/code2openId', { code: query.code }).then(res => {
        localStorage.setItem('openId', res);
    });
} else {
    if (/micromessenger/i.test(navigator.userAgent) && !/localhost|(192\.168)/i.test(location.host)) {
        document.location.replace('https://nft.9space.vip/wx/redirect?redirectUrl=' + location.href);
    }
}
if (query.invitor) {
    store.commit('setInvitor', query.invitor);
}
