import { Navigate } from 'react-router-dom';
import { getStoredUser } from '../api';

function RoleRoute({ children, allowedRoles }) {
  const user = getStoredUser();

  if (!user || !allowedRoles.includes(user.role)) {
    return <Navigate to="/dashboard" replace />;
  }

  return children;
}

export default RoleRoute;
