import { Navigate } from 'react-router-dom';
import { useAuthStore } from '../../store/authStore';

/**
 * AuthGuard
 * Protects all authenticated routes.
 * Redirects unauthenticated users to /login.
 */
export function AuthGuard({ children }: { children: React.ReactNode }) {
  const { isAuthenticated } = useAuthStore();

  if (!isAuthenticated) {
    return <Navigate to="/login" replace />;
  }

  return <>{children}</>;
}
