import 'package:easy_localization/easy_localization.dart'
    show tr, StringTranslateExtension;
import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.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/doctor_filter/doctor_filter_view_model.dart';
import 'package:hmg_patient_app_new/features/my_appointments/appointment_via_region_viewmodel.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/book_appointment/doctor_filter/clinic_item.dart';
import 'package:hmg_patient_app_new/theme/colors.dart' show AppColors;
import 'package:provider/provider.dart';


class ClinicBottomSheet extends StatelessWidget {
  late BookAppointmentsViewModel appointmentsViewModel;
  late AppointmentViaRegionViewmodel regionalViewModel;
  final TextEditingController searchText = TextEditingController();

  ClinicBottomSheet({super.key});

  @override
  Widget build(BuildContext context) {
    appointmentsViewModel = Provider.of<BookAppointmentsViewModel>(context);
    regionalViewModel = Provider.of<AppointmentViaRegionViewmodel>(context);
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          LocaleKeys.selectClinic.tr(),
          style: TextStyle(
            fontSize: 21,
            fontWeight: FontWeight.w600,
            color: AppColors.blackColor,
          ),
        ),
        SizedBox(height: 24.h),
        SizedBox(
          height: MediaQuery.sizeOf(context).height * .4,
          child: ListView.separated(
              itemBuilder: (_, index)
              {
                return AnimationConfiguration.staggeredList(
                  position: index,
                  duration: const Duration(milliseconds: 500),
                  child: SlideAnimation(
                    verticalOffset: 100.0,
                    child: FadeInAnimation(
                      child: AnimatedContainer(
                        duration: Duration(milliseconds: 300),
                        curve: Curves.easeInOut,
                        decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.h, hasShadow: true),
                        child: ClinicItem(
                          isArabic: appointmentsViewModel.isArabic(),
                          clinicName: appointmentsViewModel.searchedClinicList[index],
                        ),
                      ),
                    ),
                  ),

              ).onPress(() {
                  context.read<DoctorFilterViewModel>()
                    .setSelectedClinicForFilter(appointmentsViewModel.searchedClinicList[index]);
                 Navigator.pop(context);
                });},
              separatorBuilder: (_, __) => SizedBox(
                    height: 16.h,
                  ),
              itemCount: appointmentsViewModel.searchedClinicList.length ?? 0),
        )
      ],
    );
  }
}
