import { useState, useCallback, useEffect, useRef } from "react"; import { Link } from "lucide-react"; import type { Task, TaskCreateInput } from "@hai/core"; import type { ToastType } from "../hooks/useToast"; interface InlineCreateCardProps { tasks: Task[]; onSubmit: (input: TaskCreateInput) => Promise; onCancel: () => void; addToast: (msg: string, type?: ToastType) => void; } export function InlineCreateCard({ tasks, onSubmit, onCancel, addToast }: InlineCreateCardProps) { const [description, setDescription] = useState(""); const [dependencies, setDependencies] = useState([]); const [showDeps, setShowDeps] = useState(false); const [submitting, setSubmitting] = useState(false); const inputRef = useRef(null); const cardRef = useRef(null); useEffect(() => { inputRef.current?.focus(); }, []); const handleKeyDown = useCallback( async (e: React.KeyboardEvent) => { if (e.key === "Escape") { e.preventDefault(); onCancel(); return; } if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); if (!description.trim() || submitting) return; setSubmitting(true); try { const task = await onSubmit({ description: description.trim(), column: "triage", dependencies: dependencies.length ? dependencies : undefined, }); addToast(`Created ${task.id}`, "success"); } catch (err: any) { addToast(err.message, "error"); } finally { setSubmitting(false); } } }, [description, dependencies, submitting, onSubmit, onCancel, addToast], ); const toggleDep = useCallback((id: string) => { setDependencies((prev) => prev.includes(id) ? prev.filter((d) => d !== id) : [...prev, id], ); }, []); const truncate = (s: string, len: number) => s.length > len ? s.slice(0, len) + "…" : s; return (