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/blood_donation/blood_donation_view_model.dart';
import 'package:hmg_patient_app_new/features/blood_donation/models/blood_group_hospitals_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/theme/colors.dart' show AppColors;
import 'package:provider/provider.dart';

class HospitalBottomSheetBodySelection extends StatelessWidget {
  final Function(BdGetProjectsHaveBdClinic userSelection) onUserHospitalSelection;
  final bool isHideTitle;

  const HospitalBottomSheetBodySelection({super.key, required this.onUserHospitalSelection(BdGetProjectsHaveBdClinic userSelection), this.isHideTitle = false});

  @override
  Widget build(BuildContext context) {
    final bloodDonationVm = Provider.of<BloodDonationViewModel>(context, listen: false);
    AppState appState = getIt.get<AppState>();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
       if(!isHideTitle) LocaleKeys.selectHospital.tr(context: context).toText16(isBold: true, color: AppColors.greyTextColor),
        SizedBox(height: 16.h),
        SizedBox(
          height: MediaQuery.sizeOf(context).height * .4,
          child: ListView.separated(
              itemBuilder: (_, index) {
                return DecoratedBox(
                  decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
                    color: AppColors.whiteColor,
                    borderRadius: 20.h,
                    hasShadow: false,
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          spacing: 8.h,
                          children: [
                            hospitalName(bloodDonationVm.hospitalList[index]).onPress(() {
                              onUserHospitalSelection(bloodDonationVm.hospitalList[index]);
                              Navigator.of(context).pop();
                            })
                          ],
                        ),
                      ),
                      Transform.flip(
                        flipX: appState.isArabic(),
                        child: Utils.buildSvgWithAssets(icon: AppAssets.forward_arrow_icon, iconColor: AppColors.blackColor, width: 40.h, height: 40.h, fit: BoxFit.contain),
                      ),
                    ],
                  ).paddingSymmetrical(16.h, 16.h),
                ).onPress(() {
                  bloodDonationVm.setSelectedHospital(bloodDonationVm.hospitalList[index]);
                  Navigator.of(context).pop();
                });
              },
              separatorBuilder: (_, __) => SizedBox(height: 16.h),
              itemCount: bloodDonationVm.hospitalList.length),
        )
      ],
    );
  }

  Widget hospitalName(dynamic hospital) => Row(
        children: [
          Utils.buildSvgWithAssets(icon: AppAssets.hmg).paddingOnly(right: 10),
          Expanded(
            child: (hospital.projectName ?? "").toString().toText16(isBold: true, color: AppColors.blackColor),
            // Text(hospital.projectName ?? "", style: TextStyle(isBold: true, fontSize: 16.f, color: AppColors.blackColor)),
          )
        ],
      );
}
