import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../core/theme/app_colors.dart'; class MobileScaffold extends ConsumerWidget { final Widget child; final int currentIndex; final Function(int) onIndexChanged; const MobileScaffold({ super.key, required this.child, required this.currentIndex, required this.onIndexChanged, }); @override Widget build(BuildContext context, WidgetRef ref) { return Scaffold( backgroundColor: AppColors.background, body: Column( children: [ // Top Navigation Bar (Apple TV Style) Container( padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16), decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Colors.black.withOpacity(0.6), Colors.transparent, ], ), ), child: SafeArea( bottom: false, child: Container( child: Row( children: [ // LOGO (Left side) Padding( padding: const EdgeInsets.only(right: 16), child: Image.asset( 'assets/images/logo_xtremflow.png', height: 40, width: 40, errorBuilder: (context, error, stackTrace) => const SizedBox(width: 40), // Fallback if missing ), ), // NAVIGATION PILL (Expanded) Expanded( child: Container( height: 50, decoration: BoxDecoration( color: Colors.white.withOpacity(0.15), borderRadius: BorderRadius.circular(30), border: Border.all(color: Colors.white.withOpacity(0.15)), ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ _buildNavItem(0, 'Live TV', Icons.tv), _buildNavItem(1, 'Films', Icons.movie), _buildNavItem(2, 'Séries', Icons.video_library), _buildNavItem(3, 'Paramètres', Icons.settings), ], ), ), ), ], ), ), ), ), // Main Content Expanded(child: child), ], ), ); } Widget _buildNavItem(int index, String label, IconData icon) { final isSelected = currentIndex == index; return _AppleTVNavItem( isSelected: isSelected, icon: icon, label: label, onPressed: () => onIndexChanged(index), ); } } /// Apple TV style navigation item - matches desktop style class _AppleTVNavItem extends StatefulWidget { final bool isSelected; final IconData icon; final String label; final VoidCallback onPressed; const _AppleTVNavItem({ required this.isSelected, required this.icon, required this.label, required this.onPressed, }); @override State<_AppleTVNavItem> createState() => _AppleTVNavItemState(); } class _AppleTVNavItemState extends State<_AppleTVNavItem> { final FocusNode _focusNode = FocusNode(); bool _isFocused = false; @override void initState() { super.initState(); _focusNode.addListener(_onFocusChange); } @override void dispose() { _focusNode.removeListener(_onFocusChange); _focusNode.dispose(); super.dispose(); } void _onFocusChange() { setState(() => _isFocused = _focusNode.hasFocus); } @override Widget build(BuildContext context) { // Selected OR Focused = black text (white bg), Normal = white70 text final Color textColor = (widget.isSelected || _isFocused) ? Colors.black : Colors.white70; final Color iconColor = (widget.isSelected || _isFocused) ? Colors.black : Colors.white70; return Focus( focusNode: _focusNode, onKeyEvent: (node, event) { if (event is KeyDownEvent) { final key = event.logicalKey; if (key == LogicalKeyboardKey.select || key == LogicalKeyboardKey.enter || key == LogicalKeyboardKey.space) { widget.onPressed(); return KeyEventResult.handled; } } return KeyEventResult.ignored; }, child: GestureDetector( onTap: widget.onPressed, child: AnimatedContainer( duration: const Duration(milliseconds: 150), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), margin: const EdgeInsets.symmetric(horizontal: 2, vertical: 4), decoration: BoxDecoration( // White pill when selected OR focused color: widget.isSelected ? Colors.white : (_isFocused ? Colors.white.withOpacity(0.9) : Colors.transparent), borderRadius: BorderRadius.circular(25), // Strong glow when focused boxShadow: _isFocused ? [ BoxShadow( color: Colors.white.withOpacity(0.5), blurRadius: 16, spreadRadius: 4, ), ] : null, ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(widget.icon, color: iconColor, size: 18), const SizedBox(width: 6), Text( widget.label, style: TextStyle( color: textColor, fontWeight: widget.isSelected ? FontWeight.w700 : FontWeight.w400, fontSize: 13, ), ), ], ), ), ), ); } }