import 'package:flutter/material.dart';


class PasswordField extends StatelessWidget {
  const PasswordField({
    required this.controller,
    required this.labelText,
    required this.fieldWidth,
    required this.isEnabled,
    required this.obscureText,
    required this.onToggleVisibility,
    required this.validator,
  });

  final TextEditingController controller;
  final String labelText;
  final double fieldWidth;
  final bool isEnabled;
  final bool obscureText;
  final VoidCallback onToggleVisibility;
  final String? Function(String?) validator;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: fieldWidth,
      child: TextFormField(
        controller: controller,
        obscureText: obscureText,
        enabled: isEnabled,
        autovalidateMode: AutovalidateMode.onUserInteraction,
        decoration: InputDecoration(
          labelText: labelText,
          border: const OutlineInputBorder(),
          suffixIcon: IconButton(
            onPressed: onToggleVisibility,
            icon: Icon(
              obscureText ? Icons.visibility_off : Icons.visibility,
            ),
          ),
        ),
        validator: validator,
      ),
    );
  }
}
