part of 'field.dart';

class AppPasswordTextFormField extends StatefulWidget {
  const AppPasswordTextFormField({
    super.key,
    this.controller,
    required this.title,
    this.hintText,
    required this.prefixIcon,
    this.validator,
  });

  final TextEditingController? controller;
  final String title;
  final String? hintText;
  final IconData prefixIcon;
  final String? Function(String?)? validator;

  @override
  State<AppPasswordTextFormField> createState() =>
      _AppPasswordTextFormFieldState();
}

class _AppPasswordTextFormFieldState extends State<AppPasswordTextFormField> {
  bool _obscurePassword = true;
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          widget.title,
          style: AppStyle.lg.copyWith(
            fontWeight: FontWeight.w600,
            color: AppColor.textPrimary,
          ),
        ),
        const SpaceHeight(8),
        TextFormField(
          controller: widget.controller,
          keyboardType: TextInputType.emailAddress,
          cursorColor: AppColor.primary,
          obscureText: _obscurePassword,
          style: AppStyle.md.copyWith(color: AppColor.textPrimary),
          decoration: InputDecoration(
            hintText: widget.hintText,
            prefixIcon: LineIcon(
              widget.prefixIcon,
              color: AppColor.textSecondary,
            ),
            suffixIcon: IconButton(
              padding: EdgeInsets.zero,
              icon: Icon(
                _obscurePassword ? LineIcons.eye : LineIcons.eyeSlash,
                color: AppColor.textSecondary,
              ),
              onPressed: () {
                setState(() {
                  _obscurePassword = !_obscurePassword;
                });
              },
            ),
          ),
          validator: widget.validator,
        ),
      ],
    );
  }
}
