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/widget_extensions.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:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';

class RegionListItem extends StatelessWidget {
  final String title;
  final String hmcCount;
  final String hmgCount;
  final String subTitle;

  const RegionListItem({super.key, required this.title, required this.subTitle, required this.hmcCount, required this.hmgCount});

  @override
  Widget build(BuildContext context) {
    AppState appState = getIt.get<AppState>();
    return Container(
      decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
        color: AppColors.whiteColor,
        borderRadius: 20.h,
        hasShadow: false,
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          header,
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                spacing: 8.h,
                children: [
                  placesCountItem(AppAssets.hmg, hmgCount, " ${LocaleKeys.hospital.tr()}"),
                  placesCountItem(AppAssets.hmc, hmcCount, " ${LocaleKeys.medicalCenters.tr()}"),
                ],
              ),
              Transform.flip(
                flipX: appState.isArabic(),
                child: Utils.buildSvgWithAssets(
                  icon: AppAssets.forward_arrow_icon_small,
                  iconColor: AppColors.blackColor,
                  width: 18,
                  height: 13,
                  fit: BoxFit.contain,
                ),
              ),
            ],
          )
        ],
      ).paddingAll(16.h),
    );
  }

  Widget placesCountItem(String svgPath, String count, String title) {
    return AppCustomChipWidget(
      iconSize: 14.h,
      icon: svgPath,
      iconHasColor: false,
      applyThemeColor: false,
      richText: RichText(
          text: TextSpan(
              text: count,
              style: TextStyle(fontSize: 12.h, fontWeight: FontWeight.w700, color: AppColors.blackColor),
              children: [TextSpan(text: title, style: TextStyle(fontSize: 12.h, fontWeight: FontWeight.w600, color: AppColors.blackColor))])),
    );
  }

  Widget get header => Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Align(
            alignment: AlignmentDirectional.centerStart,
            child: Text(
              title,
              style: TextStyle(
                fontSize: 16.h,
                fontWeight: FontWeight.w600,
                color: AppColors.blackColor,
              ),
            ),
          ),
          Align(
            alignment: Alignment.centerLeft,
            child: Text(
              subTitle,
              style: TextStyle(
                fontSize: 12.h,
                fontWeight: FontWeight.w600,
                color: AppColors.greyTextColor,
              ),
            ),
          ),
        ],
      );
}
