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/app_assets.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/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/lab/collapsing_list_view.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:provider/provider.dart';

import '../../widgets/chip/app_custom_chip_widget.dart';

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

  late MyAppointmentsViewModel myAppointmentsViewModel;

  @override
  Widget build(BuildContext context) {
    myAppointmentsViewModel = Provider.of<MyAppointmentsViewModel>(context, listen: false);
    return Scaffold(
      backgroundColor: AppColors.bgScaffoldColor,
      body: CollapsingListView(
        title: LocaleKeys.myDoctor.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.isPatientMyDoctorsLoading ? 5 : myAppointmentsVM.patientMyDoctorsList.length,
                  shrinkWrap: true,
                  physics: NeverScrollableScrollPhysics(),
                  padding: EdgeInsets.only(left: 24.h, right: 24.h),
                  itemBuilder: (context, index) {
                    return myAppointmentsVM.isPatientMyDoctorsLoading
                        ? Container(
                            decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
                              color: AppColors.whiteColor,
                              borderRadius: 20.h,
                              hasShadow: true,
                            ),
                            child: Padding(
                              padding: EdgeInsets.all(14.h),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      Image.network(
                                        "https://hmgwebservices.com/Images/MobileImages/DUBAI/unkown_female.png",
                                        width: 63.h,
                                        height: 63.h,
                                        fit: BoxFit.fill,
                                      ).circle(100).toShimmer2(isShow: true),
                                      SizedBox(width: 16.h),
                                      Expanded(
                                        child: Column(
                                          crossAxisAlignment: CrossAxisAlignment.start,
                                          children: [
                                            "Dr John Smith".toText16(isBold: true).toShimmer2(isShow: true),
                                            SizedBox(height: 8.h),
                                            Wrap(
                                              direction: Axis.horizontal,
                                              spacing: 3.h,
                                              runSpacing: 4.h,
                                              children: [
                                                AppCustomChipWidget(labelText: "").toShimmer2(isShow: true, width: 16.h),
                                                AppCustomChipWidget(labelText: "").toShimmer2(isShow: true, width: 16.h),
                                              ],
                                            ),
                                          ],
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          )
                        : AnimationConfiguration.staggeredList(
                            position: index,
                            duration: const Duration(milliseconds: 1000),
                            child: SlideAnimation(
                              verticalOffset: 100.0,
                              child: FadeInAnimation(
                                child: Container(
                                  decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
                                    color: AppColors.whiteColor,
                                    borderRadius: 20.h,
                                    hasShadow: true,
                                  ),
                                  child: Padding(
                                    padding: EdgeInsets.all(14.h),
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Row(
                                          crossAxisAlignment: CrossAxisAlignment.start,
                                          children: [
                                            Image.network(
                                              myAppointmentsVM.patientMyDoctorsList[index].doctorImageURL!,
                                              width: 63.h,
                                              height: 63.h,
                                              fit: BoxFit.fill,
                                            ).circle(100).toShimmer2(isShow: false),
                                            SizedBox(width: 16.h),
                                            Expanded(
                                              child: Column(
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                children: [
                                                  (myAppointmentsVM.patientMyDoctorsList[index].doctorName).toString().toText16(isBold: true).toShimmer2(isShow: false),
                                                  SizedBox(height: 8.h),
                                                  Wrap(
                                                    direction: Axis.horizontal,
                                                    spacing: 3.h,
                                                    runSpacing: 4.h,
                                                    children: [
                                                      AppCustomChipWidget(labelText: myAppointmentsVM.patientMyDoctorsList[index].clinicName).toShimmer2(isShow: false, width: 16.h),
                                                      AppCustomChipWidget(labelText: myAppointmentsVM.patientMyDoctorsList[index].projectName).toShimmer2(isShow: false, width: 16.h),
                                                    ],
                                                  ),
                                                ],
                                              ),
                                            ),
                                          ],
                                        ),
                                        Row(
                                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                          children: [
                                            "".toText16(),
                                            Utils.buildSvgWithAssets(icon: AppAssets.forward_arrow_icon, width: 15.h, height: 15.h, fit: BoxFit.contain, iconColor: AppColors.textColor),
                                          ],
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          );
                  },
                  separatorBuilder: (BuildContext cxt, int index) => SizedBox(height: 16.h),
                ),
                SizedBox(height: 60.h),
              ],
            );
          }),
        ),
      ),
    );
  }
}
