'use client' import { useState, useEffect } from 'react' import { Task, TaskStatus } from '@/lib/mission-control/types' interface TaskCardsPanelProps { tasks: Task[] toggleTask: (id: string) => void } const projects = ['sitemente', 'holacompi', 'arabredox', 'infrastructure', 'trading'] export function TaskCardsPanel({ tasks, toggleTask }: TaskCardsPanelProps) { const [selectedProject, setSelectedProject] = useState('sitemente') const [selectedTaskId, setSelectedTaskId] = useState(null) const [command, setCommand] = useState('') const [responses, setResponses] = useState<{id: string, task: string, command: string, reply: string, createdAt: string}[]>([]) // Poll for replies every 10 seconds useEffect(() => { const pollReplies = async () => { try { const res = await fetch('/api/command-history') if (res.ok) { const data = await res.json() // Get entries with replies that haven't been shown const withReplies = (data.history || []).filter((h: any) => h.reply && h.reply.length > 0) setResponses(withReplies.slice(-5).reverse()) } } catch (e) {} } pollReplies() const interval = setInterval(pollReplies, 10000) return () => clearInterval(interval) }, []) const projectTasks = tasks.filter(t => t.project === selectedProject && (t.status === 'todo' || t.status === 'in_progress') ) const handleTaskClick = (taskId: string) => { setSelectedTaskId(selectedTaskId === taskId ? null : taskId) setCommand('') } const handleConfirm = () => { if (!selectedTaskId || !command.trim()) return const task = tasks.find(t => t.id === selectedTaskId) if (!task) return fetch('/api/command-history', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ task: task.title, command: command, project: selectedProject, action: 'continue-task' }) }).catch(() => {}) fetch('/api/command', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ command: command, task: task.title, action: 'continue-task' }) }).catch(() => {}) alert(`✅ Sent to Horus: "${command}"`) setCommand('') setSelectedTaskId(null) } const handleQuickChat = () => { if (!command.trim()) return // Save quick chat to history - this will notify Horus via the API fetch('/api/command-history', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ task: `Quick message - ${selectedProject}`, command: command, project: selectedProject, action: 'quick-message' }) }).catch(() => {}) alert(`✅ Sent to Horus! I'll reply shortly.`) setCommand('') } const selectedTask = tasks.find(t => t.id === selectedTaskId) return (
{/* Project Tabs */}
{projects.map(project => { const count = tasks.filter(t => t.project === project && (t.status === 'todo' || t.status === 'in_progress') ).length return ( ) })}
{/* Task Cards */}

📋 {selectedProject.toUpperCase()} TASKS ({projectTasks.length})

{projectTasks.map((task) => (
handleTaskClick(task.id)} >

{task.title}

{task.description && (

{task.description}

)}
{selectedTaskId === task.id ? '▼' : '▶'}
{/* Expanded Input */} {selectedTaskId === task.id && (