"use client"; import { useMemo } from "react"; import { getCoursePlanGenerationErrorMessage, type CoursePlanGenerationError } from "./coursePlanApi"; interface LearnAnythingErrorStateProps { error: CoursePlanGenerationError; isGenerating: boolean; onRetry: () => void; canRetry: boolean; } /** * Error state display for the course-plan flow. * Shows appropriate error messages and retry options based on error type. */ export function LearnAnythingErrorState({ error, isGenerating, onRetry, canRetry, }: LearnAnythingErrorStateProps) { const message = useMemo(() => getCoursePlanGenerationErrorMessage(error), [error]); // Determine error type for styling const isAuthError = error.kind === "auth"; const isRateLimitError = error.kind === "rate-limit"; const isNetworkOrServerError = error.kind === "network" || error.kind === "server" || error.kind === "unknown"; return (
{/* Error Message */}

{message}

{/* Additional context for certain errors */} {isAuthError && (

Authentication required to generate course plans

)} {isRateLimitError && (

Free generation limit reached for now

)} {/* Retry button - only shown for retryable errors */} {canRetry && !isGenerating && (
)} {/* No retry for auth errors - just informational */} {isAuthError && !canRetry && (

Please sign in to access course plan generation

)} {/* No retry for rate limit - just informational */} {isRateLimitError && !canRetry && (

Your starter outline is still available above

)} {/* For other errors, show saved request info if available */} {isNetworkOrServerError && error.status && (

Error code: {error.status} {error.retryAfter && ` - Retry in ${error.retryAfter}s`}

)}
); }