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/medical_file/medical_file_view_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.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 AllergiesListPage extends StatelessWidget {
  AllergiesListPage({super.key});

  late MedicalFileViewModel medicalFileViewModel;

  @override
  Widget build(BuildContext context) {
    medicalFileViewModel = Provider.of<MedicalFileViewModel>(context, listen: false);
    return Scaffold(
      backgroundColor: AppColors.bgScaffoldColor,
      body: CollapsingListView(
        title: LocaleKeys.allergies.tr(),
        child: SingleChildScrollView(
          child: Consumer<MedicalFileViewModel>(builder: (context, medicalFileVM, child) {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(height: 16.h),
                ListView.separated(
                  scrollDirection: Axis.vertical,
                  itemCount: medicalFileVM.isPatientAllergiesListLoading
                      ? 5
                      : medicalFileVM.patientAllergiesList.isNotEmpty
                          ? medicalFileVM.patientAllergiesList.length
                          : 1,
                  shrinkWrap: true,
                  physics: NeverScrollableScrollPhysics(),
                  padding: EdgeInsets.only(left: 24.h, right: 24.h),
                  itemBuilder: (context, index) {
                    return medicalFileVM.isPatientAllergiesListLoading
                        ? 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: [
                                      Utils.buildSvgWithAssets(icon: AppAssets.allergy_info_icon, width: 36.w, height: 36.h, fit: BoxFit.contain, applyThemeColor: false).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),
                                              ],
                                            ),
                                          ],
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          )
                        : medicalFileVM.patientAllergiesList.isNotEmpty
                            ? 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: false,
                                      ),
                                      child: Padding(
                                        padding: EdgeInsets.all(16.h),
                                        child: Column(
                                          crossAxisAlignment: CrossAxisAlignment.start,
                                          children: [
                                            Utils.buildSvgWithAssets(icon: AppAssets.allergy_info_icon, width: 36.w, height: 36.h, fit: BoxFit.contain, applyThemeColor: false),
                                            SizedBox(height: 16.h),
                                            Row(
                                              crossAxisAlignment: CrossAxisAlignment.start,
                                              children: [
                                                Expanded(
                                                  child: Column(
                                                    crossAxisAlignment: CrossAxisAlignment.start,
                                                    children: [
                                                      (medicalFileVM.patientAllergiesList[index].description).toString().toText16(isBold: true).toShimmer2(isShow: false),
                                                      (medicalFileVM.patientAllergiesList[index].remarks).toString().toText12(),
                                                    ],
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              )
                            : Utils.getNoDataWidget(context, noDataText: LocaleKeys.noAllergiesDataFound.tr());
                  },
                  separatorBuilder: (BuildContext cxt, int index) => SizedBox(height: 16.h),
                ),
                SizedBox(height: 60.h),
              ],
            );
          }),
        ),
      ),
    );
  }
}
