import './assets/css/main.css'

import { createApp } from 'vue'
import App from './App.vue'
import router, { loadDynamicPages } from './router'
import { createPinia } from 'pinia'
// i18n
import { i18n } from "./i18n";
import VueCountdown from '@chenfengyuan/vue-countdown';
import { useFooterLinksStore } from '@/stores/footer-content-pages'
import { useTimelineStore } from '@/stores/timeline'
import { useComponentStore } from '@/stores/component'
import { usePageStore } from '@/stores/pages'


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

app.use(pinia)
   .use(i18n)
   const urlParams = new URLSearchParams(window.location.search);
   let lang = localStorage.getItem('lang') || 'de'
   if(urlParams.has('lang') && urlParams.get('lang') != lang){
     lang = urlParams.get('lang')!
     i18n.global.locale = i18n.global.availableLocales.find((value)=>value ==lang )!
     await setTimeout(()=>{localStorage.setItem('lang', lang!)}, 1000)
   }
const pageStroe = usePageStore()
await pageStroe.setLocale(lang)
await useFooterLinksStore().setLocale(lang)
await useTimelineStore().setLocale(lang)
await useComponentStore().setLocale(lang)
loadDynamicPages(pageStroe.pages)
app.use(router)
app.component(VueCountdown.name!, VueCountdown)

app.mount('#app')
