import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/card_with_bg_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/user-guid/CusomRow.dart';
import 'package:flutter/material.dart';
import '../../utils/utils.dart';

class PatientReferralItemWidget extends StatelessWidget {
  final String? referralStatus;
  final int? referralStatusCode;
  final String? patientName;
  final int? patientGender;
  final String? referredDate;
  final String? referredTime;
  final String? patientID;
  final isSameBranch;
  final bool isReferral;
  final bool isReferralClinic;
  final String? referralClinic;
  final String? remark;
  final String? nationality;
  final String? nationalityFlag;
  final String? doctorAvatar;
  final String? referralDoctorName;
  final String? clinicDescription;
  final Widget? infoIcon;

  PatientReferralItemWidget(
      {this.referralStatus,
      this.referralStatusCode,
      this.patientName,
      this.patientGender,
      this.referredDate,
      this.referredTime,
      this.patientID,
      this.isSameBranch,
      this.isReferral = false,
      this.remark,
      this.nationality,
      this.nationalityFlag,
      this.doctorAvatar,
      this.referralDoctorName,
      this.clinicDescription,
       this.infoIcon,
      this.isReferralClinic = false,
      this.referralClinic});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(left: 16.0, right: 16.0, top: 0.0),
      child: Column(
        children: [
          Container(
            child: CardWithBgWidget(
              bgColor: referralStatusCode == 1
                  ? AppGlobal.inProgressColor
                  //Color(0xffc4aa54)
                  : referralStatusCode == 2
                      ? AppGlobal.appGreenColor
                      : referralStatusCode == 46
                          ? AppGlobal.appGreenColor
                          : referralStatusCode == 4
                              ? Colors.red[700]!
                              : Colors.red[900]!,
              hasBorder: false,
              widget: Container(
                  // padding: EdgeInsets.only(left: 20, right: 0, bottom: 0),
                  child: InkWell(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        AppText(
                          referralStatus != null ? referralStatus! : "",
                          fontFamily: 'Poppins',
                          fontSize: 12.0,
                          letterSpacing: -0.48,
                          fontWeight: FontWeight.w600,
                          color: referralStatusCode == 1
                              ? AppGlobal.inProgressColor
                              : referralStatusCode == 2
                                  ? AppGlobal.appGreenColor
                                  : referralStatusCode == 46
                                      ? AppGlobal.appGreenColor
                                      : referralStatusCode == 4
                                          ? Colors.red[700]!
                                          : Colors.red[900]!,
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            AppText(
                              referredDate ?? "",
                              fontFamily: 'Poppins',
                              fontWeight: FontWeight.w600,
                              letterSpacing: -0.48,
                              fontSize: 12.0,
                              color: Color(0XFF28353E),
                            ),
                            AppText(
                              referredTime ?? "",
                              fontFamily: 'Poppins',
                              fontWeight: FontWeight.w600,
                              fontSize: 12.0,
                              color: Color(0XFF575757),
                              letterSpacing: -0.48,
                            ),
                          ],
                        )
                      ],
                    ),
                    SizedBox(
                      height: 7,
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        AppText(
                          Utils.convertToTitleCase(patientName ?? ""),
                          fontSize: 16.0,
                          fontWeight: FontWeight.w600,
                          color: Color(0xff2E303A),
                          fontFamily: 'Poppins',
                          letterSpacing: -0.64,
                        ),
                        SizedBox(
                          width: 0,
                        ),
                        patientGender == 1
                            ? Icon(
                                DoctorApp.male_2,
                                color: Colors.blue,
                              )
                            : Icon(DoctorApp.female_1,
                                color: Color(0xffF0448D)),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Expanded(
                          child: Column(
                            children: [
                              CustomRow(
                                label: TranslationBase.of(context).fileNumber,
                                value: patientID!,
                              ),
                              CustomRow(
                                label: isSameBranch
                                    ? TranslationBase.of(context).referredFrom
                                    : TranslationBase.of(context).refClinic,
                                value: !isReferralClinic
                                    ? isSameBranch
                                        ? TranslationBase.of(context).sameBranch
                                        : TranslationBase.of(context)
                                            .otherBranch
                                    : " " +
                                        Utils.convertToTitleCase(
                                            referralClinic ?? ""),
                              ),
                            ],
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(right: 0.1),
                          child: Row(
                            children: [
                              AppText(
                                nationality != null ? nationality! : "",
                                fontWeight: FontWeight.w600,
                                color: Color(0xFF2E303A),
                                fontSize: 10.0,
                                letterSpacing: -0.4,
                              ),
                              nationalityFlag != null
                                  ? ClipRRect(
                                      borderRadius: BorderRadius.circular(20.0),
                                      child: Image.network(
                                        nationalityFlag!,
                                        height: 25,
                                        width: 30,
                                        errorBuilder: (BuildContext context,
                                            Object exception,
                                            StackTrace? stackTrace) {
                                          return Text('');
                                        },
                                      ))
                                  : SizedBox()
                            ],
                          ),
                        )
                      ],
                    ),
                    CustomRow(
                      label: TranslationBase.of(context).remarks + " : ",
                      value: remark ?? "",
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          margin: EdgeInsets.only(left: 3, right: 0, top: 0.1),
                          child: Image.asset(
                            isReferral
                                ? 'assets/images/patient/ic_ref_arrow_up.png'
                                : 'assets/images/patient/ic_ref_arrow_left.png',
                            height: 50,
                            width: 30,
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(
                              left: 0, top: 18, right: 0, bottom: 0),
                          padding: EdgeInsets.only(left: 4.0, right: 1.0),
                          child: Container(
                            width: 40,
                            height: 40,
                            child: doctorAvatar != null
                                ? ClipRRect(
                                    borderRadius: BorderRadius.circular(20.0),
                                    child: Image.network(
                                      doctorAvatar!,
                                      height: 28,
                                      width: 28,
                                      errorBuilder: (BuildContext context,
                                          Object exception,
                                          StackTrace? stackTrace) {
                                        return Text('No Image');
                                      },
                                    ))
                                : Container(
                                    child: Image.asset(
                                      patientGender == 1
                                          ? 'assets/images/male_avatar.png'
                                          : 'assets/images/female_avatar.png',
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                          ),
                        ),
                        Expanded(
                          flex: 4,
                          child: Container(
                            margin:
                                EdgeInsets.only(left: 10, top: 17, bottom: 0),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                AppText(
                                  Utils.convertToTitleCase(
                                      referralDoctorName ?? ""),
                                  fontFamily: 'Poppins',
                                  fontWeight: FontWeight.w600,
                                  fontSize: 14.0,
                                  color: Color(0xff2E303A),
                                  letterSpacing: -0.56,
                                ),
                                if (clinicDescription != null)
                                  AppText(
                                    Utils.convertToTitleCase(
                                        clinicDescription ?? ""),
                                    fontFamily: 'Poppins',
                                    fontWeight: FontWeight.w600,
                                    fontSize: 10.0,
                                    color: Color(0xff575757),
                                    letterSpacing: -0.4,
                                  ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                    Container(
                        width: double.infinity,
                        alignment: Alignment.centerRight,
                        child: infoIcon ?? Container())
                  ],
                ),
                // onTap: onTap,
              )),
            ),
          ),
        ],
      ),
    );
  }
}
