import 'package:easy_localization/easy_localization.dart'
    show tr, StringTranslateExtension;
import 'package:flutter/cupertino.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_view_model.dart';
import 'package:hmg_patient_app_new/features/my_appointments/appointment_via_region_viewmodel.dart';
import 'package:hmg_patient_app_new/features/my_appointments/models/facility_selection.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/appointments/widgets/faculity_selection/facility_selection_item.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:provider/provider.dart' show Provider;

class FacilityTypeSelectionWidget extends StatelessWidget {
  late BookAppointmentsViewModel bookAppointmentViewModel;
  late AppointmentViaRegionViewmodel regionalViewModel;
  final String selectedRegion;

  FacilityTypeSelectionWidget({super.key, required this.selectedRegion});

  @override
  Widget build(BuildContext context) {
    bookAppointmentViewModel = Provider.of<BookAppointmentsViewModel>(context);
    regionalViewModel = Provider.of<AppointmentViaRegionViewmodel>(context);
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          LocaleKeys.selectFacility.tr(),
          style: TextStyle(
            fontSize: 21,
            fontWeight: FontWeight.w600,
            color: AppColors.blackColor,
          ),
        ),
        Text(
          LocaleKeys.selectFacilitiesSubTitle.tr(),
          style: TextStyle(
            fontSize: 16,
            fontWeight: FontWeight.w600,
            color: AppColors.greyTextColor,
          ),
        ),
        SizedBox(height: 24.h),
        FacilitySelectionItem(
          svgPath: AppAssets.hmg,
          title: "HMG",
          subTitle: LocaleKeys.hospitalsWithCount.tr(namedArgs: {
            'count':
                "${bookAppointmentViewModel.hospitalList?.registeredDoctorMap?[selectedRegion]?.hmgSize ?? 0}"
          }),
        ).onPress(
          () {
            if(bookAppointmentViewModel.hospitalList?.registeredDoctorMap?[selectedRegion]?.hmgSize != 0) {
              regionalViewModel.setFacility(FacilitySelection.HMG.name);
              regionalViewModel.setBottomSheetState(
                  AppointmentViaRegionState.HOSPITAL_SELECTION);
            }
          },
        ),
        SizedBox(height: 16.h),
        FacilitySelectionItem(
            svgPath: AppAssets.hmc,
            title: "HMC",
            subTitle: LocaleKeys.medicalCentersWithCount.tr(namedArgs: {
              'count':
                  "${bookAppointmentViewModel.hospitalList?.registeredDoctorMap?[selectedRegion]?.hmcSize ?? 0}"
            })).onPress(
          () {
            if(bookAppointmentViewModel.hospitalList?.registeredDoctorMap?[selectedRegion]?.hmcSize!= 0 ) {
              regionalViewModel.setFacility(FacilitySelection.HMC.name);
              regionalViewModel.setBottomSheetState(
                  AppointmentViaRegionState.HOSPITAL_SELECTION);
            }
          },
        ),
      ],
    );
  }
}
