import { i18nextInit } from "@/i18nextWrapper";
import * as Sentry from "@sentry/vue";
import i18next from "i18next";
import I18NextVue from "i18next-vue";
import * as log from "loglevel";
import { createPinia } from "pinia";
import { createApp, markRaw } from "vue";
import type { Router } from "vue-router";
import "../tailwind.css";
import App from "./App.vue";
import router from "./router";

declare module "pinia" {
  export interface PiniaCustomProperties {
    router: Router;
  }
}

const appEnv = import.meta.env.VITE_APP_ENVIRONMENT || "local";

if (appEnv.startsWith("prod")) {
  log.setLevel("warn");
} else {
  log.setLevel("trace");
}

const commit = "VBV_VERSION_BUILD_NUMBER_VBV";
log.warn(`application started appEnv=${appEnv}, build=${commit}`);

const app = createApp(App);

app.use(router);
const pinia = createPinia();
pinia.use(({ store }) => {
  store.router = markRaw(router);
});
app.use(pinia);

Sentry.init({
  app,
  environment: appEnv,
  dsn: "https://2df6096a4fd94bd6b4802124d10e4b8d@o8544.ingest.sentry.io/4504157846372352",
  tracesSampleRate: 0.0,
  enabled: appEnv.startsWith("prod") || appEnv.startsWith("stage"),
});

i18nextInit().then(() => {
  app.use(I18NextVue, { i18next });
  app.mount("#app");
});
