import { $axios } from '@/plugins/axios';
import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router';
import { useAuthStore } from '@/stores/auth';
import { usePermissionsStore } from '@/stores/permissions';

export default async function (
  _to: RouteLocationNormalized,
  _from: RouteLocationNormalized,
  _next: NavigationGuardNext,
) {
  if (!$axios) {
    return console.error('app $axios instance not injected');
  }

  // const $auth = useAuthStore();

  // if (!$auth.loggedIn) {
  //   return;
  // }

  const $permissions = usePermissionsStore();

  if (!$permissions.exist()) {
    $permissions.getAll();
  }
}
