import router from '@/router';
import store from '@/store';

/**
 * 动态隐藏或显示路由菜单
 * @param {string} pathName - 路由的 path 属性
 * @param {boolean} shouldHide - 是否隐藏路由
 */
export const toggleRouteVisibility = (pathName, shouldHide) => {
  const routes = router.options.routes;
  const findAndUpdateRoute = (routes) => {
    for (const route of routes) {

      if (route.path === pathName) {
        if (route.hidden) {
          route.hidden = shouldHide;
        } else {
          route = { hidden: shouldHide };
        }
        break;
      }
      // if (route.children) {
      //   findAndUpdateRoute(route.children);
      // }
    }
  };
 

  findAndUpdateRoute(routes);
  // 更新路由配置
  router.addRoutes(routes);

  // 刷新菜单数据（根据若依的实现）
  // store.dispatch('permission/GenerateRoutes', routes).then(() => {
  //   router.addRoutes(store.getters.permission_routes);
  // });
};
