import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import router from './router'
import i18n from './i18n'
import './style.css'
import App from './App.vue'

// Force unregister service workers to clear cache for now
if ('serviceWorker' in navigator) {
    navigator.serviceWorker.getRegistrations().then((registrations) => {
        for (const registration of registrations) {
            registration.unregister();
        }
    });
}

const app = createApp(App)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

app.use(pinia)
app.use(router)
app.use(i18n)

app.config.errorHandler = (err, _vm, info) => {
    console.error('Global Error Handler:', err, info)
    // Display error on screen if possible or alert for dev
    if (import.meta.env.DEV) {
        alert('Frontend Error: ' + err)
    }
}

app.mount('#app')
