import 'dart:convert';

import 'package:chat/configs/app_colors.dart';
import 'package:chat/models/im/calling_model.dart';
import 'package:chat/models/im/custom_message_model.dart';
import 'package:flutter/material.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_message.dart';

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

  @override
  State<ShowCallMessage> createState() => _ShowCallMessageState();
}

class _ShowCallMessageState extends State<ShowCallMessage> {
  @override
  Widget build(BuildContext context) {
    var model = CallingModel.fromJson(
      json.decode(widget.message.customElem!.data!),
    );

    final isVoiceCall = model.callType == CallingType.audioCall;
    return Container(
      constraints: const BoxConstraints(minHeight: 43),
      padding: const EdgeInsets.all(12),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(4),
        color: widget.message.isSelf! ? AppColors.primary : AppColors.white,
      ),
      child: Row(
        children: [
          Icon(
            isVoiceCall ? Icons.call_end : Icons.videocam,
            size: 20,
            color: widget.message.isSelf! ? AppColors.white : AppColors.active,
          ),
          const SizedBox(width: 4),
          model.timeout > 0
              ? Text(
                  '通话时长',
                  style: TextStyle(
                    color: widget.message.isSelf!
                        ? AppColors.white
                        : AppColors.active,
                  ),
                )
              : Text(
                  model.actionTypeText,
                  style: TextStyle(
                    color: widget.message.isSelf!
                        ? AppColors.white
                        : AppColors.active,
                  ),
                ),
        ],
      ),
    );
  }
}
