import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import '../models/syncretic_session_model.dart'; import '../services/oracle_master_prompt_generator.dart'; import '../services/words_repository.dart'; import '../widgets/gradient_star_badge.dart'; class CrossSystemComparisonScreen extends StatefulWidget { final SyncreticSession session; const CrossSystemComparisonScreen({super.key, required this.session}); @override State createState() => _CrossSystemComparisonScreenState(); } class _CrossSystemComparisonScreenState extends State { final _repo = WordsRepository(); late SyncreticSession _session; @override void initState() { super.initState(); _session = widget.session; } void _showMasterPrompt() { HapticFeedback.mediumImpact(); final prompt = OracleMasterPromptGenerator.generateCrossSystemComparison(_session); showModalBottomSheet( context: context, isScrollControlled: true, backgroundColor: const Color(0xFF0F1222), shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(24)), ), builder: (ctx) { return DraggableScrollableSheet( initialChildSize: 0.85, minChildSize: 0.5, maxChildSize: 0.95, expand: false, builder: (context, scrollController) { return Container( padding: const EdgeInsets.fromLTRB(20, 12, 20, 20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Center( child: Container( width: 44, height: 4, decoration: BoxDecoration( color: Colors.white24, borderRadius: BorderRadius.circular(2), ), ), ), const SizedBox(height: 14), Row( children: [ const Icon(Icons.psychology_alt_rounded, color: Color(0xFFFFD54F), size: 24), const SizedBox(width: 10), const Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Великий Мета-Промпт Сравнения', style: TextStyle(color: Colors.white, fontSize: 17, fontWeight: FontWeight.bold), ), Text( 'Для Grok, Claude 3.5 Sonnet, GPT-4o, Gemini 1.5 Pro', style: TextStyle(color: Color(0xFF90A4AE), fontSize: 11), ), ], ), ), IconButton( icon: const Icon(Icons.close_rounded, color: Color(0xFF90A4AE)), onPressed: () => Navigator.pop(ctx), ), ], ), const SizedBox(height: 12), Row( children: [ Container( padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), decoration: BoxDecoration( color: const Color(0xFF1C223D), borderRadius: BorderRadius.circular(8), ), child: Text( '${prompt.length} симв. • ${_session.readings.length} систем', style: const TextStyle(color: Color(0xFF90CAF9), fontSize: 11), ), ), const Spacer(), ElevatedButton.icon( style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFFFD54F), foregroundColor: Colors.black, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8), ), onPressed: () { Clipboard.setData(ClipboardData(text: prompt)); HapticFeedback.heavyImpact(); ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Мета-промпт скопирован! Вставьте в Grok или Claude для сравнения.'), backgroundColor: Color(0xFF388E3C), behavior: SnackBarBehavior.floating, ), ); }, icon: const Icon(Icons.copy_rounded, size: 16), label: const Text('Скопировать всё', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12.5)), ), ], ), const SizedBox(height: 12), Expanded( child: Container( padding: const EdgeInsets.all(14), decoration: BoxDecoration( color: const Color(0xFF090A14), borderRadius: BorderRadius.circular(16), border: Border.all(color: const Color(0xFF232742), width: 1.0), ), child: SingleChildScrollView( controller: scrollController, child: SelectableText( prompt, style: const TextStyle( color: Color(0xFFECEFF1), fontFamily: 'monospace', fontSize: 11.5, height: 1.45, ), ), ), ), ), ], ), ); }, ); }, ); } void _confirmDeleteReading(SyncreticReading reading) { showDialog( context: context, builder: (ctx) => AlertDialog( backgroundColor: const Color(0xFF151829), title: const Text('Удалить расклад?', style: TextStyle(color: Color(0xFFFFF9C4), fontSize: 16, fontWeight: FontWeight.bold)), content: Text('Удалить «${reading.systemName} (${reading.layoutTitle})» из текущей сессии дня?', style: const TextStyle(color: Color(0xFFECEFF1), fontSize: 13)), actions: [ TextButton( onPressed: () => Navigator.pop(ctx), child: const Text('Отмена', style: TextStyle(color: Color(0xFF8C93B8))), ), ElevatedButton( style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFEF5350), foregroundColor: Colors.white), onPressed: () async { Navigator.pop(ctx); await _repo.removeReadingFromSyncreticSession(reading.id); setState(() { _session = _repo.currentSyncreticSession; }); HapticFeedback.mediumImpact(); }, child: const Text('Удалить'), ), ], ), ); } @override Widget build(BuildContext context) { final readings = _session.readings; return Scaffold( backgroundColor: const Color(0xFF0C0E1A), appBar: AppBar( title: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('Синхронистическая Сессия', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)), Text( '${_session.formattedDate} • ${readings.length} ${readings.length == 1 ? "гадание" : (readings.length < 5 ? "гадания" : "гаданий")}', style: const TextStyle(color: Color(0xFF8C93B8), fontSize: 11), ), ], ), actions: [ IconButton( tooltip: 'Великий Мета-Промпт', icon: const Icon(Icons.psychology_alt_rounded, color: Color(0xFFFFD54F)), onPressed: _showMasterPrompt, ), ], ), body: SingleChildScrollView( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ // Question Banner Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( gradient: const LinearGradient( colors: [Color(0xFF2A1F45), Color(0xFF17192E)], ), borderRadius: BorderRadius.circular(16), border: Border.all(color: const Color(0xFFFFD54F).withValues(alpha: 0.4)), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Row( children: [ GradientStar(size: 16), SizedBox(width: 8), Text( 'ФОКУС ВОПРОШАНИЯ ДНЯ', style: TextStyle( color: Color(0xFFFFD54F), fontSize: 11, fontWeight: FontWeight.w900, letterSpacing: 0.8, ), ), ], ), const SizedBox(height: 8), Text( _session.mainQuestion?.isNotEmpty == true ? '«${_session.mainQuestion!}»' : 'Общий срез судьбы и самосогласованность мантических систем.', style: const TextStyle( color: Color(0xFFFFF9C4), fontSize: 15, fontWeight: FontWeight.bold, height: 1.4, ), ), const SizedBox(height: 12), SizedBox( width: double.infinity, child: ElevatedButton.icon( style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFFFD54F), foregroundColor: Colors.black, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), padding: const EdgeInsets.symmetric(vertical: 11), ), onPressed: _showMasterPrompt, icon: const Icon(Icons.psychology_alt_rounded, size: 18), label: const Text( 'Сформировать Мета-Промпт для нейросетей', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13), ), ), ), ], ), ), const SizedBox(height: 20), Row( children: [ const Icon(Icons.history_edu_rounded, color: Color(0xFF80DEEA), size: 20), const SizedBox(width: 8), Text( 'ЛЕНТА РАСКЛАДОВ СЕССИИ (${readings.length})', style: const TextStyle( color: Color(0xFF80DEEA), fontSize: 13, fontWeight: FontWeight.w900, letterSpacing: 0.8, ), ), ], ), const SizedBox(height: 12), if (readings.isEmpty) Container( padding: const EdgeInsets.all(24), alignment: Alignment.center, decoration: BoxDecoration( color: const Color(0xFF151829), borderRadius: BorderRadius.circular(16), border: Border.all(color: const Color(0xFF2A2D4A)), ), child: const Text( 'В этой сессии пока нет проведённых гаданий.\nСделайте расклад в любой из систем (Оракул, Руны, Ленорман, Таро, И Цзин), и они появятся здесь.', textAlign: TextAlign.center, style: TextStyle(color: Color(0xFF8C93B8), fontSize: 13, height: 1.5), ), ) else for (int i = 0; i < readings.length; i++) ...[ _buildReadingCard(readings[i], i + 1), const SizedBox(height: 12), ], ], ), ), ); } Widget _buildReadingCard(SyncreticReading reading, int index) { return Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: const Color(0xFF151829), borderRadius: BorderRadius.circular(16), border: Border.all(color: const Color(0xFF2A2D4A)), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Container( width: 36, height: 36, alignment: Alignment.center, decoration: BoxDecoration( color: const Color(0xFF232742), borderRadius: BorderRadius.circular(10), border: Border.all(color: const Color(0xFFFFD54F).withValues(alpha: 0.4)), ), child: Text(reading.systemIcon, style: const TextStyle(fontSize: 18)), ), const SizedBox(width: 12), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( '#$index. ${reading.systemName}', style: const TextStyle( color: Color(0xFFFFF9C4), fontSize: 14, fontWeight: FontWeight.bold, ), ), Text( '${reading.formattedTime} • ${reading.layoutTitle}', style: const TextStyle(color: Color(0xFF8C93B8), fontSize: 11), ), ], ), ), IconButton( icon: const Icon(Icons.close_rounded, size: 20, color: Color(0xFFEF5350)), tooltip: 'Удалить из сессии', onPressed: () => _confirmDeleteReading(reading), ), ], ), const SizedBox(height: 12), const Divider(color: Color(0xFF2A2D4A), height: 1), const SizedBox(height: 10), for (final item in reading.items) ...[ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ if (item.symbol != null) ...[ Text( item.symbol!, style: const TextStyle(fontSize: 20, color: Color(0xFFFFD54F)), ), const SizedBox(width: 8), ], Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( item.title + (item.isReversed ? ' (перевёрнутая)' : ''), style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 13), ), if (item.subtitle != null) Text(item.subtitle!, style: const TextStyle(color: Color(0xFF80DEEA), fontSize: 11)), if (item.lore != null) Padding( padding: const EdgeInsets.only(top: 4), child: Text( item.lore!, maxLines: 2, overflow: TextOverflow.ellipsis, style: const TextStyle(color: Color(0xFFB0BEC5), fontSize: 11.5, height: 1.4), ), ), if (item.linkedWord != null) Padding( padding: const EdgeInsets.only(top: 4), child: Text( '🔗 Знак 999: #${item.linkedWord!.formattedSessionNumber} «${item.linkedWord!.word}»', style: const TextStyle(color: Color(0xFFFFD54F), fontSize: 11, fontWeight: FontWeight.bold), ), ), ], ), ), ], ), const SizedBox(height: 6), ], ], ), ); } }