import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/components/alert_dialog.dart';
import 'package:vnote_device_plugin/models/exams/twelve_heart.dart';

///  ecg结论
///  确认提示框
class ConclusionDialog extends StatelessWidget {
  /// 确认信息
  final TwelveHeartResultEntity twelveHeartResult;

  /// 标题，默认“提示”
  final String? title;

  /// 禁用取消按钮
  final bool disableCancel;

  const ConclusionDialog({
    super.key,
    required this.twelveHeartResult,
    this.disableCancel = false,
    this.title,
  });

  /// 弹出确认框
  ///
  /// [message] 确认信息
  ///
  /// [title] 标题，默认“提示”
  ///
  /// [disableCancel] 禁用取消按钮
  static Future<bool> show({
    required TwelveHeartResultEntity twelveHeartResult,
    String? title,
    bool disableCancel = false,
  }) async {
    final result = await Get.dialog(
      ConclusionDialog(
        twelveHeartResult: twelveHeartResult,
        title: title,
        disableCancel: disableCancel,
      ),
      barrierDismissible: false,
    );
    return result == true;
  }

  String _replaceSemicolon(String input) {
    String result = input;
    if (result.endsWith(';')) {
      result = result.replaceAll(';', '');
    } else {
      result = result.replaceAll(';', '、');
    }
    return result;
  }

  @override
  Widget build(BuildContext context) {
    return VAlertDialog(
      title: "心电图特征",
      width: 550,
      content: Container(
        padding: const EdgeInsets.symmetric(horizontal: 24),
        height: 280,
        alignment: Alignment.center,
        child: Column(
          children: [
            // 自适应换行
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    "检测提示:",
                    style: TextStyle(fontSize: 20),
                  ),
                  Text(
                    _replaceSemicolon(twelveHeartResult.advice),
                    style: const TextStyle(fontSize: 20),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    "HR:",
                    style: TextStyle(fontSize: 20),
                  ),
                  Text(
                    "${twelveHeartResult.HR} bpm",
                    style: const TextStyle(fontSize: 20),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    "QRS:",
                    style: TextStyle(fontSize: 20),
                  ),
                  Text(
                    "${twelveHeartResult.QRSAxis} ms",
                    style: const TextStyle(fontSize: 20),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    "PR:",
                    style: TextStyle(fontSize: 20),
                  ),
                  Text(
                    "${twelveHeartResult.PR} ms",
                    style: const TextStyle(fontSize: 20),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    "QT/QTc:",
                    style: TextStyle(fontSize: 20),
                  ),
                  Text(
                    "${twelveHeartResult.QTDur} ms/${twelveHeartResult.QTCDur} ms",
                    style: const TextStyle(fontSize: 20),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    "P/QRS/T轴:",
                    style: TextStyle(fontSize: 20),
                  ),
                  Text(
                    "${twelveHeartResult.P_QRS_T_Axis} 度",
                    style: const TextStyle(fontSize: 20),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    "RV5/SV1:",
                    style: TextStyle(fontSize: 20),
                  ),
                  Text(
                    "${twelveHeartResult.Rv5_Sv1_1} mV",
                    style: const TextStyle(fontSize: 20),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    "RV5+SV1:",
                    style: TextStyle(fontSize: 20),
                  ),
                  Text(
                    "${twelveHeartResult.Rv5_Sv1_2} mV",
                    style: const TextStyle(fontSize: 20),
                  ),
                ],
              ),
            ),

            // Expanded(
            //   child: Row(
            //     mainAxisAlignment: MainAxisAlignment.spaceBetween,
            //     children: [
            //       const Text(
            //         "PWidth:",
            //         style: TextStyle(fontSize: 20),
            //       ),
            //       Text(
            //         twelveHeartResult.P_QRS_T_Axis,
            //         style: const TextStyle(fontSize: 20),
            //       ),
            //     ],
            //   ),
            // ),
          ],
        ),
      ),
      onConfirm: () {
        Get.back(result: true);
      },
      showCancel: false,
      // onCanceled: () {
      //   Get.back(result: false);
      // },
    );
  }
}
