import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:taafee_mobile/common/extensions/widget_extension.dart';
import 'package:taafee_mobile/features/chat/business%20logic%20layer/chat_controller.dart';
import 'package:taafee_mobile/features/chat/data_layer/model/message.dart';
import 'package:taafee_mobile/features/chat/presentation_layer/widgets/recieved_message_widget.dart';
import 'package:taafee_mobile/features/chat/presentation_layer/widgets/sent_message_widget.dart';
import 'package:taafee_mobile/features/home/business_logic_layer/home_controller.dart';

import '../../../../common/const/const.dart';
import '../../../../common/widgets/text.dart';

// ignore: must_be_immutable
class RepliedMessage extends StatelessWidget {
  RepliedMessage({
    super.key,
    required this.messageModel,
    required this.repliedMessageModel,
    required this.textFieldFocusNode,
  });
  final ChatController chatController = Get.find<ChatController>();
  final HomeController homeController = Get.find<HomeController>();

  final MessageModel repliedMessageModel;
  final MessageModel messageModel;
  FocusNode textFieldFocusNode;
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: homeController.isArabic.value
          ? CrossAxisAlignment.start
          : CrossAxisAlignment.end,
      children: [
        Container(
          height: 40,
          decoration: BoxDecoration(
            color: Colors.grey[350],
            borderRadius: const BorderRadius.only(
              topLeft: Radius.circular(12),
              topRight: Radius.circular(12),
            ),
          ),
          child: SizedBox(
            width: messageModel.direction == MessageDirection.sent
                ? Get.width * 0.47
                : Get.width * 0.448,
            child: Row(
              children: [
                VerticalDivider(
                  width: Responsive.isTablet() ? 16 : 18,
                  color: Colors.white,
                  thickness: 4,
                ).paddingOnly(top: 12, bottom: 8),
                if (repliedMessageModel.type == MessageType.image)
                  (repliedMessageModel.content != '')
                      ? Image(
                          image: CachedNetworkImageProvider(
                              Domain.chatFiles + repliedMessageModel.content),
                          width: 100,
                        ).paddingSymmetric(horizontal: 6)
                      : Image(
                          image: FileImage(repliedMessageModel.temporaryFile!),
                          width: 100,
                        ).paddingSymmetric(horizontal: 6),
                (repliedMessageModel.type == MessageType.image)
                    ? SizedBox(
                        width: Get.width * 0.3,
                        child: RegularTextWidget(
                          'photo'.tr,
                          overflow: TextOverflow.fade,
                          color: Colors.white,
                          fontSize: 14,
                          maxLines: 1,
                        ),
                      )
                    : (repliedMessageModel.type == MessageType.voice)
                        ? SizedBox(
                            width: Get.width * 0.3,
                            child: RegularTextWidget(
                              'voice'.tr,
                              overflow: TextOverflow.fade,
                              color: Colors.white,
                              fontSize: 14,
                              maxLines: 1,
                            ),
                          )
                        : SizedBox(
                            width: Get.width * 0.35,
                            child: RegularTextWidget(
                              repliedMessageModel.content,
                              overflow: TextOverflow.fade,
                              color: Colors.white,
                              fontSize: 14,
                              maxLines: 1,
                            ),
                          ),
              ],
            ),
          ),
        ).paddingOnly(right: Responsive.isTablet() ? 8 : 8).paddingOnly(
              right: (messageModel.direction == MessageDirection.received)
                  ? (Responsive.isTablet() ? 0 : Get.width * 0.435)
                  : 0,
              left: (messageModel.direction == MessageDirection.received)
                  ? ((Responsive.isTablet()) ? 8 : 0)
                  : 0,
            ),
        Stack(
          children: [
            Container(
              color: Colors.grey[350],
              width: messageModel.direction == MessageDirection.sent
                  ? Get.width * 0.47
                  : Get.width * 0.448,
              height: 20.0,
            )
                .align(alignment: Alignment.topRight)
                .paddingOnly(right: Responsive.isTablet() ? 8 : 8)
                .paddingOnly(
                  right: (messageModel.direction == MessageDirection.received)
                      ? (Responsive.isTablet() ? 0 : Get.width * 0.435)
                      : 0,
                  left: (messageModel.direction == MessageDirection.received)
                      ? ((Responsive.isTablet()) ? 8 : 0)
                      : 0,
                ),
            if (messageModel.direction == MessageDirection.sent)
              SentMessageWidget(
                      textFieldFocusNode: textFieldFocusNode,
                      messageModel: messageModel)
                  .align(
                alignment: Alignment.bottomCenter,
              ),
            if (messageModel.direction == MessageDirection.received)
              RecievedMessageWidget(
                      textFieldFocusNode: textFieldFocusNode,
                      messageModel: messageModel)
                  .align(
                alignment: Alignment.bottomLeft,
              ),
          ],
        ),
      ],
    );
  }
}
