import "element-plus/theme-chalk/el-message.css";
import "element-plus/theme-chalk/el-message-box.css";
import "vant/lib/index.css";
import "./styles/base.css";
import "./styles/pc.css";
import "./styles/admin.css";

import { createPinia } from "pinia";
import { createApp } from "vue";

import App from "./App.vue";
import router from "./router";
import { useAdminSessionStore } from "./stores/adminSession";
import { useSessionStore } from "./stores/session";

const app = createApp(App);
const pinia = createPinia();

app.use(pinia).use(router);

window.addEventListener("auth-storage-changed", () => {
  useSessionStore(pinia).syncFromStorage();
  useAdminSessionStore(pinia).syncFromStorage();
});

window.addEventListener("storage", (event) => {
  if (event.storageArea === localStorage) {
    useSessionStore(pinia).syncFromStorage();
    useAdminSessionStore(pinia).syncFromStorage();
  }
});

router.isReady().then(() => app.mount("#app"));
