import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:taafee_mobile/common/extensions/widget_extension.dart';

import '../../../../common/const/const.dart';
import '../../../../common/widgets/text.dart';
import '../../business logic layer/chat_controller.dart';
import '../../data_layer/model/message.dart';

class ReplyingWidget extends StatelessWidget {
  ReplyingWidget({
    super.key,
  });
  final ChatController chatController = Get.find<ChatController>();

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 55,
      decoration: BoxDecoration(
        color: Colors.grey[350],
        borderRadius: const BorderRadius.only(
          topLeft: Radius.circular(12),
          topRight: Radius.circular(12),
        ),
      ),
      child: Stack(
        children: [
          Obx(() {
            return Row(
              children: [
                const VerticalDivider(
                  width: 18,
                  color: Colors.white,
                  thickness: 4,
                ),
                if (chatController.replyModel.value.type == MessageType.image)
                  (chatController.replyModel.value.content != '')
                      ? Image(
                          image: CachedNetworkImageProvider(Domain.chatFiles +
                              chatController.replyModel.value.content),
                          width: 100,
                        ).paddingSymmetric(horizontal: 6)
                      : Image(
                          image: FileImage(
                              chatController.replyModel.value.temporaryFile!),
                          width: 100,
                        ).paddingSymmetric(horizontal: 6),
                (chatController.replyModel.value.type == MessageType.image)
                    ? RegularTextWidget(
                        'photo'.tr,
                        overflow: TextOverflow.fade,
                        color: Colors.white,
                        fontSize: 16,
                        maxLines: 1,
                      )
                    : (chatController.replyModel.value.type ==
                            MessageType.voice)
                        ? RegularTextWidget(
                            'voice'.tr,
                            overflow: TextOverflow.fade,
                            color: Colors.white,
                            fontSize: 16,
                            maxLines: 1,
                          )
                        : SizedBox(
                            width: Get.width * 0.7,
                            child: RegularTextWidget(
                              chatController.replyModel.value.content,
                              overflow: TextOverflow.ellipsis,
                              color: Colors.white,
                              fontSize: 16,
                              maxLines: 1,
                            ),
                          ),
              ],
            );
          }),
          SvgPicture.asset('assets/icons/x.svg')
              .paddingOnly(
            top: 8,
            right: 8,
          )
              .onTap(() {
            chatController.toggleIsReplying();
          }).align(alignment: Alignment.topRight)
        ],
      ),
    );
  }
}
