import 'package:flutter/material.dart';

import '../../../../api/marianumcloud/talk/chat/getChatResponse.dart';
import '../../../../api/marianumcloud/talk/chat/richObjectStringProcessor.dart';
import 'chatBubbleStyles.dart';

class AnswerReference extends StatelessWidget {
  final BuildContext context;
  final GetChatResponseObject referenceMessage;
  final String? selfId;
  const AnswerReference({required this.context, required this.referenceMessage, required this.selfId, super.key});

  @override
  Widget build(BuildContext context) {
    var style = ChatBubbleStyles(context);
    return DecoratedBox(
      decoration: BoxDecoration(
        color: referenceMessage.actorId == selfId
            ? style.getSelfStyle(false).color!.withGreen(200).withOpacity(0.2)
            : style.getRemoteStyle(false).color!.withWhite(200).withOpacity(0.2),
        borderRadius: const BorderRadius.all(Radius.circular(5)),
        border: Border(left: BorderSide(
            color: referenceMessage.actorId == selfId
                ? style.getSelfStyle(false).color!.withGreen(200)
                : style.getRemoteStyle(false).color!.withWhite(200),
            width: 5
        )),
      ),
      child: Padding(
        padding: const EdgeInsets.all(5).add(const EdgeInsets.only(left: 5)),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              referenceMessage.actorDisplayName,
              maxLines: 1,
              style: TextStyle(
                overflow: TextOverflow.ellipsis,
                color: referenceMessage.actorId == selfId
                    ? style.getSelfStyle(false).color!.withGreen(200)
                    : style.getRemoteStyle(false).color!.withWhite(200),
                fontSize: 12,
              ),
            ),
            Text(
              RichObjectStringProcessor.parseToString(referenceMessage.message, referenceMessage.messageParameters),
              maxLines: 2,
              style: TextStyle(
                overflow: TextOverflow.ellipsis,
                color: Theme.of(context).colorScheme.onSurface,
                fontSize: 12,
              ),
            ),
          ],
        ),
      ),
    );
  }
}