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/insurance/insurance_view_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/lab/lab_result_item_view.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';
import 'package:provider/provider.dart';

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

  late InsuranceViewModel insuranceViewModel;

  @override
  Widget build(BuildContext context) {
    insuranceViewModel = Provider.of<InsuranceViewModel>(context);
    return Consumer<InsuranceViewModel>(builder: (context, insuranceVM, child) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              LocaleKeys.history.tr(context: context).toText24(isBold: true),
              Utils.buildSvgWithAssets(icon: AppAssets.close_bottom_sheet_icon).onPress(() {
                Navigator.of(context).pop();
              }),
            ],
          ).paddingSymmetrical(24.h, 24.h),
          insuranceVM.isInsuranceHistoryLoading
              ? LabResultItemView(
                  onTap: () {},
                  labOrder: null,
                  index: 0,
                  isLoading: true,
                ).paddingSymmetrical(24.h, 24.h)
              : insuranceVM.patientInsuranceCardHistoryList.isNotEmpty
                  ? ListView.separated(
                      itemCount: insuranceVM.patientInsuranceCardHistoryList.length,
                      shrinkWrap: true,
                      padding: const EdgeInsets.only(left: 0, right: 8),
                      itemBuilder: (context, index) {
                        return AnimationConfiguration.staggeredList(
                          position: index,
                          duration: const Duration(milliseconds: 1000),
                          child: SlideAnimation(
                            verticalOffset: 100.0,
                            child: FadeInAnimation(
                              child: Container(
                                // height: 120.h,
                                decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
                                  color: AppColors.whiteColor,
                                  borderRadius: 24,
                                ),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Row(
                                      children: [
                                        CustomButton(
                                          text: insuranceVM.patientInsuranceCardHistoryList[index].statusDescription ?? "",
                                          onPressed: () {},
                                          backgroundColor: AppColors.primaryRedColor.withOpacity(0.1),
                                          borderColor: AppColors.primaryRedColor.withOpacity(0.0),
                                          textColor: AppColors.primaryRedColor,
                                          fontSize: 10,
                                          isBold: true,
                                          borderRadius: 8,
                                          padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                                          height: 30.h,
                                        ),
                                      ],
                                    ),
                                    SizedBox(height: 8.h),
                                    // "Haroon Amjad".toText16(isBold: true),
                                    SizedBox(height: 8.h),
                                    Row(
                                      children: [
                                        Wrap(
                                          direction: Axis.horizontal,
                                          spacing: 4.h,
                                          runSpacing: 4.h,
                                          children: [
                                            AppCustomChipWidget(
                                              labelText: "File No.: ${insuranceVM.patientInsuranceCardHistoryList[index].patientID}",
                                            ),
                                            AppCustomChipWidget(
                                              labelText: insuranceVM.patientInsuranceCardHistoryList[index].createdOn!,
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                  ],
                                ).paddingSymmetrical(16.h, 16.h),
                              ).paddingSymmetrical(24.h, 0.h),
                            ),
                          ),
                        );
                      },
                      separatorBuilder: (BuildContext cxt, int index) => SizedBox(height: 16.h),
                    )
                  : Utils.getNoDataWidget(
                      context,
                      noDataText: LocaleKeys.noInsuranceUpdateRequest.tr(context: context),
                      // isSmallWidget: true,
                      // width: 62,
                      // height: 62,
                    ),
        ],
      );
    });
  }
}
