import NProgress from "nprogress";
import { setToken } from "@/utils/auth";

/**
 * 简易权限守卫（无 store）
 * - URL 带 token 时写入本地
 * - 设置 document.title
 */
export default {
  install: (app, { router }) => {
    router.beforeEach((to, from, next) => {
      if (to.query.token) {
        setToken(to.query.token);
      }

      if (to.meta?.title) {
        document.title = to.meta.title;
      }

      NProgress.start();
      next();
    });

    router.afterEach(() => {
      NProgress.done();
    });
  },
};
