import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import '../../models/post.dart'; import '../../theme/app_theme.dart'; import '../media/signed_media_image.dart'; /// Widget for displaying video thumbnails on regular posts (Twitter-style) /// Clicking opens the Quips feed with the full video class VideoThumbnailWidget extends StatelessWidget { final Post post; final VoidCallback? onTap; const VideoThumbnailWidget({ super.key, required this.post, this.onTap, }); @override Widget build(BuildContext context) { if (post.thumbnailUrl == null) return const SizedBox.shrink(); return GestureDetector( onTap: onTap, child: Container( margin: const EdgeInsets.only(top: 12), child: ClipRRect( borderRadius: BorderRadius.circular(12), child: Stack( children: [ // Video thumbnail SignedMediaImage( url: post.thumbnailUrl!, width: double.infinity, height: 200, fit: BoxFit.cover, ), // Dark overlay Positioned.fill( child: Container( decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Colors.transparent, Colors.black.withValues(alpha: 0.3), ], ), ), ), ), // Play button overlay Positioned.fill( child: Center( child: Container( width: 56, height: 56, decoration: BoxDecoration( color: Colors.white.withValues(alpha: 0.9), shape: BoxShape.circle, boxShadow: [ BoxShadow( color: Colors.black.withValues(alpha: 0.3), blurRadius: 8, offset: const Offset(0, 2), ), ], ), child: const Icon( Icons.play_arrow, color: Colors.black, size: 28, ), ), ), ), // Duration indicator if (post.durationMs != null) Positioned( bottom: 8, right: 8, child: Container( padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), decoration: BoxDecoration( color: Colors.black.withValues(alpha: 0.7), borderRadius: BorderRadius.circular(4), ), child: Text( _formatDuration(post.durationMs!), style: GoogleFonts.inter( color: Colors.white, fontSize: 12, fontWeight: FontWeight.w500, ), ), ), ), // Video indicator badge Positioned( top: 8, left: 8, child: Container( padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), decoration: BoxDecoration( color: AppTheme.brightNavy, borderRadius: BorderRadius.circular(4), ), child: Text( 'VIDEO', style: GoogleFonts.inter( color: Colors.white, fontSize: 10, fontWeight: FontWeight.w600, ), ), ), ), ], ), ), ), ); } String _formatDuration(int durationMs) { final duration = Duration(milliseconds: durationMs); final minutes = duration.inMinutes; final seconds = duration.inSeconds % 60; return '$minutes:${seconds.toString().padLeft(2, '0')}'; } }