import App from './App.vue';
import router from './router';
import { getAppEnvConfig } from './utils';
import { persistToIndexedDB } from './plugins';
import '@/styles/reset.scss';
import { VueQueryPlugin } from '@tanstack/vue-query';
import localforage from 'localforage';
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import persist from 'pinia-plugin-persistedstate';

const { storageVersion } = getAppEnvConfig();
const localStorageVersion = window.localStorage.getItem('ndm-storage-version');
if (localStorageVersion !== storageVersion) {
  window.localStorage.clear();
  window.localStorage.setItem('ndm-storage-version', storageVersion);
  await localforage.clear();
}

document.title = import.meta.env.VITE_APP_TITLE;

const pinia = createPinia();
pinia.use(persist);
pinia.use(persistToIndexedDB);

const app = createApp(App);
app.use(pinia);
app.use(router);
app.use(VueQueryPlugin);

app.mount('#app');
