import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../ui/motion/quick_switch_animation.dart'; import '../chat/workspace/chat_workspace.dart'; import 'settings_theme.dart'; /// The real workspace renderer, with local miniature chats. Previewing never /// opens an operator chat, changes a saved pane layout or contacts the server. class QuickSwitchPreview extends StatefulWidget { const QuickSwitchPreview({super.key, required this.animation}); final QuickSwitchAnimation animation; @override State createState() => _QuickSwitchPreviewState(); } class _QuickSwitchPreviewState extends State { late final ChatWorkspaceController _panes; @override void initState() { super.initState(); _panes = ChatWorkspaceController()..open('First chat'); _panes.splitActive('Second chat', ChatSplitAxis.horizontal); _schedulePreview(); } @override void didUpdateWidget(QuickSwitchPreview oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.animation != widget.animation) _schedulePreview(); } void _schedulePreview() { WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted && !MediaQuery.disableAnimationsOf(context)) _replay(); }); } void _replay() { final next = _panes.panes.firstWhere((p) => p.id != _panes.activePaneId); _panes.activate(next.id); } @override void dispose() { _panes.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final reduced = MediaQuery.disableAnimationsOf(context); final cupertino = usesCupertinoControls(context); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Wrap( alignment: WrapAlignment.spaceBetween, crossAxisAlignment: WrapCrossAlignment.center, children: [ Text('Preview', style: settingsTextStyle(context, title: true)), cupertino ? CupertinoButton( onPressed: reduced ? null : _replay, child: const Text('Replay animation'), ) : TextButton.icon( onPressed: reduced ? null : _replay, icon: const Icon(Icons.replay), label: const Text('Replay animation'), ), ], ), Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 420), child: AspectRatio( aspectRatio: 1.6, child: Semantics( identifier: 'quick-switch-preview', label: '${widget.animation.label} animation preview', image: true, child: ExcludeSemantics( child: IgnorePointer( child: ClipRRect( borderRadius: BorderRadius.circular(12), child: ChatWorkspace( controller: _panes, animationStyle: widget.animation, shortcutsEnabled: false, singlePane: true, mobilePeeks: true, paneBuilder: (context, pane, active) => _PreviewChat( title: pane.sessionId, alternate: pane.sessionId == 'Second chat', ), ), ), ), ), ), ), ), ), if (reduced) const Padding( padding: EdgeInsets.only(top: 8), child: Text('Reduced motion is enabled. Preview stays still.'), ), ], ); } } class _PreviewChat extends StatelessWidget { const _PreviewChat({required this.title, required this.alternate}); final String title; final bool alternate; @override Widget build(BuildContext context) { final cupertino = usesCupertinoControls(context); final color = cupertino ? (alternate ? CupertinoColors.systemTeal : CupertinoColors.systemBlue) .resolveFrom(context) : (alternate ? Theme.of(context).colorScheme.tertiary : Theme.of(context).colorScheme.primary); final background = cupertino ? CupertinoColors.secondarySystemGroupedBackground.resolveFrom(context) : Theme.of(context).colorScheme.surfaceContainerHigh; return DecoratedBox( decoration: BoxDecoration( color: background, border: Border.all(color: color.withValues(alpha: .5)), borderRadius: BorderRadius.circular(12), ), child: LayoutBuilder( builder: (context, constraints) => SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(title, style: settingsTextStyle(context, title: true)), if (constraints.maxHeight > 80) ...[ const SizedBox(height: 12), for (final width in [0.65, 0.85, 0.5]) Padding( padding: const EdgeInsets.only(bottom: 8), child: FractionallySizedBox( widthFactor: width, child: SizedBox( height: 8, child: ColoredBox( color: color.withValues(alpha: .18), ), ), ), ), Text( 'Draft a reply…', style: settingsTextStyle(context, secondary: true), ), ], ], ), ), ), ), ); } }