import { useState } from 'react'; import { useRouter } from 'next/router'; import { useAuth } from '../src/context/AuthContext'; import GoalSelector from '../src/components/plans/GoalSelector'; import PlanParameters from '../src/components/plans/PlanParameters'; import { generatePlan } from '../src/services/planService'; import ProgressTracker from '../src/components/ui/ProgressTracker'; const PlanGeneration = () => { const { apiKey } = useAuth(); const router = useRouter(); const [step, setStep] = useState(1); const [goals, setGoals] = useState([]); const [rules, setRules] = useState([]); const [params, setParams] = useState({ duration: 4, weeklyHours: 8, availableDays: [] }); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleGenerate = async () => { try { setLoading(true); const plan = await generatePlan(apiKey, { goals, ruleIds: rules, ...params }); router.push(`/plans/${plan.id}/preview`); } catch (err) { setError('Failed to generate plan. Please try again.'); } finally { setLoading(false); } }; return (
{error}
}