import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:cutdex_ui/theme.dart'; import '../../workspace/project_state.dart'; import '../projects/conversation_sidebar.dart'; import 'agent_chat_panel.dart'; import 'agent_panel_presentation.dart'; import 'floating_agent_panel.dart'; import 'agent_composer_store.dart'; import 'composer_project_selector.dart'; /// Shared conversation presentation, independent of the navigation sidebar. class WorkspaceAgentSurface extends ConsumerWidget { const WorkspaceAgentSurface({ super.key, required this.state, required this.onSelectProject, required this.onCreateProject, this.showProjectSelector = true, }); final ProjectState state; final ValueChanged? onSelectProject; final VoidCallback? onCreateProject; final bool showProjectSelector; @override Widget build(BuildContext context, WidgetRef ref) { final selection = ref.watch( conversationSelectionProvider(state.activeProject?.id), ); final conversations = ref.read(conversationSidebarProvider.notifier); final composers = ref.watch(agentComposerStoreProvider); final projectId = state.activeProject?.id; final conversationId = selection.selectedId; final presentation = AgentPanelPresentation.of(context); if (presentation?.compact == true) { return FloatingAgentPanel( state: state, selection: selection, input: composers.input( projectId, conversationId, projectScoped: !showProjectSelector, ), composer: composers.composer( projectId, conversationId ?? selection.draftKey, ), expanded: presentation!.expanded, onToggleExpanded: presentation.onToggleExpanded!, onDock: presentation.onDock!, onConversationCreated: (item) => unawaited( conversations.updateListing( item, selectIfDraftKey: selection.draftKey, ), ), onConversationUpdated: (item) => unawaited(conversations.updateListing(item)), ); } return AgentChatPanel( key: ValueKey((projectId, conversationId ?? selection.draftKey)), inputController: composers.input( projectId, conversationId, projectScoped: !showProjectSelector, ), composer: composers.composer( projectId, conversationId ?? selection.draftKey, ), projectSelector: showProjectSelector ? ComposerProjectSelector( backgroundColor: AppTheme.composerUtilityBackground(context), projects: state.recent, selected: state.activeProject, busy: state.projectBusy, onSelect: (project) => onSelectProject?.call(project), onCreate: onCreateProject, ) : null, composerColor: AppSurfaces.of(context).composerBackground, projectId: projectId, timelineId: state.timeline?.id, conversationId: conversationId, draftKey: conversationId == null ? selection.draftKey : null, onConversationCreated: (item) => unawaited( conversations.updateListing(item, selectIfDraftKey: selection.draftKey), ), onConversationUpdated: (item) => unawaited(conversations.updateListing(item)), ); } }