export const checkMenuPermission = (
  menuItemName: string,
  userPermissions: string[] = []
): boolean => {
  if (userPermissions.includes("admin")) {
    return true;
  }

  const permissionMap: Record<string, string[]> = {
    users: ["admin", "add"],
    inspections: ["admin", "submit"],
    statics: [],
    nationalinfo: ["admin"],
  };

  const requiredPermissions = permissionMap[menuItemName] || [];

  if (requiredPermissions.length === 0) {
    return true;
  }

  return requiredPermissions.some((perm) => userPermissions.includes(perm));
};

export const checkRoutePermission = (
  routePath: string,
  userPermissions: string[] = []
): boolean => {
  if (userPermissions.includes("admin")) {
    return true;
  }

  const routePermissionMap: Record<string, string[]> = {
    "/users": ["admin", "add"],
    "/inspections": ["admin", "submit"],
    "/statics": [],
    "/nationalinfo": ["admin"],
  };

  const requiredPermissions = routePermissionMap[routePath] || [];

  if (requiredPermissions.length === 0) {
    return true;
  }

  return requiredPermissions.some((perm) => userPermissions.includes(perm));
};
