import 'package:flutter/material.dart';


class ConfirmPasswordField extends StatelessWidget {
  const ConfirmPasswordField({
    required this.controller,
    required this.fieldWidth,
    required this.isEnabled,
    required this.confirmPasswordLabel,
    required this.newPasswordController,
    required this.missingPasswordError,
    required this.passwordsDoNotMatchError,
    required this.obscureText,
    required this.onToggleVisibility,
  });

  final TextEditingController controller;
  final double fieldWidth;
  final bool isEnabled;
  final String confirmPasswordLabel;
  final TextEditingController newPasswordController;
  final String missingPasswordError;
  final String passwordsDoNotMatchError;
  final bool obscureText;
  final VoidCallback onToggleVisibility;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: fieldWidth,
      child: TextFormField(
        controller: controller,
        obscureText: obscureText,
        enabled: isEnabled,
        autovalidateMode: AutovalidateMode.onUserInteraction,
        decoration: InputDecoration(
          labelText: confirmPasswordLabel,
          border: const OutlineInputBorder(),
          suffixIcon: IconButton(
            onPressed: onToggleVisibility,
            icon: Icon(
              obscureText ? Icons.visibility_off : Icons.visibility,
            ),
          ),
        ),
        validator: (value) {
          if (value == null || value.isEmpty) return missingPasswordError;
          if (value != newPasswordController.text) {
            return passwordsDoNotMatchError;
          }
          return null;
        },
      ),
    );
  }
}
