import 'package:flutter/cupertino.dart';

import '../../core/i18n/translations.g.dart';
import '../../core/styles/my_dimensions.dart';
import 'ipm_textfield.dart';

class IPMSearchField extends StatelessWidget {
  final TextEditingController? controller;
  final String hintText;
  final String checkHome;
  final List<Widget>? actions;
  final Function(String)? onFieldSubmitted;

  const IPMSearchField({
    Key? key,
    this.controller,
    required this.hintText,
    required this.checkHome,
    this.actions,
    this.onFieldSubmitted,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(children: [
      Expanded(
        child: IPMTextField(
          controller: controller,
          hintText: this.hintText,
          onChanged: (v) {
            if (this.checkHome == "YESY") {
              if (onFieldSubmitted != null && controller != null) {
                // FocusScope.of(context).requestFocus(FocusNode());
                onFieldSubmitted!(controller!.text);
              }
            } else {}
          },
          suffixIcon: GestureDetector(
            onTap: () {
              if (onFieldSubmitted != null && controller != null) {
                FocusScope.of(context).requestFocus(FocusNode());
                onFieldSubmitted!(controller!.text);
              }
            },
            child: Icon(
              CupertinoIcons.search,
              size: MyDimens.dimen26,
            ),
          ),
          maxLines: 1,
          onFieldSubmitted: onFieldSubmitted,
        ),
      ),
      if (this.actions != null)
        Row(
          children: this.actions!,
        )
    ]);
  }
}
