import 'package:fis_jsonrpc/services/patient.m.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/architecture/utils/datetime.dart';
import 'package:vitalapp/components/alert_dialog.dart';
import 'package:vitalapp/consts/rpc_enum_labels.dart';

class FaceResultDialog extends StatelessWidget {
  final PatientBaseDTO data;

  /// 是否已建档
  final bool? hasCreateRecord;

  const FaceResultDialog({
    super.key,
    required this.data,
    this.hasCreateRecord = true,
  });

  static Future<bool> show(
    PatientBaseDTO data,
    bool hasCreateRecord,
  ) async {
    final result = await Get.dialog(
      FaceResultDialog(
        data: data,
        hasCreateRecord: hasCreateRecord,
      ),
      barrierDismissible: false,
    );
    return result == true;
  }

  @override
  Widget build(BuildContext context) {
    return _buildContent();
  }

  Widget _buildContent() {
    final title = hasCreateRecord! ? "识别结果-已建档" : "识别结果-未建档";
    return VAlertDialog(
      title: title,
      width: 400,
      contentPadding: const EdgeInsets.symmetric(horizontal: 36, vertical: 12),
      showCancel: false, // 目前销售确认只要确定，不需要取消
      onConfirm: () {
        Get.back(result: true);
      },
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          _buildRow("姓名", data.patientName!),
          _buildRow("性别", RpcEnumLabels.gender[data.patientGender]!),
          // _buildRow("出生日期", DateFormat('yyyy-MM-dd').format(data.birthday!)),
          _buildRow("年龄", DataTimeUtils.calculateAge(data.birthday!)),
          _buildRow("身份证", data.cardNo!),
        ],
      ),
    );
  }

  Widget _buildRow(String label, String content) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4),
      child: Row(
        children: [
          SizedBox(
            width: 90,
            child: Text(
              '$label:',
              style: const TextStyle(color: Colors.black, fontSize: 20),
            ),
          ),
          const SizedBox(width: 12),
          Expanded(
            child: Text(
              content,
              style: const TextStyle(color: Colors.black, fontSize: 20),
            ),
          ),
        ],
      ),
    );
  }
}
