import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/viewModel/patient-ucaf-viewmodel.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/patients/profile/UCAF/page-stepper-widget.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-header-new-design-app-bar.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hexcolor/hexcolor.dart';

import '../../../../routes.dart';

class UCAFInputScreen extends StatefulWidget {
  @override
  _UCAFInputScreenState createState() => _UCAFInputScreenState();
}

class _UCAFInputScreenState extends State<UCAFInputScreen> {
  bool _inPatient = false;
  bool _emergencyCase = false;
  final _durationOfIllnessController = TextEditingController();
  final _additionalComplaintsController = TextEditingController();
  final _otherController = TextEditingController();
  final _howController = TextEditingController();
  final _whenController = TextEditingController();
  final _whereController = TextEditingController();
  final _managementsLineController = TextEditingController();
  final _signsController = TextEditingController();
  List<Map> conditionsData = [
    {"name": "CHRONIC", "isChecked": false},
    {"name": "RTA", "isChecked": false},
    {"name": "PSYCHIATRIC", "isChecked": false},
    {"name": "WORK RELATED", "isChecked": false},
    {"name": "VACCINATION", "isChecked": false},
    {"name": "CONGENITAL", "isChecked": false},
    {"name": "INFERTILITY", "isChecked": false},
    {"name": "CHECK-UP", "isChecked": false},
    {"name": "PREGNANCY/INDICATE MP", "isChecked": false},
    {"name": "CLEANING", "isChecked": false},
    {"name": "ORTHO DONTICS", "isChecked": false},
    {"name": "SPORTS RELATED", "isChecked": false},
    {"name": "REGULAR DENTAL TREATMENT", "isChecked": false},
    {"name": "IS TRAUMA TREATMENT SPECIFY ETA", "isChecked": false},
  ];

