
import 'package:easy_localization/easy_localization.dart' show tr, StringTranslateExtension;
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/doctor_filter/doctor_filter_view_model.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';
import 'package:provider/provider.dart';

class FacilityChip extends StatelessWidget {
  const FacilityChip({super.key});

  @override
  Widget build(BuildContext context) {
    return Selector<DoctorFilterViewModel, List<String>>(
        selector: (_, model) => model.facilityList,
        builder: (__, data, ___) =>
            Selector<DoctorFilterViewModel, List<String>?>(
              selector: (_, model) => model.selectedFacilityForFilters,
              builder: (context, selectRegion, ___) => Row(
                children: [
                  Expanded(
                      child: ListView.separated(
                          scrollDirection: Axis.horizontal,

                          itemCount: data.length,
                          separatorBuilder: (_, __)=>SizedBox(width: 8.h,),
                          itemBuilder: (_, index) => AppCustomChipWidget(
                            icon: data[index].contains("hmg")?AppAssets.hmg: AppAssets.hmc,
                              iconHasColor: false,
                              iconSize: 18,
                              labelText: data[index].tr(),
                              textColor: selectRegion?.any((selectedRegion)=>data[index] == selectedRegion) == true
                                  ? AppColors.primaryRedColor
                                  : AppColors.textColor,
                              backgroundColor:
                              data[index] == selectRegion
                                  ? AppColors.primaryRedColor
                                  .withOpacity(0.1)
                                  : AppColors.whiteColor,
                              shape: RoundedRectangleBorder(
                                  side: BorderSide(
                                    color: selectRegion?.any((selectedRegion)=>data[index] == selectedRegion) == true
                                        ? AppColors
                                        .primaryRedBorderColor
                                        : AppColors
                                        .chipBorderColorOpacity20,
                                    width: 1,
                                  ),
                                  borderRadius:
                                  BorderRadius.circular(10)))
                              .onPress(() {
                            context
                                .read<DoctorFilterViewModel>()
                                .setSelectedFacilityForFilter(data[index]);
                          })))
                ],
              ),
            ));
  }
}
