import {useContext} from "react";
import {AuthContext} from "../AuthProvider";

const PermissionGuard = ({rolesRequired, children}) => {
    const { roles = [] } = useContext(AuthContext);
    const hasPermission = rolesRequired.some((role) => roles.includes(role));

    if (!hasPermission) {
        return null;
    }
    return children;
}

export default PermissionGuard;