/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */

export default function access(initialState: {
  currentUser?: API.CurrentUser | undefined;
  routeList: any;
}) {
  const { currentUser, routeList } = initialState || {};
  return {
    canAdmin: currentUser && currentUser.access === 'admin',
    normalRouteFilter: (route: any) => {
      // return true;
      if (routeList == null || routeList == undefined || routeList.length == 0) {
        return true;
      }
      return routeList.includes(route.name);
    },
  };
}
