import * as Sentry from "@sentry/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 { loadLocaleMessages, setupI18n } from "./i18n";
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 i18n = setupI18n();
const app = createApp(App);

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

// todo: define lang setup
loadLocaleMessages("de").then(() => {
  app.use(router);

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

  app.mount("#app");
});
