import 'package:chat/configs/app_colors.dart';
import 'package:chat/configs/app_size.dart';
import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_message.dart';

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

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () async {
        // try {
        //   var result = await OpenFile.open(message.fileElem!.localUrl);
        //   if (result.type != ResultType.done) {
        //     UiTools.toast(result.message);
        //   }
        // } catch (e) {
        //   UiTools.toast(e.toString());
        // }
      },
      child: Container(
        padding: const EdgeInsets.all(12),
        width: Get.width * 0.618,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(4),
          color: AppColors.white,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    message.fileElem!.fileName!,
                    overflow: TextOverflow.visible,
                    style: const TextStyle(
                      fontSize: AppSize.fontSize,
                      color: AppColors.active,
                    ),
                  ),
                  const SizedBox(height: 8),
                  Text(
                    filesize(message.fileElem!.fileSize),
                    overflow: TextOverflow.visible,
                    style: const TextStyle(
                      fontSize: AppSize.smallFontSize,
                      color: AppColors.unactive,
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(width: 8),
            Image.asset(
              'assets/chats/file_msg.png',
              width: 44,
            ),
          ],
        ),
      ),
    );
  }
}
