import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:fis_jsonrpc/rpc.dart';
import '../index.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_i18n/i18n.dart';

class RecordMessageCard extends GetView<GroupChatController> {
  RecordMessageCard({
    Key? key,
    required this.recordInfo,
  }) : super(key: key);

  final SimpleRecordInfoDTO recordInfo;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 400,
      height: 100,
      // color: Colors.red,
      child: Column(
        children: [
          Expanded(
            child: Align(
              alignment: Alignment.topLeft,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Icon(
                    Icons.description_outlined,
                    size: 50,
                    color: Colors.black54,
                  ),
                  Expanded(
                    child: Container(
                      // color: Colors.yellow,
                      // width: double.infinity,
                      padding: EdgeInsets.symmetric(horizontal: 5),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Align(
                            alignment: Alignment.topLeft,
                            child: Text(
                              recordInfo.patientName ?? "",
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                fontSize: 14,
                              ),
                            ),
                          ),
                          Align(
                            alignment: Alignment.bottomRight,
                            child: Text(
                              _stateLabel(recordInfo.recordStatus,
                                  recordInfo.referralType),
                              style: _getTextStyleByState(
                                recordInfo.recordStatus,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          SizedBox(height: 5),
          Container(
            height: 40,
            child: Row(
              children: [
                Expanded(
                  child: Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 5, vertical: 0),
                    child: OutlinedButton(
                      onPressed: () {
                        if (kIsMobile) {
                          controller.openImagePageOnMobile(recordInfo);
                        } else {
                          controller.openImageAndReportsDrawer(recordInfo);
                        }
                      },
                      style: OutlinedButton.styleFrom(
                        foregroundColor: Colors.grey,
                      ),
                      child: Text(
                        i18nBook.common.image.t,
                        style: TextStyle(color: Colors.black87),
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 5, vertical: 0),
                    child: OutlinedButton(
                      onPressed: () {
                        if (kIsMobile) {
                          controller.routerToReportsPage(recordInfo);
                        } else {
                          controller.openImageAndReportsDrawer(recordInfo,
                              isReport: true);
                        }
                      },
                      style: OutlinedButton.styleFrom(
                        foregroundColor: Colors.grey,
                      ),
                      child: Text(
                        i18nBook.common.report.t,
                        style: TextStyle(color: Colors.black87),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  ///获取状态文本显示样式
  TextStyle _getTextStyleByState(RecordStatusEnum state) {
    var color = Color.fromRGBO(124, 182, 90, 1);
    if ([RecordStatusEnum.NotReport, RecordStatusEnum.NotScanned]
        .contains(state)) {
      color = Color.fromRGBO(240, 141, 46, 1);
    }
    return TextStyle(
      color: color,
      fontSize: 12,
      fontWeight: FontWeight.bold,
    );
  }

  String _stateLabel(
    RecordStatusEnum? statusEnum,
    ReferralTypeEnum? referralType,
  ) {
    String label = '';
    switch (statusEnum) {
      case RecordStatusEnum.Completed:
        label = i18nBook.remedical.reported4Label.t;
        break;
      case RecordStatusEnum.NotReport:
        label = i18nBook.remedical.scanned4Label.t;
        break;
      case RecordStatusEnum.NotScanned:
        label = i18nBook.remedical.toScan4Label.t;
        break;
      case RecordStatusEnum.Uploaded:
        label = i18nBook.remedical.imageUploaded4Label.t;
        break;
      default:
        label = i18nBook.remedical.notFinished4Label.t;
        break;
    }

    if (referralType == ReferralTypeEnum.ReferralIn) {
      label += '(${i18nBook.remedical.transferiIn.t})';
    } else if (referralType == ReferralTypeEnum.ReferralOut) {
      label += '(${i18nBook.remedical.transferOut.t})';
    }
    return label;
  }
}
