import 'package:baseproject/core/components/index.dart';
import 'package:baseproject/core/theme/form_theme.dart';
import 'package:flutter/material.dart';

class TextFieldPassword extends StatefulWidget {
  const TextFieldPassword({
    Key? key,
    this.labelText = "",
    this.name = "TextFieldPassword",
    this.validator,
    this.onChanged,
  }) : super(key: key);
  final String labelText;
  final String name;
  final FormFieldValidator<String?>? validator;
  final ValueChanged<String?>? onChanged;

  @override
  State<TextFieldPassword> createState() => _TextFieldPasswordState();
}

class _TextFieldPasswordState extends State<TextFieldPassword> {
  late bool _passwordVisible;
  @override
  void initState() {
    super.initState();
    _passwordVisible = false;
  }

  @override
  Widget build(BuildContext context) {
    return CustomTextField(
      textCapitalization: TextCapitalization.none,
      isShowTextRequire: true,
      isLabelTop: true,
      name: widget.name,
      validator: widget.validator,
      labelText: widget.labelText,
      obscureText: !_passwordVisible,
      maxLines: 1,
      onChanged: widget.onChanged,
      decoration: FormTheme.getInputDecoration().copyWith(
        suffixIcon: IconButton(
          icon: Icon(
            _passwordVisible ? Icons.visibility : Icons.visibility_off,
          ),
          onPressed: () {
            setState(() {
              _passwordVisible = !_passwordVisible;
            });
          },
        ),
      ),
    );
  }
}
