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/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/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';

class AppointmentDoctorCard extends StatelessWidget {
  AppointmentDoctorCard({super.key, required this.patientAppointmentHistoryResponseModel, required this.onRescheduleTap, required this.onCancelTap, required this.onAskDoctorTap});

  PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel;
  late Function onRescheduleTap;
  late Function onCancelTap;
  late Function onAskDoctorTap;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
        color: AppColors.whiteColor,
        borderRadius: 20.h,
        hasShadow: true,
      ),
      child: Padding(
        padding: EdgeInsets.all(16.h),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Image.network(
                  patientAppointmentHistoryResponseModel.doctorImageURL!,
                  width: 63.h,
                  height: 63.h,
                  fit: BoxFit.fill,
                ).circle(100),
                SizedBox(width: 16.h),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    patientAppointmentHistoryResponseModel.doctorNameObj!.toText16(isBold: true),
                    SizedBox(height: 8.h),
                    Row(
                      children: [
                        CustomButton(
                          text: patientAppointmentHistoryResponseModel.clinicName!,
                          onPressed: () {},
                          backgroundColor: AppColors.greyColor,
                          borderColor: AppColors.greyColor,
                          textColor: AppColors.blackColor,
                          fontSize: 10,
                          fontWeight: FontWeight.w500,
                          borderRadius: 8,
                          padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                          height: 30.h,
                        ),
                        SizedBox(width: 6.h),
                        CustomButton(
                          text: patientAppointmentHistoryResponseModel.projectName!,
                          onPressed: () {},
                          backgroundColor: AppColors.greyColor,
                          borderColor: AppColors.greyColor,
                          textColor: AppColors.blackColor,
                          fontSize: 10,
                          fontWeight: FontWeight.w500,
                          borderRadius: 8,
                          padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                          height: 30.h,
                        ),
                      ],
                    ),
                    SizedBox(height: 6.h),
                    Row(
                      children: [
                        CustomButton(
                          icon: AppAssets.appointment_calendar_icon,
                          iconColor: AppColors.blackColor,
                          iconSize: 12.h,
                          text: DateUtil.formatDateToDate(DateUtil.convertStringToDate(patientAppointmentHistoryResponseModel.appointmentDate), false),
                          onPressed: () {},
                          backgroundColor: AppColors.greyColor,
                          borderColor: AppColors.greyColor,
                          textColor: AppColors.blackColor,
                          fontSize: 10,
                          fontWeight: FontWeight.w500,
                          borderRadius: 8,
                          padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                          height: 30.h,
                        ),
                        SizedBox(width: 6.h),
                        CustomButton(
                          icon: AppAssets.appointment_time_icon,
                          iconColor: AppColors.blackColor,
                          iconSize: 12.h,
                          text: DateUtil.formatDateToTimeLang(DateUtil.convertStringToDate(patientAppointmentHistoryResponseModel.appointmentDate), false),
                          onPressed: () {},
                          backgroundColor: AppColors.greyColor,
                          borderColor: AppColors.greyColor,
                          textColor: AppColors.blackColor,
                          fontSize: 10,
                          fontWeight: FontWeight.w500,
                          borderRadius: 8,
                          padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                          height: 30.h,
                        ),
                      ],
                    )
                  ],
                ),
              ],
            ),
            SizedBox(height: 16.h),
            getAppointmentActionButtons(
              AppointmentType.isArrived(patientAppointmentHistoryResponseModel),
            ),
          ],
        ),
      ),
    );
  }

  Widget getAppointmentActionButtons(bool isAppointmentArrived) {
    if (isAppointmentArrived) {
      return CustomButton(
        text: LocaleKeys.askDoctor.tr(),
        onPressed: () {},
        backgroundColor: AppColors.secondaryLightRedColor,
        borderColor: AppColors.secondaryLightRedColor,
        textColor: AppColors.primaryRedColor,
        fontSize: 14,
        fontWeight: FontWeight.w500,
        borderRadius: 12,
        padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
        height: 40.h,
        icon: AppAssets.ask_doctor_icon,
        iconColor: AppColors.primaryRedColor,
      );
    } else {
      return Row(
        children: [
          Expanded(
            child: CustomButton(
              text: LocaleKeys.reschedule.tr(),
              onPressed: () {
                onRescheduleTap();
              },
              backgroundColor: AppColors.secondaryLightRedColor,
              borderColor: AppColors.secondaryLightRedColor,
              textColor: AppColors.primaryRedColor,
              fontSize: 14,
              fontWeight: FontWeight.w500,
              borderRadius: 12.h,
              height: 40.h,
              icon: AppAssets.appointment_calendar_icon,
              iconColor: AppColors.primaryRedColor,
              iconSize: 16.h,
            ),
          ),
          SizedBox(width: 16.h),
          Expanded(
            child: CustomButton(
              text: LocaleKeys.cancel.tr(),
              onPressed: () {
                onCancelTap();
              },
              backgroundColor: AppColors.primaryRedColor,
              borderColor: AppColors.primaryRedColor,
              textColor: AppColors.whiteColor,
              fontSize: 14,
              fontWeight: FontWeight.w500,
              borderRadius: 12.h,
              height: 40.h,
              icon: AppAssets.cancel,
              iconColor: AppColors.whiteColor,
              iconSize: 16.h,
            ),
          ),
        ],
      );
    }
  }
}
