import 'package:hmg_patient_app/models/Appointments/DoctorListResponse.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

typedef OnRegionSelected = Function(String);
class ResultByRegion extends StatelessWidget {
  List<DoctorList> doctorsList = [];
  RegionList patientDoctorAppointmentListHospital;
  OnRegionSelected onRegionSelected;
  ResultByRegion(
      {required this.doctorsList,
        required this.patientDoctorAppointmentListHospital,
        required this.onRegionSelected
      });

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
         child: patientDoctorAppointmentListHospital
              .registeredDoctorMap?.isNotEmpty ==
              true
              ? ListView.separated(
            addAutomaticKeepAlives: true,
            physics: BouncingScrollPhysics(),
            separatorBuilder: (context, index) {
              return Material(
                color: Color(0xFFf5f5f5),
                child: SizedBox(
                  height: 12,
                ),
              );
            },
            itemBuilder: (context, index) {
              String key = patientDoctorAppointmentListHospital
                  .registeredDoctorMap?.keys
                  .toList()[index] ??
                  '';

              return InkWell(
                onTap: (){
                  onRegionSelected(key);
                },
                child: RegionTitle(
                  title: key,
                  hmcCount:
                  "${patientDoctorAppointmentListHospital.registeredDoctorMap?[key]?.hmcSize ?? 0}",
                  hmgCount:
                  "${patientDoctorAppointmentListHospital.registeredDoctorMap?[key]?.hmgSize ?? 0}",
                ),
              );

            },
            itemCount: patientDoctorAppointmentListHospital
                .registeredDoctorMap?.length ??
                0,
          )
              : getNoDataWidget(context),
        ),
      ],
    );
  }
}


class RegionTitle extends StatelessWidget {
  final String title;
  final String hmcCount;
  final String hmgCount;

  const RegionTitle(
      {super.key,
        required this.title,
        required this.hmcCount,
        required this.hmgCount});

  @override
  Widget build(BuildContext context) {
    return Material(
      color: CustomColors.white,
      child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
          child: Row(
          children: [
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    title,
                    style: TextStyle(
                        fontSize: 22, color: Colors.black, fontWeight: FontWeight.w700),
                  ),
                  SizedBox(
                    height: 8,
                  ),
                  Row(
                    children: [
                        Visibility(
                          visible: hmgCount != "0",
                          child: Row(
                            children: [
                              SvgPicture.asset(
                                'assets/images/svg/HMG.svg',
                                width: 10,
                                height: 10,
                              ),
                              SizedBox(
                                width: 8,
                              ),
                              Text(
                                "${TranslationBase.of(context).HospitalString(num.parse(hmgCount)).replaceAll("@", hmgCount)}",
                                style: TextStyle(
                                    fontSize: 14,
                                    color: Color(0xFFD02127),
                                    fontWeight: FontWeight.w600),
                              ),
                            ],
                          ),
                        ),
                        Visibility(
                            visible: hmcCount != "0" && hmgCount != "0",
                            child: Text(", ")),
                        Visibility(
                          visible: hmcCount != "0",
                          child: Row(
                            children: [
                              SvgPicture.asset(
                                'assets/images/svg/HMC.svg',
                                width: 10,
                                height: 10,
                              ),
                              SizedBox(
                                width: 8,
                              ),
                              Text(
                                "${TranslationBase.of(context).MedicalCenterString(num.parse(hmcCount)).replaceAll("@", hmcCount)}",
                                style: TextStyle(
                                    fontSize: 14,
                                    color: Color(0xFF40ACC9),
                                    fontWeight: FontWeight.w600),
                              ),
                            ],
                          ),
                        ),
                      ],
                  ),
                ],
              ),
            ),
            Padding(
              padding: EdgeInsets.all(8),
              child: Center(
                child: Icon(
                  Icons.arrow_forward_ios,
                  color: CustomColors.black,
                  size: 16,
                ),
              ),
            ),
          ],
        )
      ),
    );
  }
}
