import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:hmg_patient_app_new/core/app_assets.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/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/features/insurance/models/resp_models/patient_insurance_details_response_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/insurance/widgets/insurance_update_details_card.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/common_bottom_sheet.dart';
import 'package:provider/provider.dart';

class PatientInsuranceCard extends StatelessWidget {
  PatientInsuranceCard({super.key, required this.insuranceCardDetailsModel, required this.isInsuranceExpired});

  PatientInsuranceDetailsResponseModel insuranceCardDetailsModel;
  bool isInsuranceExpired = false;

  late InsuranceViewModel insuranceViewModel;

  @override
  Widget build(BuildContext context) {
    insuranceViewModel = Provider.of<InsuranceViewModel>(context);
    return Container(
      width: double.infinity,
      decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
        color: AppColors.whiteColor,
        borderRadius: 24,
      ),
      child: Padding(
        padding: EdgeInsets.all(16.h),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    "Haroon Amjad".toText18(isBold: true),
                    "Policy: ${insuranceCardDetailsModel.insurancePolicyNo}".toText12(isBold: true, color: AppColors.lightGrayColor),
                  ],
                ),
                CustomButton(
                  icon: isInsuranceExpired ? AppAssets.cancel_circle_icon : AppAssets.insurance_active_icon,
                  iconColor: isInsuranceExpired ? AppColors.primaryRedColor : AppColors.successColor,
                  iconSize: 13.h,
                  text: isInsuranceExpired ? "Insurance Expired" : "Insurance Active",
                  onPressed: () {},
                  backgroundColor: isInsuranceExpired ? AppColors.primaryRedColor.withOpacity(0.15) : AppColors.successColor.withOpacity(0.15),
                  borderColor: isInsuranceExpired ? AppColors.primaryRedColor.withOpacity(0.01) : AppColors.successColor.withOpacity(0.01),
                  textColor: isInsuranceExpired ? AppColors.primaryRedColor : AppColors.successColor,
                  fontSize: 10,
                  fontWeight: FontWeight.w500,
                  borderRadius: 12,
                  padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                  height: 30.h,
                ),
              ],
            ),
            SizedBox(height: 12.h),
            insuranceCardDetailsModel.groupName!.toText12(isBold: true),
            insuranceCardDetailsModel.companyName!.toText12(isBold: true),
            SizedBox(height: 8.h),
            Wrap(
              direction: Axis.horizontal,
              spacing: 6.h,
              runSpacing: 6.h,
              children: [
                Row(
                  children: [
                    CustomButton(
                      icon: AppAssets.doctor_calendar_icon,
                      iconColor: AppColors.blackColor,
                      iconSize: 13.h,
                      text: "${LocaleKeys.expiryDate.tr(context: context)} ${DateUtil.formatDateToDate(DateUtil.convertStringToDate(insuranceCardDetailsModel.cardValidTo), false)}",
                      onPressed: () {},
                      backgroundColor: AppColors.greyColor,
                      borderColor: AppColors.greyColor,
                      textColor: AppColors.blackColor,
                      fontSize: 10,
                      fontWeight: FontWeight.w500,
                      borderRadius: 12,
                      padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                      height: 30.h,
                    ),
                  ],
                ),
                Row(
                  children: [
                    CustomButton(
                      text: "Patient Card ID: ${insuranceCardDetailsModel.patientCardID}",
                      onPressed: () {},
                      backgroundColor: AppColors.greyColor,
                      borderColor: AppColors.greyColor,
                      textColor: AppColors.blackColor,
                      fontSize: 10,
                      fontWeight: FontWeight.w500,
                      borderRadius: 12,
                      padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                      height: 30.h,
                    ),
                  ],
                ),
              ],
            ),
            SizedBox(height: 10.h),
            isInsuranceExpired
                ? CustomButton(
                    icon: AppAssets.update_insurance_card_icon,
                    iconColor: AppColors.successColor,
                    iconSize: 15.h,
                    text: "${LocaleKeys.updateInsurance.tr(context: context)} ${LocaleKeys.updateInsuranceSubtitle.tr(context: context)}",
                    onPressed: () {
                      insuranceViewModel.setIsInsuranceUpdateDetailsLoading(true);
                      insuranceViewModel.getPatientInsuranceDetailsForUpdate();
                      showCommonBottomSheet(context,
                          child: PatientInsuranceCardUpdateCard(), callBackFunc: () {}, title: "", height: ResponsiveExtension.screenHeight * 0.42, isCloseButtonVisible: false, isFullScreen: false);
                    },
                    backgroundColor: AppColors.bgGreenColor.withOpacity(0.20),
                    borderColor: AppColors.bgGreenColor.withOpacity(0.0),
                    textColor: AppColors.bgGreenColor,
                    fontSize: 14,
                    fontWeight: FontWeight.w500,
                    borderRadius: 12,
                    padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                    height: 40.h,
                  )
                : Container(),
          ],
        ),
      ),
    ).paddingSymmetrical(24.h, 0.h);
  }
}
