import 'package:flutter/material.dart';

class CPasswordTextField extends StatefulWidget {
  const CPasswordTextField(
      {super.key, required this.cFocusNode, required this.cController});

  final FocusNode cFocusNode;
  final TextEditingController cController;

  @override
  State<CPasswordTextField> createState() => _CPasswordTextFieldState();
}

class _CPasswordTextFieldState extends State<CPasswordTextField> {
  var _isVisible = false;

  @override
  Widget build(BuildContext context) {
    return TextFormField(
        controller: widget.cController,
        textInputAction: TextInputAction.go,
        obscureText: !_isVisible,
        validator: (value) {
          if (value == null || value.isEmpty || value.length < 5) {
            return "Need a valied password with more than 4 charectors";
          }
          return null;
        },
        decoration: InputDecoration(
            //filled: true,
            //fillColor: Theme.of(context).colorScheme.tertiaryContainer,
            hintText: "Enter password",
            labelText: "Password",
            labelStyle: TextStyle(
                color: Theme.of(context).colorScheme.primary, fontSize: 16),
            suffixIcon: IconButton(
                onPressed: () {
                  setState(() {
                    _isVisible = !_isVisible;
                  });
                },
                icon: _isVisible
                    ? const Icon(Icons.visibility)
                    : const Icon(Icons.visibility_off)),
            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))));
  }
}
