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/dependencies.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/authentication/authentication_view_model.dart';
import 'package:hmg_patient_app_new/features/book_appointments/models/resp_models/get_clinic_list_response_model.dart';
import 'package:hmg_patient_app_new/features/immediate_livecare/immediate_livecare_view_model.dart';
import 'package:hmg_patient_app_new/features/immediate_livecare/models/resp_models/get_livecare_immediate_clinics_response_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/book_appointment/livecare/immediate_livecare_payment_details.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart';
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_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/common_bottom_sheet.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart';
import 'package:provider/provider.dart';

class SelectLivecareClinicPage extends StatelessWidget {

  final VoidCallback? onNegativeClicked;
  late GetClinicsListResponseModel selectedClinic;

  SelectLivecareClinicPage({super.key, this.onNegativeClicked, required this.selectedClinic});

  late ImmediateLiveCareViewModel immediateLiveCareViewModel;

  @override
  Widget build(BuildContext context) {
    immediateLiveCareViewModel = Provider.of<ImmediateLiveCareViewModel>(context, listen: false);
    return Scaffold(
      backgroundColor: AppColors.bgScaffoldColor,
      body: Column(
        children: [
          Expanded(
            child: CollapsingListView(
              title: LocaleKeys.livecare.tr(context: context),
              child: SingleChildScrollView(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(height: 24.h),
                    LocaleKeys.livecareModalTop.tr(context: context).toText18(isBold: true),
                    SizedBox(height: 40.h),
                    Row(
                      children: [
                        Utils.buildSvgWithAssets(icon: AppAssets.immediate_service_icon, width: 58.w, height: 58.h),
                        SizedBox(width: 18.h),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              LocaleKeys.immediateService.tr(context: context).toText18(color: AppColors.textColor, isBold: true),
                              LocaleKeys.noNeedToWaitGetMedicalConsultation.tr(context: context).toText14(color: AppColors.greyTextColor, isBold: true),
                            ],
                          ),
                        ),
                      ],
                    ),
                    SizedBox(height: 24.h),
                    Row(
                      children: [
                        Utils.buildSvgWithAssets(icon: AppAssets.no_visit_icon, width: 58.h, height: 58.h),
                        SizedBox(width: 18.h),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              LocaleKeys.noVisitRequired.tr(context: context).toText18(color: AppColors.textColor, isBold: true),
                              LocaleKeys.livecarePoint5.tr(context: context).toText14(color: AppColors.greyTextColor, isBold: true),
                            ],
                          ),
                        ),
                      ],
                    ),
                    SizedBox(height: 24.h),
                    Row(
                      children: [
                        Utils.buildSvgWithAssets(icon: AppAssets.doctor_contact_icon, width: 58.h, height: 58.h),
                        SizedBox(width: 18.h),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              LocaleKeys.doctorWillContact.tr(context: context).toText18(color: AppColors.textColor, isBold: true),
                              LocaleKeys.specialisedDoctorWillContactYou.tr(context: context).toText14(color: AppColors.greyTextColor, isBold: true),
                            ],
                          ),
                        ),
                      ],
                    ),
                    SizedBox(height: 24.h),
                    Row(
                      children: [
                        Utils.buildSvgWithAssets(icon: AppAssets.free_med_delivery_icon, width: 58.h, height: 58.h),
                        SizedBox(width: 18.h),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              LocaleKeys.freeMedicineDelivery.tr(context: context).toText18(color: AppColors.textColor, isBold: true),
                              LocaleKeys.offersFreeMedicineDelivery.tr(context: context).toText14(color: AppColors.greyTextColor, isBold: true),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ],
                ).paddingSymmetrical(24.h, 0.h),
              ),
            ),
          ),
          getIt.get<AppState>().isAuthenticated
              ? Column(children: [
                  CustomButton(
                    text: LocaleKeys.yesPleasImInAHurry.tr(context: context),
                    onPressed: () async {
                  Navigator.pop(context);
                  GetLiveCareClinicListResponseModel liveCareClinic = GetLiveCareClinicListResponseModel(
                    iD: selectedClinic.liveCareClinicID,
                    serviceID: selectedClinic.liveCareServiceID,
                    serviceName: selectedClinic.clinicDescription,
                    serviceNameN: selectedClinic.clinicDescriptionN,
                  );

                  immediateLiveCareViewModel.setLiveCareSelectedCallType(1);
                  immediateLiveCareViewModel.setImmediateLiveCareSelectedClinic(liveCareClinic);
                  LoaderBottomSheet.showLoader(loadingText: LocaleKeys.fetchingFeesPleaseWait.tr(context: context));
                  await immediateLiveCareViewModel.getLiveCareImmediateAppointmentFees(onSuccess: (val) {
                    LoaderBottomSheet.hideLoader();
                    Navigator.of(getIt.get<NavigationService>().navigatorKey.currentContext!).push(
                      CustomPageRoute(
                        page: ImmediateLiveCarePaymentDetails(),
                      ),
                    );
                  }, onError: (err) {
                    LoaderBottomSheet.hideLoader();
                    showCommonBottomSheetWithoutHeight(
                      context,
                      child: Utils.getErrorWidget(loadingText: err),
                      callBackFunc: () {},
                      isFullScreen: false,
                      isCloseButtonVisible: true,
                    );
                  });
                },
                backgroundColor: AppColors.primaryRedColor,
                borderColor: AppColors.primaryRedColor,
                textColor: AppColors.whiteColor,
                fontSize: 16.f,
                isBold: true,
                borderRadius: 10.r,
                padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                height: 50.h,
                icon: AppAssets.livecare_book_icon,
                iconColor: AppColors.whiteColor,
                iconSize: 18.h,
              ).paddingSymmetrical(24.h, 0.h),
              SizedBox(height: 16.h),
              CustomButton(
                text: LocaleKeys.noThanksPhysicalVisit.tr(context: context),
                onPressed: () {
                  Navigator.of(context).pop();
                  onNegativeClicked?.call();
                },
                backgroundColor: AppColors.secondaryLightRedColor,
                borderColor: AppColors.secondaryLightRedColor,
                textColor: AppColors.primaryRedColor,
                fontSize: 16.f,
                isBold: true,
                borderRadius: 10.r,
                padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                height: 50.h,
              ).paddingSymmetrical(24.h, 0.h),
              SizedBox(height: 24.h),
                ])
              : CustomButton(
                  text: LocaleKeys.loginToUseServiceLiveCare.tr(),
                  onPressed: () async {
                    await getIt.get<AuthenticationViewModel>().onLoginPressed();
                  },
                  backgroundColor: AppColors.primaryRedColor,
                  borderColor: AppColors.primaryRedColor,
                  textColor: AppColors.whiteColor,
                  fontSize: 16.f,
                  isBold: true,
                  borderRadius: 12.r,
                  padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                  height: 50.h,
                  icon: AppAssets.login1,
                  iconColor: AppColors.whiteColor,
                  iconSize: 24.h,
                ).paddingSymmetrical(24.h, 120.h),
        ],
      ),
    );
  }
}
