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/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/book_appointments/book_appointments_view_model.dart';
import 'package:hmg_patient_app_new/features/book_appointments/models/resp_models/doctors_list_response_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/book_appointment/widgets/appointment_calendar.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:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';

class DoctorCard extends StatelessWidget {
  DoctorCard({super.key, required this.doctorsListResponseModel, required this.isLoading, required this.bookAppointmentsViewModel});

  DoctorsListResponseModel doctorsListResponseModel;
  bool isLoading = false;
  BookAppointmentsViewModel bookAppointmentsViewModel;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
        color: AppColors.whiteColor,
        borderRadius: 24.h,
        hasShadow: false,
      ),
      child: Padding(
        padding: EdgeInsets.all(14.h),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Image.network(
                  isLoading
                      ? "https://hmgwebservices.com/Images/MobileImages/OALAY/1439.png"
                      : doctorsListResponseModel.doctorImageURL ?? "https://hmgwebservices.com/Images/MobileImages/OALAY/1439.png",
                  width: 63.h,
                  height: 63.h,
                  fit: BoxFit.fill,
                ).circle(100).toShimmer2(isShow: isLoading),
                SizedBox(width: 8.h),
                Expanded(
                  flex: 9,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          SizedBox(
                            width: MediaQuery.of(context).size.width * 0.49,
                            child: (isLoading ? "Dr John Smith" : "${doctorsListResponseModel.doctorTitle} ${doctorsListResponseModel.name}").toString().toText16(isBold: true, maxlines: 1),
                          ).toShimmer2(isShow: isLoading),
                          Image.network(
                            isLoading ? "https://hmgwebservices.com/Images/flag/SYR.png" : doctorsListResponseModel.nationalityFlagURL ?? "https://hmgwebservices.com/Images/flag/SYR.png",
                            width: 20.h,
                            height: 15.h,
                            fit: BoxFit.fill,
                          ).toShimmer2(isShow: isLoading),
                        ],
                      ),
                      SizedBox(height: 2.h),
                      (isLoading
                              ? "Consultant Cardiologist"
                              : doctorsListResponseModel.speciality!.isNotEmpty
                                  ? doctorsListResponseModel.speciality!.first
                                  : "")
                          .toString()
                          .toText12(fontWeight: FontWeight.w500, color: AppColors.greyTextColor, maxLine: 1)
                          .toShimmer2(isShow: isLoading),
                    ],
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Utils.buildSvgWithAssets(icon: AppAssets.doctor_profile_icon, width: 20.h, height: 20.h, fit: BoxFit.scaleDown).toShimmer2(isShow: isLoading),
                ),
              ],
            ),
            SizedBox(height: 12.h),
            Wrap(
              direction: Axis.horizontal,
              spacing: 3.h,
              runSpacing: 4.h,
              children: [
                AppCustomChipWidget(
                  labelText: "Clinic: ${isLoading ? "Cardiologist" : doctorsListResponseModel.clinicName}".needTranslation,
                ).toShimmer2(isShow: isLoading),
                AppCustomChipWidget(
                  labelText: "Branch: ${isLoading ? "Olaya Hospital" : doctorsListResponseModel.projectName}".needTranslation,
                ).toShimmer2(isShow: isLoading),
                AppCustomChipWidget(
                  icon: AppAssets.rating_icon,
                  iconColor: AppColors.ratingColorYellow,
                  labelText: "Rating: ${isLoading ? 4.78 : doctorsListResponseModel.decimalDoctorRate}".needTranslation,
                ).toShimmer2(isShow: isLoading),
              ],
            ),
            SizedBox(height: 12.h),
            CustomButton(
              text: LocaleKeys.bookAppo.tr(context: context),
              onPressed: () async {
                bookAppointmentsViewModel.setSelectedDoctor(doctorsListResponseModel);
                LoaderBottomSheet.showLoader();
                await bookAppointmentsViewModel.getDoctorFreeSlots(
                    isBookingForLiveCare: false,
                    onSuccess: (dynamic respData) async {
                      LoaderBottomSheet.hideLoader();
                      showCommonBottomSheetWithoutHeight(
                        title: "Pick a Date".needTranslation,
                        context,
                        child: AppointmentCalendar(),
                        isFullScreen: false,
                        isCloseButtonVisible: true,
                        callBackFunc: () {},
                      );
                    },
                    onError: (err) {
                      LoaderBottomSheet.hideLoader();
                      showCommonBottomSheetWithoutHeight(
                        context,
                        child: Utils.getErrorWidget(loadingText: err),
                        callBackFunc: () {},
                        isFullScreen: false,
                        isCloseButtonVisible: true,
                      );
                    });
              },
              backgroundColor: Color(0xffFEE9EA),
              borderColor: Color(0xffFEE9EA),
              textColor: Color(0xffED1C2B),
              fontSize: 14,
              fontWeight: FontWeight.w500,
              borderRadius: 12,
              padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
              height: 40.h,
              icon: AppAssets.add_icon,
              iconColor: AppColors.primaryRedColor,
              iconSize: 15.h,
            ).toShimmer2(isShow: isLoading),
          ],
        ),
      ),
    );
  }
}
