import 'dart:convert';

import 'package:chat/configs/app_colors.dart';
import 'package:chat/models/im/custom_message_model.dart';
import 'package:chat/views/conversation/widgets/show_call_message.dart';
import 'package:chat/views/conversation/widgets/show_group_card_message.dart';
import 'package:chat/views/conversation/widgets/show_name_card_message.dart';
import 'package:chat/views/conversation/widgets/show_transfer_message.dart';
import 'package:flutter/material.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_message.dart';

class ShowCustomMessage extends StatelessWidget {
  final V2TimMessage message;
  const ShowCustomMessage(this.message, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    try {
      String type =
          json.decode(message.customElem!.data!)['businessID'].toString();

      switch (type) {
        // case CustomMessageType.EVALUATION:
        //   return ShowEvaluationMessage(message);
        case CustomMessageType.NAME_CARD:
          return ShowNameCardMessage(message);
        case CustomMessageType.DT_TRANSFER:
          return ShowTransferMessage(message);
        case CustomMessageType.CALL:
          return ShowCallMessage(message);
        case CustomMessageType.GROUP_CARD:
          return ShowGroupCardMessage(message);
        default:
          return _unknowMessage();
      }
    } catch (e) {
      return _unknowMessage();
    }
  }

  Widget _unknowMessage() {
    return Container(
      height: 44,
      padding: const EdgeInsets.symmetric(horizontal: 8),
      decoration: BoxDecoration(
        color: AppColors.white,
        borderRadius: BorderRadius.circular(4),
      ),
      alignment: Alignment.center,
      child: Column(
        children: [
          const Text('【自定义消息】'),
          Text(
            message.customElem!.data!,
            maxLines: 5,
          ),
        ],
      ),
    );
  }
}
