import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.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/screens/base/base_view.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/utils/utils.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/errors/error_message.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:flutter/material.dart';

class UCAFInputScreen extends StatefulWidget {
  final PatiantInformtion patient;
  final Function? changeLoadingState;

  UCAFInputScreen(this.patient, {this.changeLoadingState});

  @override
  _UCAFInputScreenState createState() => _UCAFInputScreenState(this.patient);
}

class _UCAFInputScreenState extends State<UCAFInputScreen> {
  final PatiantInformtion patient;

  _UCAFInputScreenState(this.patient);

  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();

  ///TODO Elham* fix this
  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) {
    return BaseView<UcafViewModel>(
      onModelReady: (model) async {
        model.resetDataInFirst();
        await model.getUCAFData(patient);
        widget.changeLoadingState!(false);
      },
      builder: (_, model, w) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: false,
        body: model.patientVitalSignsHistory != null && model.patientVitalSignsHistory!.length > 0 && model.patientChiefComplaintList != null && model.patientChiefComplaintList!.length > 0
            ? Column(
                children: [
                  Expanded(
                    child: SingleChildScrollView(
                      child: Center(
                        child: FractionallySizedBox(
                          widthFactor: .9,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              SizedBox(
                                height: 10,
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Icon(
                                    DoctorApp.warning,
                                    size: 20,
                                    color: Color(0xFFCC9B14),
                                  ),
                                  SizedBox(
                                    width: 10,
                                  ),
                                  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,
                                  ),
                                ],
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                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: 10,
                              ),
                              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: 20,
                              ),
                              AppText(
                                Utils.convertToTitleCase(TranslationBase.of(context).chiefComplaintsAndSymptoms),
                                fontFamily: 'Poppins',
                                fontSize: SizeConfig.textMultiplier! * 2.2,
                                fontWeight: FontWeight.w700,
                                color: Color(0xFF2E303A),
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              AppTextFieldCustom(
                                hintText: TranslationBase.of(context).instruction,
                                dropDownText: Utils.parseHtmlString(model.patientChiefComplaintList![0].chiefComplaint! + '\n'),
                                controller: _additionalComplaintsController,
                                inputType: TextInputType.multiline,
                                enabled: false,
                                minLines: 1,
                                maxLines: 20,
                                onClick: () {},
                                onChanged: (value) {},
                                onFieldSubmitted: () {},
                              ),
                              SizedBox(
                                height: 8,
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              )
            : model.patientChiefComplaintList != null || model.patientVitalSignsHistory != null
                ? Center(
                    child: ErrorMessage(
                        error: model.patientVitalSignsHistory == null || model.patientVitalSignsHistory!.length == 0
                            ? TranslationBase.of(context).vitalSignEmptyMsg
                            : TranslationBase.of(context).chiefComplaintEmptyMsg))
                : Container(),
      ),
    );
  }
}
