<script setup lang="ts">
import { App as CapacitorApp } from "@capacitor/app";

const userStore = useUserStore();
const { isAuthenticated } = storeToRefs(userStore);
const { loadSavedLanguage } = useLanguage();

onBeforeMount(() => {
  loadSavedLanguage();
});

onMounted(() => {
  if (!isAuthenticated.value)
    return;
  userStore.updateProfile();
  CapacitorApp.addListener("appStateChange", ({ isActive }) => {
    if (isActive) {
      userStore.updateProfile();
    }
  });
});
</script>

<template>
  <IonApp>
    <Suspense>
      <IonRouterOutlet />
    </Suspense>
  </IonApp>
</template>
