import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

import 'app-textfield-custom.dart';

class AppTextFieldCustomSearch extends StatelessWidget {
  const AppTextFieldCustomSearch({
    Key? key,
    required this.onChangeFun,
    this.positionedChild,
    this.marginTop,
    this.suffixIcon,
    this.validationError,
    this.inputType,
    this.inputFormatters,
    this.searchController,
    required this.onFieldSubmitted,
    this.hintText,
    this.height,
  });

  final TextEditingController? searchController;

  final Function(String val) onChangeFun;
  final Function onFieldSubmitted;

  final Widget? positionedChild;
  final IconButton? suffixIcon;
  final double? marginTop;
  final String? validationError;
  final String? hintText;

  final TextInputType? inputType;
  final List<TextInputFormatter>? inputFormatters;
  final double? height;

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return Container(
      margin: EdgeInsets.only(left: 16, right: 16, bottom: 16, top: marginTop!),
      child: Stack(
        children: [
          AppTextFieldCustom(
            height: height ?? 0,
            hintText: hintText ?? TranslationBase.of(context).searchPatientName,
            isTextFieldHasSuffix: true,
            isSearchTextField: true,
            inputFormatters: inputFormatters,
            suffixIcon: suffixIcon ??
                IconButton(
                  icon: Icon(
                    Icons.search,
                    color: Colors.black,
                  ),
                  onPressed: () {},
                ),
            controller: searchController,
            onChanged: (val) {
              onChangeFun(val!);
            },
            onFieldSubmitted: () {
              onFieldSubmitted;
            },
            validationError: validationError,
            onClick: () {},
          ),
          if (positionedChild != null) projectViewModel.isArabic ? Positioned(left: 35, top: 5, child: positionedChild!) : Positioned(right: 35, top: 5, child: positionedChild!)
        ],
      ),
    );
  }
}
