import 'package:flutter/material.dart';

class CFormTextField extends StatelessWidget {
  const CFormTextField({
    super.key,
    required this.cFocus,
    required TextEditingController cController,
  }) : cTextEditingController = cController;

  final FocusNode cFocus;
  final TextEditingController cTextEditingController;

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      autocorrect: false,
      autofocus: true,
      focusNode: cFocus,
      controller: cTextEditingController,
      keyboardType: TextInputType.emailAddress,
      textInputAction: TextInputAction.done,
      validator: (value) {
        if (value == null || value.isEmpty) {
          return "Need a valied email address";
        }
        return null;
      },
      decoration: InputDecoration(
          //filled: true,
          //fillColor: Theme.of(context).colorScheme.primaryContainer,
          hintText: "Enter email address",
          labelText: "Email",
          labelStyle: TextStyle(
              color: Theme.of(context).colorScheme.onPrimaryContainer,
              fontSize: 16),
          prefixIcon: const Icon(Icons.email_outlined),
          suffixIcon: cTextEditingController.text.isNotEmpty
              ? IconButton(
                  onPressed: () {
                    cTextEditingController.clear();
                  },
                  icon: const Icon(Icons.clear))
              : Container(
                  width: 0,
                ),
          enabledBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(16),
              borderSide: BorderSide(
                  width: 1, color: Theme.of(context).colorScheme.secondary)),
          focusedBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(16),
              borderSide: BorderSide(
                  width: 2, color: Theme.of(context).colorScheme.primary))),
    );
  }
}
