import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/utils/date_util.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/models/resp_models/patient_insurance_approval_response_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/utils/appointment_type.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/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';

class InsuranceApprovalCard extends StatelessWidget {
  InsuranceApprovalCard({super.key, required this.insuranceApprovalResponseModel, required this.isLoading, required this.appState});

  InsuranceApprovalResponseModel insuranceApprovalResponseModel;
  AppState appState;
  bool isLoading;

  @override
  Widget build(BuildContext context) {
    return 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: [
            Wrap(
              alignment: WrapAlignment.start,
              direction: Axis.horizontal,
              spacing: 6.h,
              runSpacing: 6.h,
              children: [
                AppCustomChipWidget(
                  labelText: isLoading ? "Approved" : insuranceApprovalResponseModel.approvalStatusDescption,
                  backgroundColor: insuranceApprovalResponseModel.status == 9 ? AppColors.successColor.withOpacity(0.1) : AppColors.primaryRedColor.withOpacity(0.1),
                  textColor: insuranceApprovalResponseModel.status == 9 ? AppColors.successColor : AppColors.primaryRedColor,
                ).toShimmer2(isShow: isLoading),
                AppCustomChipWidget(
                  icon: isLoading ? AppAssets.walkin_appointment_icon : (!insuranceApprovalResponseModel.isLiveCareAppointment! ? AppAssets.walkin_appointment_icon : AppAssets.small_livecare_icon),
                  iconColor: isLoading
                      ? AppColors.textColor
                      : !insuranceApprovalResponseModel.isLiveCareAppointment!
                          ? AppColors.textColor
                          : AppColors.whiteColor,
                  labelText: isLoading
                      ? "Walk In"
                      : insuranceApprovalResponseModel.isLiveCareAppointment!
                          ? LocaleKeys.livecare.tr(context: context)
                          : "Walk In".needTranslation,
                  backgroundColor: isLoading ? AppColors.greyColor : (!insuranceApprovalResponseModel.isLiveCareAppointment! ? AppColors.greyColor : AppColors.successColor),
                  textColor: isLoading ? AppColors.textColor : (!insuranceApprovalResponseModel.isLiveCareAppointment! ? AppColors.textColor : AppColors.whiteColor),
                ).toShimmer2(isShow: isLoading),
                AppCustomChipWidget(
                  labelText: isLoading
                      ? "OutPatient"
                      : appState.isArabic()
                          ? insuranceApprovalResponseModel.isInOutPatientDescriptionN!
                          : insuranceApprovalResponseModel.isInOutPatientDescription!,
                  backgroundColor: AppColors.primaryRedColor.withOpacity(0.1),
                  textColor: AppColors.primaryRedColor,
                ).toShimmer2(isShow: isLoading),
              ],
            ).toShimmer2(isShow: isLoading),
            SizedBox(height: 16.h),
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Image.network(
                  isLoading ? "https://hmgwebservices.com/Images/MobileImages/OALAY/1439.png" : insuranceApprovalResponseModel.doctorImageURL!,
                  width: 63.h,
                  height: 63.h,
                  fit: BoxFit.cover,
                ).circle(100).toShimmer2(isShow: isLoading),
                SizedBox(width: 16.h),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      (isLoading ? "John Smith" : insuranceApprovalResponseModel.doctorName!).toText16(isBold: true).toShimmer2(isShow: isLoading),
                      Wrap(
                        direction: Axis.horizontal,
                        spacing: 3.h,
                        runSpacing: 4.h,
                        children: [
                          // AppCustomChipWidget(labelText: isLoading ? "Approved" : insuranceApprovalResponseModel.approvalStatusDescption!,
                          //   backgroundColor: insuranceApprovalResponseModel.status == 9 ? AppColors.successColor.withValues(alpha: 0.1) : AppColors.primaryRedColor.withValues(alpha: 0.1),
                          //   textColor: insuranceApprovalResponseModel.status == 9 ? AppColors.successColor : AppColors.primaryRedColor,
                          // ).toShimmer2(isShow: isLoading),
                          AppCustomChipWidget(labelText: isLoading ? "Cardiology" : insuranceApprovalResponseModel.clinicName!).toShimmer2(isShow: isLoading),
                          AppCustomChipWidget(
                                  icon: AppAssets.doctor_calendar_icon,
                                  labelText: isLoading ? "Cardiology" : DateUtil.formatDateToDate(DateUtil.convertStringToDate(insuranceApprovalResponseModel.submitOn), false))
                              .toShimmer2(isShow: isLoading),
                          isLoading
                              ? SizedBox.shrink()
                              : AppCustomChipWidget(
                                      labelText: isLoading ? LocaleKeys.approvalNo.tr(context: context) : "${LocaleKeys.approvalNo.tr(context: context)} ${insuranceApprovalResponseModel.approvalNo}")
                                  .toShimmer2(isShow: isLoading),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Transform.flip(
                    flipX: appState.isArabic(), child: Utils.buildSvgWithAssets(icon: AppAssets.forward_arrow_icon_small, width: 15.h, height: 15.h, fit: BoxFit.contain, iconColor: AppColors.textColor)),
              ],
            ).toShimmer2(isShow: isLoading),
          ],
        ),
      ),
    );
  }
}
