import 'dart:convert';
import 'package:chat/configs/app_colors.dart';
import 'package:chat/configs/app_size.dart';
import 'package:chat/controllers/private_controller.dart';
import 'package:chat/models/im/name_card_model.dart';
import 'package:chat/routes/contact_routes.dart';
import 'package:chat/widgets/custom_avatar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_message.dart';

/// 个人名片消息
class ShowNameCardMessage extends StatelessWidget {
  final V2TimMessage message;

  const ShowNameCardMessage(this.message, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var model = NameCardModel.fromJson(
      json.decode(message.customElem!.data!),
    );

    return InkWell(
      onTap: () async {
        await PrivateController.to.setCurrentFriend(
          model.userID,
        );
        Get.toNamed(
          ContactRoutes.friendProfile,
        );
      },
      child: Container(
        width: Get.width * 0.618,
        padding: const EdgeInsets.all(12),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(4),
          color: AppColors.white,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                CustomAvatar(
                  model.avatar,
                  size: 44,
                ),
                const SizedBox(
                  width: 8,
                ),
                Text(
                  model.userName,
                  style: const TextStyle(
                    color: AppColors.primary,
                    overflow: TextOverflow.ellipsis,
                  ),
                  maxLines: 1,
                )
              ],
            ),
            const Divider(height: 16),
            const Text(
              '个人名片',
              style: TextStyle(
                fontSize: AppSize.smallFontSize,
                color: AppColors.unactive,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
