import 'package:flutter/material.dart';
import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/models/general_models/widgets_models.dart';
import 'package:mc_common_app/theme/colors.dart';

class FiltersList extends StatelessWidget {
  final List<FilterListModel> filterList;
  final Function(int, int) onFilterTapped;
  final bool needLeftPadding;
  EdgeInsets? padding;

  FiltersList({
    Key? key,
    this.padding,
    required this.filterList,
    this.needLeftPadding = true,
    required this.onFilterTapped,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 37,
      width: double.infinity,
      child: ListView.builder(
          padding: padding ?? EdgeInsets.only(left: needLeftPadding ? 12 : 0),
          itemCount: filterList.length,
          scrollDirection: Axis.horizontal,
          itemBuilder: (BuildContext context, int index) {
            return InkWell(
              onTap: () {
                onFilterTapped(index, filterList[index].id);
              },
              child: Container(
                alignment: Alignment.center,
                padding: const EdgeInsets.symmetric(horizontal: 8),
                margin: const EdgeInsets.symmetric(horizontal: 4),
                decoration: BoxDecoration(
                  color: filterList[index].isSelected
                      ? MyColors.darkIconColor
                      : null,
                  border: Border.all(
                    color: filterList[index].isSelected
                        ? MyColors.darkIconColor
                        : MyColors.primaryColor,
                    width: 2,
                  ),
                ),
                child: filterList[index].title.toText(
                      fontSize: 12,
                      letterSpacing: -0.14,
                      color:
                          filterList[index].isSelected ? MyColors.white : null,
                    ),
              ),
            );
          }),
    );
  }
}
