import { createRouter, createWebHistory } from "vue-router";
// import { useAuthentication } from "@actindo/core-ui";
import { routes } from "./routes";

const router = createRouter({
  history: createWebHistory(),
  routes,
});

// router.beforeEach((to) => {
// const authStore = useAuthentication();
// const isAuthorized = authStore.privileges?.length;
// const needAuthorization = !to.meta.unauthenticated;
// if (needAuthorization && !isAuthorized) {
//   // a NOT authenticated user is trying to access a route that needs authentication, present him the login instead
//   const redirectPath = to.path.includes("auth") ? "/" : to.path;
//   router.push({ name: "UnAuthorized", query: { to: redirectPath } });
// } else if (!needAuthorization && isAuthorized) {
//   // an authenticated user is trying to access a route that is only for NOT authenticated users, go to "/" instead
//   router.push({ name: "Start" });
// } else {
//   const lastRoute = to.matched[to.matched.length - 1];
//   if (lastRoute.children?.[0]?.path === "" && lastRoute.children[0].name) {
//     router.replace({ name: lastRoute.children[0].name });
//   }
// }
// });

export default router;
