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/date_util.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/ask_doctor/models/doctor_response_model.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';

class DoctorResponseTransactions extends StatelessWidget {
  const DoctorResponseTransactions({super.key, required this.doctorResponseModel});

  final DoctorResponseModel doctorResponseModel;

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Utils.buildImgWithNetwork(
                  url: "https://hmgwebservices.com/Images/MobileImages/DUBAI/unkown.png",
                  iconColor: AppColors.blackBgColor,
                  width: 50.w,
                  height: 50.h,
                  fit: BoxFit.cover,
                ).circle(100.r),
              ],
            ),
            SizedBox(width: 16.h),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  doctorResponseModel.doctorName!.toText16(isBold: true, maxlines: 1),
                  SizedBox(height: 8.h),
                  Wrap(
                    direction: Axis.horizontal,
                    spacing: 3.h,
                    runSpacing: 4.h,
                    children: [
                      AppCustomChipWidget(
                        labelText: (doctorResponseModel.clinicName ?? "").length > 15 ? '${doctorResponseModel.clinicName!.substring(0, 12)}...' : doctorResponseModel.clinicName ?? "",
                      ),
                      AppCustomChipWidget(
                          labelText: (doctorResponseModel.projectName ?? "").length > 15 ? '${doctorResponseModel.projectName!.substring(0, 12)}...' : doctorResponseModel.projectName ?? ""),
                      AppCustomChipWidget(
                        labelPadding: EdgeInsetsDirectional.only(start: -4.w, end: 6.w),
                        icon: AppAssets.appointment_calendar_icon,
                        labelText: DateUtil.formatDateToDate(DateUtil.convertStringToDate(doctorResponseModel.createdOn), false),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
        SizedBox(height: 16.h),
        Divider(color: AppColors.dividerColor, height: 1.h),
        SizedBox(height: 16.h),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 72.w),
          child: CustomButton(
            text: DateUtil.formatDateToDate(DateUtil.convertStringToDate(doctorResponseModel.createdOn), false),
            onPressed: () {},
            backgroundColor: AppColors.greyColor,
            borderColor: AppColors.greyColor,
            textColor: AppColors.textColor,
            fontSize: 14.f,
            fontWeight: FontWeight.w600,
            borderRadius: 10.r,
            height: 40.h,
          ).paddingSymmetrical(16.w, 0.h),
        ),
        SizedBox(height: 16.h),
        Row(
          children: [
            Utils.buildImgWithAssets(
              icon: getIt.get<AppState>().getAuthenticatedUser()?.gender == 1 ? AppAssets.maleImg : AppAssets.femaleImg,
              width: 42.w,
              height: 42.h,
            ),
            SizedBox(width: 8.w),
            Container(
              padding: EdgeInsets.all(8.w),
              decoration: BoxDecoration(
                color: AppColors.infoColor.withAlpha(20),
                borderRadius: BorderRadius.circular(8.r),
              ),
              child: (doctorResponseModel.requestTypeDescription ?? "").toText12(color: AppColors.infoColor, isBold: true),
            ),
          ],
        ),
        SizedBox(height: 24.h),
        ListView.builder(
          padding: EdgeInsets.zero,
          itemCount: doctorResponseModel.transactions!.length,
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          itemBuilder: (context, index) {
            return Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Container(
                      padding: EdgeInsets.all(8.w),
                      decoration: BoxDecoration(
                        color: AppColors.infoColor.withAlpha(20),
                        borderRadius: BorderRadius.circular(8.r),
                      ),
                      child: doctorResponseModel.transactions![index].doctorResponse!.toText12(color: AppColors.textColor, isBold: true),
                  ),
                  SizedBox(width: 8.w),
                  Utils.buildImgWithNetwork(
                    url: "https://hmgwebservices.com/Images/MobileImages/DUBAI/unkown.png",
                    iconColor: AppColors.blackBgColor,
                    fit: BoxFit.cover,
                    width: 42.w,
                    height: 42.h,
                  ).circle(100.r),
                ],
                ),
              ],
            );
          },
        ),
      ],
    );
  }
}
