// lib/views/widgets/password_text_field_widget.dart
import 'package:em2rp/utils/colors.dart';
import 'package:flutter/material.dart';

class PasswordTextFieldWidget extends StatelessWidget {
  final TextEditingController passwordController;
  final bool obscurePassword;
  final bool highlightPasswordField;
  final VoidCallback onTogglePasswordVisibility;
  final VoidCallback? onSubmitted;

  const PasswordTextFieldWidget({
    super.key,
    required this.passwordController,
    required this.obscurePassword,
    required this.highlightPasswordField,
    required this.onTogglePasswordVisibility,
    this.onSubmitted,
  });

  @override
  Widget build(BuildContext context) {
    return TextField(
      controller: passwordController,
      obscureText: obscurePassword,
      autofillHints: const [AutofillHints.password],
      textInputAction: TextInputAction.done,
      onSubmitted: (_) => onSubmitted?.call(),
      decoration: InputDecoration(
        labelText: 'Mot de passe',
        border: OutlineInputBorder(
          borderSide: highlightPasswordField
              ? const BorderSide(color: Colors.red)
              : const BorderSide(),
        ),
        filled: true,
        fillColor: AppColors.blanc,
        suffixIcon: IconButton(
          icon: Icon(
            obscurePassword ? Icons.visibility_off : Icons.visibility,
            color: AppColors.gris,
          ),
          onPressed: onTogglePasswordVisibility,
        ),
      ),
    );
  }
}
