import 'package:flutter/material.dart'; import '../../../core/error_reason.dart'; import 'chat_efforts.dart'; /// The thinking-level chooser of a chat: the levels with the current one /// checked, in a Material dialog. It stays open with the server's reason when /// a choice is refused and closes once one is accepted. /// /// Nothing opens it now: the effort control shows its levels in an anchored /// menu. The class stays so existing references keep compiling. class ChatEffortSheet extends StatefulWidget { const ChatEffortSheet({ super.key, required this.state, required this.running, required this.choose, }); final ChatEffortState state; final bool running; final Future Function(ChatEffortLevel level) choose; @override State createState() => _ChatEffortSheetState(); } class _ChatEffortSheetState extends State { bool _busy = false; String? _error; Future _choose(ChatEffortLevel level) async { if (_busy) return; if (level.id == widget.state.effort) { Navigator.of(context).pop(); return; } setState(() { _busy = true; _error = null; }); try { await widget.choose(level); if (mounted) Navigator.of(context).pop(); } catch (error) { if (!mounted) return; setState(() { _busy = false; _error = describeErrorReason( error, fallback: 'The thinking level was not changed.', ); }); } } @override Widget build(BuildContext context) { final scheme = Theme.of(context).colorScheme; final error = _error; return AlertDialog( key: const Key('chat-effort-sheet'), title: const Text('Thinking'), content: SingleChildScrollView( child: ListBody( children: [ Text( error ?? chatEffortNote(running: widget.running), key: const Key('chat-effort-note'), style: error == null ? null : TextStyle(color: scheme.error), ), for (final level in widget.state.levels) ListTile( key: ValueKey('chat-effort-option-${level.id}'), title: Text(level.name), subtitle: level.description.isEmpty ? null : Text(level.description), trailing: level.id == widget.state.current ? const Icon(Icons.check) : null, onTap: () => _choose(level), ), ], ), ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: const Text('Cancel'), ), ], ); } }