  @override
  Widget build(BuildContext context) {
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;
    PatiantInformtion patient = routeArgs['patient'];
    String patientType = routeArgs['patientType'];
    String arrivalType = routeArgs['arrivalType'];

    final screenSize = MediaQuery.of(context).size;

    return BaseView<UcafViewModel>(
      onModelReady: (model) => model.getUCAFData(patient),
      builder: (_, model, w) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: true,
        appBar: PatientProfileHeaderNewDesignAppBar(
            patient, patientType, arrivalType),
        appBarTitle: TranslationBase.of(context).ucaf,
        body: model.patientVitalSignsHistory.length > 0 &&
                model.patientChiefComplaintList != null &&
                model.patientChiefComplaintList.length > 0
            ? Column(
                children: [
                  Expanded(
                    child: SingleChildScrollView(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          // PatientHeaderWidgetNoAvatar(patient),
                          Container(
                            margin: EdgeInsets.all(16.0),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                AppText(
                                  "${TranslationBase.of(context).patient}",
                                  fontFamily: 'Poppins',
                                  fontSize: SizeConfig.textMultiplier * 1.6,
                                  fontWeight: FontWeight.w600,
                                ),
                                AppText(
                                  "${TranslationBase.of(context).ucaf}",
                                  fontFamily: 'Poppins',
                                  fontSize: SizeConfig.textMultiplier * 3,
                                  fontWeight: FontWeight.bold,
                                )
                              ],
                            ),
                          ),
                          PageStepperWidget(
                            stepsCount: 2,
                            currentStepIndex: 1,
                            screenSize: screenSize,
                          ),
                          Container(
                            margin: EdgeInsets.symmetric(
                                vertical: 0, horizontal: 16),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                CheckboxListTile(
                                  title: AppText(
                                    TranslationBase.of(context).inPatient,
                                    fontWeight: FontWeight.normal,
                                    fontFamily: 'Poppins',
                                    fontSize: SizeConfig.textMultiplier * 2.2,
                                  ),
                                  value: _inPatient,
                                  onChanged: (newValue) {
                                    setState(() {
                                      _inPatient = newValue;
                                    });
                                  },
                                  activeColor: HexColor("#D02127"),
                                  controlAffinity:
                                      ListTileControlAffinity.leading,
                                  contentPadding: EdgeInsets.all(0),
                                ),
                                CheckboxListTile(
                                  title: AppText(
                                    TranslationBase.of(context).emergencyCase,
                                    fontWeight: FontWeight.normal,
                                    fontFamily: 'Poppins',
                                    fontSize: SizeConfig.textMultiplier * 2.2,
                                  ),
                                  value: _emergencyCase,
                                  onChanged: (newValue) {
                                    setState(() {
                                      _emergencyCase = newValue;
                                    });
                                  },
                                  activeColor: HexColor("#D02127"),
                                  controlAffinity:
                                      ListTileControlAffinity.leading,
                                  contentPadding: EdgeInsets.all(0),
                                ),
                                AppTextFieldCustom(
                                  hintText: TranslationBase.of(context)
                                      .durationOfIllness,
                                  dropDownText: "3",
                                  inputType: TextInputType.number,
                                  inputFormatters: [
                                    FilteringTextInputFormatter.allow(
                                        RegExp(ONLY_NUMBERS))
                                  ],
                                ),
                                SizedBox(
                                  height: 16,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Row(
                                      children: [
                                        Icon(
                                          DoctorApp.warning,
                                          size: 20,
                                          color: Color(0xFFCC9B14),
                                        ),
                                        SizedBox(
                                          width: 8,
                                        ),
                                        AppText(
                                          "BP (H/L)",
                                          fontSize:
                                              SizeConfig.textMultiplier * 1.8,
                                          color: Colors.black,
                                          fontWeight: FontWeight.normal,
                                        ),
                                        SizedBox(
                                          width: 8,
                                        ),
                                        AppText(
                                          "${model.bloodPressure}",
                                          fontSize:
                                              SizeConfig.textMultiplier * 2,
                                          color: Colors.grey.shade800,
                                          fontWeight: FontWeight.w700,
                                        ),
                                      ],
                                    ),
                                    SizedBox(
                                      width: 6,
                                    ),
                                    Expanded(
                                      child: Row(
                                        children: [
                                          AppText(
                                            "${TranslationBase.of(context).temperature}",
                                            fontSize:
                                                SizeConfig.textMultiplier * 1.8,
                                            color: Colors.black,
                                            fontWeight: FontWeight.normal,
                                          ),
                                          SizedBox(
                                            width: 4,
                                          ),
                                          Expanded(
                                            child: AppText(
                                              "${model.temperatureCelcius}(C), ${(double.parse(model.temperatureCelcius) * (9 / 5) + 32).toStringAsFixed(2)}(F)",
                                              fontSize:
                                                  SizeConfig.textMultiplier * 2,
                                              color: Colors.grey.shade800,
                                              fontWeight: FontWeight.w700,
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                                SizedBox(
                                  height: 2,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Row(
                                      children: [
                                        AppText(
                                          "${TranslationBase.of(context).pulseBeats}:",
                                          fontSize:
                                              SizeConfig.textMultiplier * 1.8,
                                          color: Colors.black,
                                          fontWeight: FontWeight.normal,
                                        ),
                                        SizedBox(
                                          width: 4,
                                        ),
                                        AppText(
                                          "${model.hartRat}",
                                          fontSize:
                                              SizeConfig.textMultiplier * 2,
                                          color: Colors.grey.shade800,
                                          fontWeight: FontWeight.w700,
                                        ),
                                      ],
                                    ),
                                  ],
                                ),
                                SizedBox(
                                  height: 16,
                                ),
                                AppText(
                                  TranslationBase.of(context)
                                      .chiefComplaintsAndSymptoms,
                                  fontFamily: 'Poppins',
                                  fontSize: SizeConfig.textMultiplier * 2.2,
                                  fontWeight: FontWeight.w700,
                                  color: Color(0xFF2E303A),
                                ),
                                SizedBox(
                                  height: 4,
                                ),
                                AppText(
                                  TranslationBase.of(context)
                                      .patientFeelsPainInHisBackAndCough,
                                  fontFamily: 'Poppins',
                                  fontWeight: FontWeight.normal,
                                  color: Color(0xFF575757),
                                  fontSize: SizeConfig.textMultiplier * 1.8,
                                ),
                                SizedBox(
                                  height: 8,
                                ),
                                AppTextFieldCustom(
                                  hintText:
                                      TranslationBase.of(context).instruction,
                                  dropDownText: Helpers.parseHtmlString(model
                                      .patientChiefComplaintList[0]
                                      .chiefComplaint),
                                  controller: _additionalComplaintsController,
                                  inputType: TextInputType.multiline,
                                  enabled: false,
                                  minLines: 1,
                                  maxLines: 20,
                                ),
                                SizedBox(
                                  height: 16,
                                ),
                                AppText(
                                  TranslationBase.of(context).otherConditions,
                                  fontWeight: FontWeight.bold,
                                  fontSize: SizeConfig.textMultiplier * 2.1,
                                  color: Color(0xFF2E303A),
                                ),
                                ...List.generate(
                                    conditionsData.length,
                                    (index) => CheckboxListTile(
                                          title: AppText(
                                            conditionsData[index]['name'],
                                            fontWeight: FontWeight.normal,
                                            fontSize:
                                                SizeConfig.textMultiplier * 2.1,
                                            fontFamily: 'Poppins',
                                          ),
                                          value: conditionsData[index]
                                              ['isChecked'],
                                          onChanged: (newValue) {
                                            setState(() {
                                              conditionsData[index]
                                                  ['isChecked'] = newValue;
                                            });
                                          },
                                          controlAffinity:
                                              ListTileControlAffinity.leading,
                                          contentPadding: EdgeInsets.all(0),
                                        )),
                                SizedBox(
                                  height: 8,
                                ),
                                AppTextFieldCustom(
                                  hintText: TranslationBase.of(context).other,
                                  dropDownText: "None",
                                  enabled: false,
                                ),
                                SizedBox(
                                  height: 8,
                                ),
                                AppTextFieldCustom(
                                  hintText: TranslationBase.of(context).how,
                                  dropDownText: "None",
                                  enabled: false,
                                ),
                                SizedBox(
                                  height: 8,
                                ),
                                Row(
                                  children: [
                                    Expanded(
                                      child: AppTextFieldCustom(
                                        hintText:
                                            TranslationBase.of(context).when,
                                        dropDownText: "None",
                                        enabled: false,
                                      ),
                                    ),
                                    SizedBox(
                                      width: 4,
                                    ),
                                    Expanded(
                                      child: AppTextFieldCustom(
                                        hintText:
                                            TranslationBase.of(context).where,
                                        dropDownText: "None",
                                        enabled: false,
                                      ),
                                    ),
                                  ],
                                ),
                                SizedBox(
                                  height: 8,
                                ),
                                AppTextFieldCustom(
                                  height: screenSize.height * 0.1,
                                  hintText: TranslationBase.of(context)
                                      .specifyPossibleLineManagement,
                                  dropDownText: "None",
                                  enabled: false,
                                  minLines: 4,
                                  maxLines: 6,
                                ),
                                SizedBox(
                                  height: 26,
                                ),
                                AppText(
                                  TranslationBase.of(context).significantSigns,
                                  fontWeight: FontWeight.bold,
                                  fontFamily: 'Poppins',
                                  fontSize: SizeConfig.textMultiplier * 2.2,
                                ),
                                SizedBox(
                                  height: 8,
                                ),
                                AppTextFieldCustom(
                                  height: screenSize.height * 0.1,
                                  hintText:
                                      TranslationBase.of(context).backAbdomen,
                                  dropDownText: "BackLNeck",
                                  enabled: false,
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    child: AppButton(
                      title: TranslationBase.of(context).next,
                      color: HexColor("#D02127"),
                      onPressed: () {
                        Navigator.of(context).pushNamed(PATIENT_UCAF_DETAIL,
                            arguments: {
                              'patient': patient,
                              'patientType': patientType,
                              'arrivalType': arrivalType
                            });
                      },
                    ),
                  ),
                ],
              )
            : Center(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    SizedBox(
                      height: 100,
                    ),
                    Image.asset('assets/images/no-data.png'),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: AppText(
                          model.patientVitalSignsHistory.length > 0
                              ? TranslationBase.of(context).vitalSignEmptyMsg
                              : TranslationBase.of(context).chiefComplaintEmptyMsg,
                        fontWeight: FontWeight.normal,
                        color: HexColor("#B8382B"),
                        fontSize: SizeConfig.textMultiplier * 2.5,
                      ),
                    )
                  ],
                ),
              ),
      ),
    );
  }
}
