import { createApp } from "vue";

import "./style.css";
import router from "./router";
import { setupStore } from "@/stores";
import App from "./App.vue";
import Vant from "vant";
import "vant/lib/index.css";
import "amfe-flexible";
import VueCookies from "vue-cookies";
// import storage, { actions } from "./utils/storage";
import Controller from "./socket/Controller.js";
import pixel from "./common/pixel.js";
import gtag from "./common/gtag.js";
import kwai from "./common/kwai.js";
import serviceWorker from "./common/service-worker.js";
import LazyPlugin from "./utils/lazyPlugin";
// import googleLogin from "@/common/google-login";
import VConsole from "vconsole";
import { Locale } from "vant";
import enUS from "vant/es/locale/lang/en-US";
Locale.use("en-US", enUS);



if (!JSON.parse(import.meta.env.VITE_OPEN_CONSOLE)) {
  new VConsole();
}

pixel();
gtag();
kwai();
serviceWorker();

// const token = storage.getStorage(actions.USER_TOEKN);

const app: any = createApp(App);

app.provide("$cookies", VueCookies);
app.provide("socket", new Controller());
app.provide("app", app);
app.use(LazyPlugin);
app.use(router);
app.use(Vant);
app.use(setupStore);
// googleLogin(app);
/**
 * 如果本地缓存token 调用token登录
 * 如果token 有效重新🔗socket
 */
// if (token) {
//   console.log('==================登录过后===================')
//   debugger
//   https.tokenLogin().then((res: ResultData) => {
//     if (res.code == 0) {
//       storage.setStorage(actions.USER_TOEKN, res.data.token)
//       new Controller().connect().then((status: boolean) => {
//         if (!status) {
//           storage.clearStorage();
//           // googleLogin(app);
//           app.mount("#app");
//         }
//         app.mount("#app");
//       });
//     } else {
//       // googleLogin(app);
//       storage.clearStorage();
//       app.mount("#app");
//     }
//   })
// } else {
//   app.mount("#app");
// }

// https.tokenLogin().then((res: ResultData) => {
//   console.log(res, '?reesssss')
//   if (res.code == 0) {
//     new Controller().connect()
//   }
// })

app.mount("#app");

export { app };
