'use client'; import { useState } from 'react'; import { Zap, ClipboardList, FileText, ScrollText, Loader2, Check, Eye, RefreshCw, Sparkles, } from 'lucide-react'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; import { cn } from '@/lib/utils'; import type { PlanSpec } from '@/store/app-store'; export type PlanningMode = 'skip' | 'lite' | 'spec' | 'full'; // Re-export for backwards compatibility export type { ParsedTask, PlanSpec } from '@/store/app-store'; interface PlanningModeSelectorProps { mode: PlanningMode; onModeChange: (mode: PlanningMode) => void; requireApproval?: boolean; onRequireApprovalChange?: (require: boolean) => void; planSpec?: PlanSpec; onGenerateSpec?: () => void; onApproveSpec?: () => void; onRejectSpec?: () => void; onViewSpec?: () => void; isGenerating?: boolean; featureDescription?: string; // For auto-generation context testIdPrefix?: string; compact?: boolean; // For use in dialogs vs settings } const modes = [ { value: 'skip' as const, label: 'Skip', description: 'Direct implementation, no upfront planning', icon: Zap, color: 'text-emerald-500', bgColor: 'bg-emerald-500/10', borderColor: 'border-emerald-500/30', badge: 'Default', }, { value: 'lite' as const, label: 'Lite', description: 'Think through approach, create task list', icon: ClipboardList, color: 'text-blue-500', bgColor: 'bg-blue-500/10', borderColor: 'border-blue-500/30', }, { value: 'spec' as const, label: 'Spec', description: 'Generate spec with acceptance criteria', icon: FileText, color: 'text-purple-500', bgColor: 'bg-purple-500/10', borderColor: 'border-purple-500/30', badge: 'Approval Required', }, { value: 'full' as const, label: 'Full', description: 'Comprehensive spec with phased plan', icon: ScrollText, color: 'text-amber-500', bgColor: 'bg-amber-500/10', borderColor: 'border-amber-500/30', badge: 'Approval Required', }, ]; export function PlanningModeSelector({ mode, onModeChange, requireApproval, onRequireApprovalChange, planSpec, onGenerateSpec, onApproveSpec, onRejectSpec, onViewSpec, isGenerating = false, featureDescription, testIdPrefix = 'planning', compact = false, }: PlanningModeSelectorProps) { const [showPreview, setShowPreview] = useState(false); const selectedMode = modes.find((m) => m.value === mode); const requiresApproval = mode === 'spec' || mode === 'full'; const canGenerate = requiresApproval && featureDescription?.trim() && !isGenerating; const hasSpec = planSpec && planSpec.content; return (
{/* Header with icon */}
{selectedMode && }

Choose how much upfront planning before implementation

{/* Quick action buttons when spec/full mode */} {requiresApproval && hasSpec && (
)}
{/* Mode Selection Cards */}
{modes.map((m) => { const isSelected = mode === m.value; const Icon = m.icon; return ( ); })}
{/* Require Approval Checkbox - Only show when mode !== 'skip' */} {mode !== 'skip' && onRequireApprovalChange && (
onRequireApprovalChange(checked === true)} data-testid={`${testIdPrefix}-require-approval-checkbox`} />
)} {/* Spec Preview/Actions Panel - Only for spec/full modes */} {requiresApproval && (
{/* Status indicator */}
{isGenerating ? ( <> Generating {mode === 'full' ? 'comprehensive spec' : 'spec'}... ) : planSpec?.status === 'approved' ? ( <> Spec Approved ) : planSpec?.status === 'generated' ? ( <> Spec Ready for Review ) : ( <> Spec will be generated when feature starts )}
{/* Auto-generate toggle area */} {!planSpec?.status && canGenerate && onGenerateSpec && ( )}
{/* Spec content preview */} {hasSpec && (
{showPreview && (
                      {planSpec.content}
                    
)}
)} {/* Action buttons when spec is generated */} {planSpec?.status === 'generated' && (
)} {/* Regenerate option when approved */} {planSpec?.status === 'approved' && onGenerateSpec && (
)}
)} {/* Info text for non-approval modes */} {!requiresApproval && (

{mode === 'skip' ? 'The agent will start implementing immediately without creating a plan or spec.' : "The agent will create a planning outline before implementing, but won't wait for approval."}

)}
); }