import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/model/SOAP/progress_note/PatientCondition.dart';
import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/screens/patients/profile/soap_update_vida_plus/assessment/widget/empty_dropdown.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_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';

import '../../../../../../core/model/SOAP/progress_note/Clinic.dart';
import '../../../../../base/base_view.dart';

class AddProgressNoteDetails extends StatefulWidget {
  @override
  State<AddProgressNoteDetails> createState() => _AddProgressNoteDetailsState();
}

class _AddProgressNoteDetailsState extends State<AddProgressNoteDetails> {
  SOAPClinic? selectedClinicItem;

  PatientCondition? selectedPatientConditionItem;

  int status = 1;
  final TextEditingController noteController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<SOAPViewModel>(
        builder: (_, model, w) => Material(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10),
                  side: BorderSide(
                    width: 1,
                    color: Color(0xFFEFEFEF),
                  )),
              color: Colors.white,
              child: Padding(
                padding:
                    const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    AppText(
                      TranslationBase.of(context).addProgressNote,
                      fontSize: 16,
                      fontWeight: FontWeight.w600,
                      textAlign: TextAlign.start,
                      color: Colors.black,
                    ),
                    SizedBox(
                      height: 16,
                    ),
                    Material(
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10),
                          side: BorderSide(
                            width: 1,
                            color: Color(0xFFEFEFEF),
                          )),
                      color: Colors.white,
                      child: Padding(
                        padding: const EdgeInsets.symmetric(
                            horizontal: 16.0, vertical: 12),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            AppText(
                              TranslationBase.of(context).patientCondition,
                              textAlign: TextAlign.start,
                              fontWeight: FontWeight.w600,
                              fontSize: 11,
                              color: Color(0xFF2E303A),
                            ),
                            SizedBox(
                              height: 4,
                            ),
                            model.patientConditionList.isEmpty
                                ? EmptyDropDown()
                                : DropdownButtonHideUnderline(
                                    child: DropdownButton<PatientCondition>(
                                      dropdownColor: Colors.white,
                                      iconEnabledColor: Colors.black,
                                      icon: Icon(Icons.keyboard_arrow_down),
                                      isExpanded: true,
                                      value:
                                          selectedPatientConditionItem == null
                                              ? model.patientConditionList.first
                                              : selectedPatientConditionItem,
                                      iconSize: 25,
                                      elevation: 16,
                                      onChanged: (newValue) async {
                                        setState(() {
                                          selectedPatientConditionItem =
                                              newValue;
                                        });
                                      },
                                      items: model.patientConditionList
                                          .map((item) {
                                        return DropdownMenuItem(
                                          child: AppText(
                                            item.name ?? '',
                                            fontSize: 14,
                                            letterSpacing: -0.96,
                                            color: AppGlobal.appTextColor,
                                            fontWeight: FontWeight.normal,
                                            textAlign: TextAlign.left,
                                          ),
                                          value: item,
                                        );
                                      }).toList(),
                                    ),
                                  ),
                          ],
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 16,
                    ),
                    AppText(
                      TranslationBase.of(context).progressNoteType,
                      fontWeight: FontWeight.bold,
                      fontFamily: 'Poppins',
                      fontSize: 11,
                    ),
                    SizedBox(
                      height: 8,
                    ),
                    Row(
                      children: [
                        Flexible(
                            child: InkWell(
                          onTap: () {
                            setState(() {
                              status = 1;
                            });
                          },
                          child: Row(
                            children: [
                              Container(
                                padding: EdgeInsets.all(2.0),
                                margin: EdgeInsets.symmetric(horizontal: 6),
                                width: 20,
                                height: 20,
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  shape: BoxShape.circle,
                                  border:
                                      Border.all(color: Colors.grey, width: 1),
                                ),
                                child: Container(
                                  decoration: BoxDecoration(
                                    color: status == 1
                                        ? HexColor("#D02127")
                                        : Colors.white,
                                    shape: BoxShape.circle,
                                  ),
                                ),
                              ),
                              AppText(
                                TranslationBase.of(context).doctorProgressNote,
                                fontWeight: FontWeight.w600,
                                fontFamily: 'Poppins',
                                fontSize: 12,
                              ),
                            ],
                          ),
                        )),
                      ],
                    ),
                    SizedBox(
                      height: 24,
                    ),
                    Material(
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10),
                          side: BorderSide(
                            width: 1,
                            color: Color(0xFFEFEFEF),
                          )),
                      color: Colors.white,
                      child: Padding(
                        padding: const EdgeInsets.symmetric(
                            horizontal: 16.0, vertical: 12),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            AppText(
                              TranslationBase.of(context).speciality,
                              textAlign: TextAlign.start,
                              fontWeight: FontWeight.w600,
                              fontSize: 11,
                              color: Color(0xFF2E303A),
                            ),
                            SizedBox(
                              height: 4,
                            ),
                            model.clinics.isEmpty
                                ? EmptyDropDown()
                                : DropdownButtonHideUnderline(
                                    child: DropdownButton<SOAPClinic>(
                                      dropdownColor: Colors.white,
                                      iconEnabledColor: Colors.black,
                                      icon: Icon(Icons.keyboard_arrow_down),
                                      isExpanded: true,
                                      value: selectedClinicItem == null
                                          ? model.clinics.first
                                          : selectedClinicItem,
                                      iconSize: 25,
                                      elevation: 16,
                                      onChanged: (newValue) async {
                                        setState(() {
                                          selectedClinicItem = newValue;
                                        });
                                      },
                                      items: model.clinics.map((item) {
                                        return DropdownMenuItem(
                                          child: AppText(
                                            projectViewModel.isArabic
                                                ? item.clinicNameArabic ?? ''
                                                : item.clinicNameEnglish ?? '',
                                            fontSize: 14,
                                            letterSpacing: -0.96,
                                            color: AppGlobal.appTextColor,
                                            fontWeight: FontWeight.normal,
                                            textAlign: TextAlign.left,
                                          ),
                                          value: item,
                                        );
                                      }).toList(),
                                    ),
                                  ),
                          ],
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 16,
                    ),
                    AppTextFieldCustom(
                      hintText: TranslationBase.of(context).addYourNote,
                      controller: noteController,
                      inputType: TextInputType.multiline,
                      maxLines: 25,
                      minLines: 4,
                      hasBorder: true,
                      onClick: () {},
                      onChanged: (value) {},
                      onFieldSubmitted: () {},
                    ),
                    SizedBox(
                      height: 16,
                    ),
                    // Row(
                    //   children: [
                    //     SvgPicture.asset(
                    //         'assets/images/svgs/save_as_draft.svg'),
                    //     SizedBox(
                    //       width: 4,
                    //     ),
                    //     AppText(
                    //       TranslationBase.of(context).saveAsDraft,
                    //       textAlign: TextAlign.start,
                    //       fontWeight: FontWeight.w600,
                    //       fontSize: 10,
                    //       color: Color(0xFF449BF1),
                    //     ),
                    //   ],
                    // )
                  ],
                ),
              ),
            ));
  }
}
