<script setup>
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
import useLoader from '@Stores/Loader';
import { hasToken } from '@Services/Api';

const PUBLIC_PATHS = ['/factura/'];

/** Definidores */
const router = useRouter();
const loader = useLoader();

/** Ciclos */
onMounted(async () => {
    await router.isReady();

    const currentPath = router.currentRoute.value.path;

    if (PUBLIC_PATHS.some(prefix => currentPath.startsWith(prefix))) return;

    if(!hasToken()) {
        return router.push({ name: 'auth.index' })
    }

    loader.boot()
})
</script>

<template>
    <router-view />
</template>