import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';

class ChatBubble extends StatelessWidget {
  const ChatBubble(
      {Key? key,
      required this.text,
      required this.isCurrentUser,
      required this.isSeen,
      required this.isDelivered,
      required this.dateTime})
      : super(key: key);
  final String text;
  final bool isCurrentUser;
  final bool isSeen;
  final bool isDelivered;
  final String dateTime;

  @override
  Widget build(BuildContext context) {
    return Padding(
      // asymmetric padding
      padding: EdgeInsets.fromLTRB(
        isCurrentUser ? 64.0 : 16.0,
        4,
        isCurrentUser ? 16.0 : 64.0,
        4,
      ),
      child: Align(
        // align the child within the container
        alignment: isCurrentUser ? Alignment.centerRight : Alignment.centerLeft,
        child: DecoratedBox(
          // chat bubble decoration
          decoration: BoxDecoration(
            color: Colors.white,
            gradient: isCurrentUser
                ? null
                : LinearGradient(
                    transform: GradientRotation(.46),
                    begin: Alignment.topRight,
                    end: Alignment.bottomLeft,
                    colors: [
                        MyColors.gradiantEndColor,
                        MyColors.gradiantStartColor,
                      ]),
            borderRadius: BorderRadius.circular(10),
          ),
          child: Padding(
            padding: const EdgeInsets.all(12),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                text.toText12(
                    color:
                        isCurrentUser ? MyColors.grey57Color : MyColors.white),
                8.height,
                Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    dateTime.toText12(
                        color: isCurrentUser
                            ? MyColors.grey41Color.withOpacity(.5)
                            : Colors.white.withOpacity(0.7)),
                    if (isCurrentUser) 5.width,
                    if (isCurrentUser)
                      Icon(
                        isDelivered
                                ? Icons.done_all
                                : Icons.done_all,
                        color: isSeen
                            ? MyColors.textMixColor
                            : MyColors.grey9DColor,
                        size: 14,
                      )
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
