import 'package:flutter/material.dart';

class DropdownMenuWidget extends StatelessWidget {
  final Key formKey;
  final String label;
  final TextEditingController controller;
  final String? filterValue;
  final VoidCallback onClear;
  final void Function(String?) onSelected;
  final List<String> entries;

  const DropdownMenuWidget({
    super.key,
    required this.formKey,
    required this.label,
    required this.controller,
    required this.filterValue,
    required this.onClear,
    required this.onSelected,
    required this.entries,
  });

  @override
  Widget build(BuildContext context) {
    return DropdownMenu(
      key: formKey,
      label: Text(label),
      controller: controller,
      initialSelection: filterValue,
      leadingIcon: (filterValue != null)
          ? IconButton(
              onPressed: onClear,
              icon: const Icon(Icons.cancel_outlined),
            )
          : const Icon(
              Icons.cancel_outlined,
              color: Colors.transparent,
            ),
      onSelected: onSelected,
      dropdownMenuEntries:
          entries.map<DropdownMenuEntry<String>>((String entry) {
        return DropdownMenuEntry<String>(
          value: entry,
          label: entry,
        );
      }).toList(),
    );
  }
}
