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_export.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/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/doctor_list_api_response.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/chip/app_custom_chip_widget.dart';

import 'dart:ui' as ui;

class HospitalListItem extends StatelessWidget {
  final PatientDoctorAppointmentList? hospitalData;
  final bool isLocationEnabled;

  late AppState appState;

  HospitalListItem({super.key, required this.hospitalData, required this.isLocationEnabled});

  @override
  Widget build(BuildContext context) {
    appState = getIt.get<AppState>();
    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, distanceInfo],
            ),
          ),
          Transform.flip(
            flipX: appState.isArabic(),
            child: Utils.buildSvgWithAssets(
              icon: AppAssets.forward_arrow_icon_small,
              iconColor: AppColors.blackColor,
              width: 18.h,
              height: 13.h,
              fit: BoxFit.contain,
            ),
          ),
        ],
      ).paddingSymmetrical(16.h, 16.h),
    );
  }

  Widget get hospitalName => Row(
        children: [
          Utils.buildSvgWithAssets(
            icon: (hospitalData?.isHMC == true) ? AppAssets.hmc : AppAssets.hmg,
            applyThemeColor: false,
          ).paddingOnly(right: 10),
          Expanded(
            child: Text(
              hospitalData?.filterName ?? "",
              style: TextStyle(
                fontWeight: FontWeight.w600,
                fontSize: 16,
                color: AppColors.blackColor,
              ),
            ),
          )
        ],
      );

  Widget get distanceInfo => Row(
    spacing: 4.w,
        children: [
          Visibility(
            visible: (hospitalData?.distanceInKMs != "0"),
            child: Directionality(
              textDirection: ui.TextDirection.ltr,
              child: AppCustomChipWidget(
                labelText: "${hospitalData?.distanceInKMs ?? ""} km",
                deleteIcon: AppAssets.location_red,
                deleteIconSize: Size(9, 12),
                backgroundColor: AppColors.secondaryLightRedColor,
                textColor: AppColors.errorColor,
                isEnglishOnly: true,
              ),
            ),
          ),
          Visibility(
              visible: (hospitalData?.distanceInKMs == "0"),
              child: Row(
                children: [
                  AppCustomChipWidget(
                    labelText: LocaleKeys.noDistance.tr(),
                    textColor: AppColors.blackColor,
                  ),
                  // SizedBox(
                  //   width: 8.h,
                  // )
                ],
              )),
          // Visibility(
          //     visible: !isLocationEnabled,
          //     child: AppCustomChipWidget(
          //       labelText: "Location turned off",
          //       deleteIcon: AppAssets.location_unavailable,
          //       deleteIconSize: Size(9.w, 12.h),
          //       textColor: AppColors.blackColor,
          //     )),
        ],
      );
}
