import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:taafee_mobile/common/extensions/widget_extension.dart';
import 'package:taafee_mobile/common/widgets/text.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/home/business_logic_layer/home_controller.dart';
import '../../../../common/const/const.dart';

class SentMessageWidget extends StatelessWidget {
  SentMessageWidget({
    super.key,
    this.dismissibleKey = const Key('sent'),
    required this.messageModel,
    required this.textFieldFocusNode,
  });
  final Key dismissibleKey;
  final MessageModel messageModel;

  final ChatController chatController = Get.find<ChatController>();
  final HomeController homeController = Get.find<HomeController>();
  final FocusNode textFieldFocusNode;
  @override
  Widget build(BuildContext context) {
    return Dismissible(
      confirmDismiss: (direction) async {
        chatController.updateReplyModel(
          messageModel: messageModel,
        );
        if (chatController.isReplying.value == false) {
          chatController.toggleIsReplying();
        }

        FocusScope.of(context).requestFocus(textFieldFocusNode);
        return false;
      },
      key: dismissibleKey,
      onDismissed: null,
      child: SizedBox(
        width: Get.width * 0.5,
        child: Stack(
          alignment: Alignment.bottomCenter,
          children: [
            Column(
              children: [
                Container(
                  // constraints: BoxConstraints.tight(Size(400, 400)),

                  decoration: BoxDecoration(
                    color: AppColors.sentMessageColor,
                    borderRadius: const BorderRadius.only(
                      bottomLeft: Radius.circular(12),
                      topLeft: Radius.circular(12),
                      topRight: Radius.circular(12),
                    ),
                    // image: DecorationImage(
                    //     image: AssetImage('assets/images/sent message.png'),
                    //     fit: BoxFit.fill),
                  ),
                  child: SizedBox(
                    width: Get.width,
                    child: Column(
                      crossAxisAlignment: homeController.isArabic.value
                          ? CrossAxisAlignment.start
                          : CrossAxisAlignment.end,
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        RegularTextWidget(
                          messageModel.content,
                          fontSize: 14,
                          color: Colors.white,
                          textAlign: homeController.isArabic.value
                              ? TextAlign.right
                              : TextAlign.left,
                        )
                            .paddingOnly(
                                top: 16,
                                left: 8,
                                right: Responsive.isTablet() ? 24 : 16)
                            .align(
                                alignment: homeController.isArabic.value
                                    ? Alignment.centerRight
                                    : Alignment.centerLeft)
                            .paddingOnly(
                                left: 8,
                                right: homeController.isArabic.value ? 36 : 0),
                        RegularTextWidget(
                          messageModel.createdAt.toString().substring(11, 16),
                          color: Colors.white,
                          textAlign: TextAlign.right,
                          fontSize: 10,
                        ).paddingOnly(
                            right: Responsive.isTablet() ? 70 : 40,
                            top: 8,
                            bottom: (messageModel.content.length > 34) ? 8 : 0),
                        // const SizedBox(
                        //   height: 16,
                        // ),
                      ],
                    ),
                  ).align(alignment: Alignment.centerRight),
                ).align(alignment: Alignment.centerRight),
              ],
            ).paddingOnly(bottom: 8, right: 5),
            Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Image.asset(
                  'assets/images/sent message shape.png',
                  width: 20,
                  height: 20,
                ).align(alignment: Alignment.bottomRight),
              ],
            )
          ],
        ),
      ).paddingOnly(left: Responsive.isTablet() ? 0 : 70),
    ).align(alignment: Alignment.centerRight);
  }
}
