import useUser from "@/lib/app/hooks/useUser";
import RolePermissionComponent from "@/core/components/Middleware/RolePermissionComponent";

const RolePermissionMiddleware = ({children, requiredPermissions = []}) => {
    const {user} = useUser();

    const hasPermission = requiredPermissions.length === 0 ? true : requiredPermissions.some((permission) =>
        user?.permissions?.includes(permission)
    );

    return !hasPermission ? <RolePermissionComponent/> : <>{children}</>;
};

export default RolePermissionMiddleware;
