import 'package:eatvio_app/core/utils/date_time_utils.dart'; import 'package:eatvio_app/features/chat/models/chat_room_pagination_model.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; class ChatEntryWidget extends StatefulWidget { final ChatRoom chatRoom; const ChatEntryWidget({ required this.chatRoom, super.key, }); @override State createState() => _ChatEntryWidgetState(); } class _ChatEntryWidgetState extends State { @override Widget build(BuildContext context) { return InkWell( borderRadius: BorderRadius.circular(16), onTap: () => GoRouter.of(context).pushNamed( 'chatScreen', extra: { 'chatId': widget.chatRoom.id.toString(), }, ), child: Ink( padding: const EdgeInsets.all(12), decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), color: const Color(0xFFF6FAFF), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ CircleAvatar( radius: 24, backgroundImage: NetworkImage( widget.chatRoom.users.toChatUser.profilePhotoUrl, ), backgroundColor: Colors.white, ), const SizedBox(width: 12), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( widget.chatRoom.users.toChatUser.name.length <= 20 ? widget.chatRoom.users.toChatUser.name : '${widget.chatRoom.users.toChatUser.name.substring(0, 20)}...', style: theme.textTheme.titleMedium, ), const SizedBox(height: 8), if (widget.chatRoom.lastMessage != null) SizedBox( width: MediaQuery.sizeOf(context).width * 0.5, child: Text( widget.chatRoom.lastMessage!.data.toString().trim(), maxLines: 1, overflow: TextOverflow.ellipsis, style: CustomTextStyles.bodyMediumBluegray800, ), ), ], ), const Spacer(), Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ if (widget.chatRoom.lastMessage != null) Padding( padding: const EdgeInsets.only(left: 8), child: Text( widget.chatRoom.lastMessage!.updatedAt.format('dd MMM', 'ru'), style: theme.textTheme.bodyMedium, ), ), const SizedBox(height: 4), if (widget.chatRoom.unreadMessagesCount > 0) Container( padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6), decoration: BoxDecoration( shape: BoxShape.circle, color: appTheme.blueA400, ), child: Text( widget.chatRoom.unreadMessagesCount.toString(), style: TextStyles.textXSSemibold.copyWith(color: appTheme.whiteA700), ), ), ], ), ], ), ), ); } }