import { createApp } from "vue";
import { createPinia } from "pinia";
import { MotionPlugin } from "@vueuse/motion";
import App from "./App.vue";
import { createHead } from "@unhead/vue/client";
import router from "./router";
import i18n from "./i18n";
import "./index.css";

// Handle dynamic import failures (assets deleted after deploy)
/* 
window.addEventListener('vite:preloadError', () => {
  console.warn('Vite preload error detected, reloading page for fresh assets...');
  window.location.reload();
});
*/

const app = createApp(App);

app.use(createPinia());
app.use(createHead());

app.use(MotionPlugin);
app.use(router);
app.use(i18n);

// Wait for router to be ready before mounting and rendering
router.isReady().then(() => {

  app.mount("#root");
  
  // Dispatch event for prerendering
  setTimeout(() => {
    document.dispatchEvent(new Event("render-event"));
  }, 500);
});
