/**
 * TaskListView - Render task list
 * INV: renders projection only; never mutates domain tables.
 *
 * @module packages/tui/src/components/TaskListView
 */

import type { TaskProjection } from '../types.js'

export interface TaskListViewProps {
  tasks: TaskProjection[]
}

export function TaskListView({ tasks }: TaskListViewProps): string {
  if (tasks.length === 0) return '(no tasks)'

  const lines: string[] = ['Tasks:', '']

  for (const task of tasks) {
    const status_icon = task.status === 'completed' ? '✅' : task.status === 'failed' ? '❌' : task.status === 'running' ? '🔄' : '⏳'
    lines.push(`  ${status_icon} ${task.id}  [${task.type}] ${task.title}  (${task.status}, retries: ${task.retry_count})`)
  }

  return lines.join('\n')
}
