import 'package:easy_localization/easy_localization.dart';
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/core/utils/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/models/resp_models/patient_appointment_history_response_model.dart';
import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/appointments/widgets/appointment_card.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart';
import 'package:provider/provider.dart';

class EyeMeasurementsAppointmentsPage extends StatelessWidget {
  EyeMeasurementsAppointmentsPage({super.key});

  late BookAppointmentsViewModel bookAppointmentsViewModel;

  @override
  Widget build(BuildContext context) {
    bookAppointmentsViewModel = Provider.of<BookAppointmentsViewModel>(context, listen: false);
    return Scaffold(
      backgroundColor: AppColors.bgScaffoldColor,
      body: CollapsingListView(
        title: LocaleKeys.eyeMeasurements.tr(context: context),
        child: SingleChildScrollView(
          child: Consumer<MyAppointmentsViewModel>(builder: (context, myAppointmentsVM, child) {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(height: 16.h),
                ListView.separated(
                  scrollDirection: Axis.vertical,
                  itemCount: myAppointmentsVM.isEyeMeasurementsAppointmentsLoading
                      ? 5
                      : myAppointmentsVM.patientEyeMeasurementsAppointmentsHistoryList.isNotEmpty
                          ? myAppointmentsVM.patientEyeMeasurementsAppointmentsHistoryList.length
                          : 1,
                  shrinkWrap: true,
                  physics: NeverScrollableScrollPhysics(),
                  padding: EdgeInsets.only(left: 24.h, right: 24.h),
                  itemBuilder: (context, index) {
                    return myAppointmentsVM.isEyeMeasurementsAppointmentsLoading
                        ? Container(
                            decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.h, hasShadow: true),
                            child: AppointmentCard(
                              patientAppointmentHistoryResponseModel: PatientAppointmentHistoryResponseModel(),
                              myAppointmentsViewModel: myAppointmentsVM,
                              bookAppointmentsViewModel: bookAppointmentsViewModel,
                              isLoading: true,
                              isFromHomePage: false,
                            ),
                          )
                        : myAppointmentsVM.patientEyeMeasurementsAppointmentsHistoryList.isNotEmpty
                            ? AnimationConfiguration.staggeredList(
                                position: index,
                                duration: const Duration(milliseconds: 1000),
                                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: AppointmentCard(
                                        patientAppointmentHistoryResponseModel: myAppointmentsVM.patientEyeMeasurementsAppointmentsHistoryList[index],
                                        myAppointmentsViewModel: myAppointmentsVM,
                                        bookAppointmentsViewModel: bookAppointmentsViewModel,
                                        isLoading: false,
                                        isFromHomePage: false,
                                        isForEyeMeasurements: true,
                                      ),
                                    ),
                                  ),
                                ),
                              )
                            : Utils.getNoDataWidget(context, noDataText: LocaleKeys.noOphthalmologyAppointments.tr(context: context));
                  },
                  separatorBuilder: (BuildContext cxt, int index) => SizedBox(height: 16.h),
                ),
                SizedBox(height: 60.h),
              ],
            );
          }),
        ),
      ),
    );
  }
}
