import { useState } from "react"; import type { Todo, Priority } from "../types/todo"; interface TodoItemProps { /** The todo data to render */ todo: Todo; /** Called when the checkbox is toggled */ onToggle: (id: string) => void; /** Called when the delete button is clicked */ onDelete: (id: string) => void; /** Called when the todo is updated */ onUpdate: (id: string, updates: Partial>) => void; /** Enable inline editing mode on mount */ autoEdit?: boolean; } export function TodoItem({ todo, onToggle, onDelete, onUpdate, autoEdit = false }: TodoItemProps) { const [editing, setEditing] = useState(autoEdit); const [editTitle, setEditTitle] = useState(todo.title); const isOverdue = !todo.completed && todo.dueDate && new Date(todo.dueDate) < new Date(); const handleSave = () => { if (editTitle.trim()) { onUpdate(todo.id, { title: editTitle.trim() }); } setEditing(false); }; return (
onToggle(todo.id)} /> {editing ? ( setEditTitle(e.target.value)} onBlur={handleSave} autoFocus /> ) : ( setEditing(true)}>{todo.title} )} {todo.description &&

{todo.description}

}
{todo.priority} {todo.tags.map((tag) => {tag})} {isOverdue && overdue}
); }