import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/components/cell.dart';
import 'package:vitalapp/components/dialog_input.dart';
import 'package:vitalapp/components/dialog_select.dart';
import 'package:vitalapp/pages/patient/info/controller.dart';
import 'package:vitalapp/pages/patient/info/patientInfoRecord.dart';

class PatientInfoDetailView extends GetView<PatientInfoController> {
  const PatientInfoDetailView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scrollbar(
      child: SingleChildScrollView(
        child: Container(
          alignment: Alignment.topCenter,
          color: Colors.grey.shade200,
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.all(16),
                child: Obx(
                  () => VListFormCellGroup(
                    children: [
                      VListFormCell(
                        label: "工作单位",
                        content: controller.state.workUnit,
                        onTap: () async {
                          final result = await VDialogInput(
                                  title: "工作单位",
                                  initialValue: controller.state.workUnit,
                                  placeholder: '请输入')
                              .show();
                          if (result != null) {
                            controller.state.workUnit = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "联系人姓名",
                        content: controller.state.contactName,
                        onTap: () async {
                          final result = await VDialogInput(
                                  title: "联系人姓名",
                                  initialValue: controller.state.contactName,
                                  placeholder: '请输入')
                              .show();
                          if (result != null) {
                            controller.state.contactName = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "联系人电话",
                        content: controller.state.contactPhone,
                        onTap: () async {
                          final result = await VDialogInput(
                                  title: "联系人电话",
                                  initialValue: controller.state.contactPhone,
                                  placeholder: '请输入')
                              .show();
                          if (result != null) {
                            controller.state.contactPhone = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "常住类型",
                        content:
                            controller.state.permanentlyResideType.isNotEmpty
                                ? PatientInfoRecord.permanentlyResideTypeList
                                    .firstWhere((element) =>
                                        element.key ==
                                        controller.state.permanentlyResideType)
                                    .value
                                : '',
                        onTap: () async {
                          final result = await VDialogSelect<
                              MapEntry<String, String>, String>(
                            title: "常住类型",
                            source: PatientInfoRecord.permanentlyResideTypeList
                                .toList(),
                            valueGetter: (data) => data.key,
                            labelGetter: (data) => data.value,
                            initialValue:
                                controller.state.permanentlyResideType,
                          ).show();
                          if (result != null) {
                            controller.state.permanentlyResideType = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "血型",
                        content: controller.state.bloodType.isNotEmpty
                            ? PatientInfoRecord.bloodTypeList
                                .firstWhere((element) =>
                                    element.key == controller.state.bloodType)
                                .value
                            : '',
                        onTap: () async {
                          final result = await VDialogSelect<
                              MapEntry<String, String>, String>(
                            title: "血型",
                            source: PatientInfoRecord.bloodTypeList,
                            valueGetter: (data) => data.key,
                            labelGetter: (data) => data.value,
                            initialValue: controller.state.bloodType,
                          ).show();
                          if (result != null) {
                            controller.state.bloodType = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "RH",
                        content: controller.state.rh.isNotEmpty
                            ? PatientInfoRecord.rhList
                                .firstWhere((element) =>
                                    element.key == controller.state.rh)
                                .value
                            : '',
                        onTap: () async {
                          final result = await VDialogSelect<
                              MapEntry<String, String>, String>(
                            title: "RH",
                            source: PatientInfoRecord.rhList,
                            valueGetter: (data) => data.key,
                            labelGetter: (data) => data.value,
                            initialValue: controller.state.rh,
                          ).show();
                          if (result != null) {
                            controller.state.rh = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "文化程度",
                        content: controller.state.educationLevel.isNotEmpty
                            ? PatientInfoRecord.educationLevelList
                                .firstWhere((element) =>
                                    element.key ==
                                    controller.state.educationLevel)
                                .value
                            : '',
                        onTap: () async {
                          final result = await VDialogSelect<
                              MapEntry<String, String>, String>(
                            title: "文化程度",
                            source: PatientInfoRecord.educationLevelList,
                            valueGetter: (data) => data.key,
                            labelGetter: (data) => data.value,
                            initialValue: controller.state.educationLevel,
                          ).show();
                          if (result != null) {
                            controller.state.educationLevel = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "职业",
                        content: controller.state.career.isNotEmpty
                            ? PatientInfoRecord.careerList
                                .firstWhere((element) =>
                                    element.key == controller.state.career)
                                .value
                            : '',
                        onTap: () async {
                          final result = await VDialogSelect<
                              MapEntry<String, String>, String>(
                            title: "职业",
                            source: PatientInfoRecord.careerList,
                            valueGetter: (data) => data.key,
                            labelGetter: (data) => data.value,
                            initialValue: controller.state.career,
                          ).show();
                          if (result != null) {
                            controller.state.career = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "婚姻状况",
                        content: controller.state.maritalStatus.isNotEmpty
                            ? PatientInfoRecord.maritalStatusList
                                .firstWhere((element) =>
                                    element.key ==
                                    controller.state.maritalStatus)
                                .value
                            : '',
                        onTap: () async {
                          final result = await VDialogSelect<
                              MapEntry<String, String>, String>(
                            title: "婚姻状况",
                            source: PatientInfoRecord.maritalStatusList,
                            valueGetter: (data) => data.key,
                            labelGetter: (data) => data.value,
                            initialValue: controller.state.maritalStatus,
                          ).show();
                          if (result != null) {
                            controller.state.maritalStatus = result;
                          }
                        },
                      ),
                      VListFormCell(
                        label: "医疗费用支付方式",
                        content: controller.state.providerPayments.isNotEmpty
                            ? PatientInfoRecord.providerPaymentsList
                                .firstWhere((element) =>
                                    element.key ==
                                    controller.state.providerPayments)
                                .value
                            : '',
                        onTap: () async {
                          final result = await VDialogSelect<
                              MapEntry<String, String>, String>(
                            title: "医疗费用支付方式",
                            source: PatientInfoRecord.providerPaymentsList,
                            valueGetter: (data) => data.key,
                            labelGetter: (data) => data.value,
                            initialValue: controller.state.providerPayments,
                          ).show();
                          if (result != null) {
                            controller.state.providerPayments = result;
                          }
                        },
                      ),
                      if (controller.state.providerPayments.contains('8'))
                        VListFormCell(
                          label: "其他支付方式",
                          content: controller.state.providerPaymentsOther,
                          onTap: () async {
                            final result = await VDialogInput(
                                    title: "其他支付方式",
                                    initialValue:
                                        controller.state.providerPaymentsOther,
                                    placeholder: '请输入')
                                .show();
                            if (result != null) {
                              controller.state.providerPaymentsOther = result;
                            }
                          },
                        ),
                    ],
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
