import type React from 'react'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Badge } from '@/components/ui/badge'; import { CollapsibleSection } from '@/components/ui/CollapsibleSection'; import { Plus, Loader2 } from 'lucide-react'; import type { TaskMasterTask } from '../../webview/types'; import { getStatusDotColor } from '../constants'; interface SubtasksSectionProps { currentTask: TaskMasterTask; isSubtask: boolean; sendMessage: (message: any) => Promise; onNavigateToTask: (taskId: string) => void; } export const SubtasksSection: React.FC = ({ currentTask, isSubtask, sendMessage, onNavigateToTask }) => { const [isAddingSubtask, setIsAddingSubtask] = useState(false); const [newSubtaskTitle, setNewSubtaskTitle] = useState(''); const [newSubtaskDescription, setNewSubtaskDescription] = useState(''); const [isSubmittingSubtask, setIsSubmittingSubtask] = useState(false); const handleAddSubtask = async () => { if (!currentTask || !newSubtaskTitle.trim() || isSubtask) { return; } setIsSubmittingSubtask(true); try { await sendMessage({ type: 'addSubtask', data: { parentTaskId: currentTask.id, subtaskData: { title: newSubtaskTitle.trim(), description: newSubtaskDescription.trim() || undefined, status: 'pending' } } }); // Reset form and close setNewSubtaskTitle(''); setNewSubtaskDescription(''); setIsAddingSubtask(false); } catch (error) { console.error('❌ TaskDetailsView: Failed to add subtask:', error); } finally { setIsSubmittingSubtask(false); } }; const handleCancelAddSubtask = () => { setIsAddingSubtask(false); setNewSubtaskTitle(''); setNewSubtaskDescription(''); }; if ( !((currentTask.subtasks && currentTask.subtasks.length > 0) || !isSubtask) ) { return null; } const rightElement = ( <> {currentTask.subtasks && currentTask.subtasks.length > 0 && ( {currentTask.subtasks?.filter((st) => st.status === 'done').length}/ {currentTask.subtasks?.length} )} {!isSubtask && ( )} ); return (
{/* Add Subtask Form */} {isAddingSubtask && (

Add New Subtask

setNewSubtaskTitle(e.target.value)} className="w-full px-3 py-2 text-sm bg-vscode-input-background border border-vscode-input-border text-vscode-input-foreground placeholder-vscode-input-foreground/50 rounded focus:border-vscode-focusBorder focus:ring-1 focus:ring-vscode-focusBorder" disabled={isSubmittingSubtask} />