import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../domain/chat_shells.dart'; import '../ui/sessions/chat_adaptive.dart'; import 'chat_background_task_detail.dart'; import 'chat_background_tasks_controller.dart'; /// Scrollable modal content, backed by the same live controller as its badge. class ChatBackgroundTasksPanel extends StatelessWidget { const ChatBackgroundTasksPanel({super.key, required this.controller}); final ChatBackgroundTasksController controller; @override Widget build(BuildContext context) => ListenableBuilder( listenable: controller, builder: (context, _) { final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino; final running = controller.running; final shell = controller.selectedShell; final error = controller.error; return Column( key: const Key('chat-background-tasks'), mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ if (controller.loading) cupertino ? const CupertinoActivityIndicator() : const LinearProgressIndicator(), if (error != null) ...[ Text( 'Background tasks unavailable. $error', key: const Key('chat-background-tasks-error'), ), ChatBackgroundTaskButton( label: 'Retry', onPressed: controller.refresh, ), ] else if (!controller.loading && running.isEmpty) const Text('No background tasks running.'), if (running.isNotEmpty) Text(backgroundTasksRunningLabel(running.length)), for (final task in running) ...[ _taskRow(context, task, cupertino), if (shell != null && shellIdOf(task) == controller.selectedId) ChatBackgroundTaskDetail( key: const Key('chat-bg-task-detail'), shell: shell, output: controller.output, heightBudget: MediaQuery.sizeOf(context).height, onRefresh: controller.readOutput, ), ], ], ); }, ); Widget _taskRow( BuildContext context, Map shell, bool cupertino, ) { final id = shellIdOf(shell); final selected = controller.selectedId == id; final title = Text( shellCommandSummary(shell['command']), maxLines: 2, overflow: TextOverflow.ellipsis, ); if (cupertino) { return Semantics( selected: selected, child: CupertinoListTile( key: ValueKey('chat-bg-task-$id'), title: title, subtitle: const Text(shellRowLabel), backgroundColor: selected ? CupertinoColors.tertiarySystemFill.resolveFrom(context) : null, onTap: () => controller.select(id), ), ); } return ListTile( key: ValueKey('chat-bg-task-$id'), title: title, subtitle: const Text(shellRowLabel), selected: selected, onTap: () => controller.select(id), ); } }