import '../../../../food_delivery_client.dart';

class AppTextFormField extends StatefulWidget {
  AppTextFormField({
    super.key,
    this.maxLines,
    this.minLines,
    this.textStyle,
    this.onTap,
    this.textAlign,
    this.onChanged,
    this.inputFormatters,
    this.keyBoardType,
    this.fillColor,
    this.hintText,
    this.hintTextStyle,
    this.obscureText = false,
    required this.controller,
    this.prefixIcon,
    this.prefixSvgPath,
    this.focusNode,
    this.borderRadius,
    this.height,
    this.suffixIcon,
    this.validator,
  });

  final int? maxLines;
  final int? minLines;
  final TextStyle? textStyle;
  final VoidCallback? onTap;
  final TextAlign? textAlign;
  final TextEditingController controller;
  final Function(String? value)? onChanged;
  final List<TextInputFormatter>? inputFormatters;
  final TextInputType? keyBoardType;
  final bool obscureText;
  final Color? fillColor;
  final String? hintText;
  final TextStyle? hintTextStyle;
  final Widget? prefixIcon;
  final String? prefixSvgPath;
  final FocusNode? focusNode;
  final BorderRadius? borderRadius;
  final double? height;
  final Widget? suffixIcon;
  FormFieldValidator<String>? validator;

  @override
  State<AppTextFormField> createState() => _AppTextFormFieldState();
}

class _AppTextFormFieldState extends State<AppTextFormField> {
  bool visibility = true;

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      enabled: true,
      //autofocus: true,
      maxLines: widget.maxLines ?? 1,
      minLines: widget.minLines ?? 1,
      onChanged: widget.onChanged,
      focusNode: widget.focusNode,
      inputFormatters: widget.inputFormatters,
      keyboardType: widget.keyBoardType,
      style: widget.textStyle ?? AppTextStyles.size16Regular,
      onTap: widget.onTap,
      textAlign: widget.textAlign ?? TextAlign.start,
      controller: widget.controller,
      validator: widget.validator,
      obscureText: widget.obscureText ? visibility : false,
      obscuringCharacter: "*",
      autovalidateMode: AutovalidateMode.onUserInteraction,
      decoration: InputDecoration(
        enabled: true,
        filled: true,

        fillColor: widget.fillColor ?? AppColors.cEEEEEE,
        hintText: widget.hintText,
        hintStyle:
            widget.hintTextStyle ??
            AppTextStyles.size16Regular.copyWith(color: AppColors.c7F7F7F),
        suffixIcon: widget.obscureText
            ? IconButton(
                onPressed: () {
                  setState(() {
                    visibility = !visibility;
                  });
                },
                icon: Icon(
                  visibility ? Icons.visibility : Icons.visibility_off,
                  color: AppColors.c000000,
                ),
              )
            : widget.suffixIcon,
        prefixIconConstraints: BoxConstraints(minHeight: 24, minWidth: 0),
        prefixIcon: widget.prefixIcon?.paddingOnly(left: 10).paddingAll(3),
        contentPadding: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
        border: OutlineInputBorder(
          borderRadius: widget.borderRadius ?? AppUtils.kBorderRadius40,
          borderSide: BorderSide.none,
        ),
        errorBorder: OutlineInputBorder(
          borderRadius: widget.borderRadius ?? AppUtils.kBorderRadius40,
          borderSide: BorderSide.none,
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: widget.borderRadius ?? AppUtils.kBorderRadius40,
          borderSide: BorderSide.none,
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: widget.borderRadius ?? AppUtils.kBorderRadius40,
          borderSide: BorderSide.none,
        ),
        disabledBorder: OutlineInputBorder(
          borderRadius: widget.borderRadius ?? AppUtils.kBorderRadius40,
          borderSide: BorderSide.none,
        ),
      ),
    );
  }
}
