import 'package:flutter/material.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


class RecipientSearchField extends StatelessWidget {
  final TextEditingController controller;
  final ValueChanged<String> onChanged;
  final FocusNode? focusNode;

  const RecipientSearchField({
    super.key,
    required this.controller,
    required this.onChanged,
    this.focusNode,
  });

  @override
  Widget build(BuildContext context) {
    final l10n = AppLocalizations.of(context)!;

    return TextField(
      controller: controller,
      focusNode: focusNode,
      decoration: InputDecoration(
        prefixIcon: const Icon(Icons.search), 
        hintText: l10n.searchHint,
        border: const OutlineInputBorder(),
        fillColor: Theme.of(context).colorScheme.onSecondary,
        filled: true,
        suffixIcon: IconButton(
          icon: const Icon(Icons.clear),
          onPressed: () {
            controller.clear();
            onChanged('');
            focusNode?.unfocus();
          },
        ),
      ),
      onChanged: onChanged,
    );

  }
}
