import 'package:flutter/material.dart';
import 'package:mc_common_app/extensions/int_extensions.dart';
import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/widgets/common_widgets/custom_rectangle_chip.dart';
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';

class SearchEntityWidget extends StatelessWidget {
  final String title;
  final Widget actionWidget;
  final List<DropValue> historyContent;
  final Function(int) onHistoryItemDeleted;
  final Function(DropValue) onHistoryItemTapped;

  const SearchEntityWidget({
    super.key,
    required this.title,
    required this.actionWidget,
    required this.historyContent,
    required this.onHistoryItemDeleted,
    required this.onHistoryItemTapped,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        title.toText(fontSize: 16, isBold: true),
        8.height,
        actionWidget,
        10.height,
        historyContent.isNotEmpty
            ? SizedBox(
                height: 33,
                child: ListView.builder(
                    shrinkWrap: true,
                    scrollDirection: Axis.horizontal,
                    itemCount: historyContent.length,
                    itemBuilder: (BuildContext context, int index) {
                      return CustomRectangleChip(
                        text: historyContent[index].value,
                        onHistoryItemDeleted: () {
                          onHistoryItemDeleted(index);
                        },
                        onHistoryItemTapped: () {
                          onHistoryItemTapped(historyContent[index]);
                        },
                      ).paddingOnly(right: 10);
                    }),
              )
            : const SizedBox.shrink(),
      ],
    );
  }
}
