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

<script lang="ts">
import { useMainStore } from '@/stores/main';
import { storeToRefs } from 'pinia';
import type { RouteLocationNormalized, NavigationGuardNext } from 'vue-router';
import { onBeforeRouteUpdate } from 'vue-router';
export default {
  setup() {
    onBeforeRouteUpdate((to, from, next) =>{
      routeGuardAdmin(to, from, next);
    });
  },
  beforeRouteEnter(to, from, next){
    routeGuardAdmin(to, from, next);
  },
}
const routeGuardAdmin = async (to:RouteLocationNormalized, from:RouteLocationNormalized, next:NavigationGuardNext) => {
  const mainStore = useMainStore();
  const mainStoreRef = storeToRefs(mainStore);
  if (!mainStoreRef.readhasAdminAccess) {
    next('/main');
  } else {
    next();
  }
};

</script>