import 'package:flutter/material.dart';

import 'package:pshared/widgets/password/confirm_field.dart';
import 'package:pshared/widgets/password/field.dart';


class PasswordFields extends StatelessWidget {
  const PasswordFields({
    super.key,
    required this.oldPasswordController,
    required this.newPasswordController,
    required this.confirmPasswordController,
    required this.oldPasswordLabel,
    required this.newPasswordLabel,
    required this.confirmPasswordLabel,
    required this.missingPasswordError,
    required this.passwordsDoNotMatchError,
    required this.fieldWidth,
    required this.gapSmall,
    required this.isEnabled,
    required this.showOldPassword,
    required this.showNewPassword,
    required this.showConfirmPassword,
    required this.onToggleOldPassword,
    required this.onToggleNewPassword,
    required this.onToggleConfirmPassword,
  });

  final TextEditingController oldPasswordController;
  final TextEditingController newPasswordController;
  final TextEditingController confirmPasswordController;
  final String oldPasswordLabel;
  final String newPasswordLabel;
  final String confirmPasswordLabel;
  final String missingPasswordError;
  final String passwordsDoNotMatchError;
  final double fieldWidth;
  final double gapSmall;
  final bool isEnabled;
  final bool showOldPassword;
  final bool showNewPassword;
  final bool showConfirmPassword;
  final VoidCallback onToggleOldPassword;
  final VoidCallback onToggleNewPassword;
  final VoidCallback onToggleConfirmPassword;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        PasswordField(
          controller: oldPasswordController,
          labelText: oldPasswordLabel,
          fieldWidth: fieldWidth,
          isEnabled: isEnabled,
          obscureText: !showOldPassword,
          onToggleVisibility: onToggleOldPassword,
          validator: (value) =>
              (value == null || value.isEmpty) ? missingPasswordError : null,
        ),
        SizedBox(height: gapSmall),
        PasswordField(
          controller: newPasswordController,
          labelText: newPasswordLabel,
          fieldWidth: fieldWidth,
          isEnabled: isEnabled,
          obscureText: !showNewPassword,
          onToggleVisibility: onToggleNewPassword,
          validator: (value) =>
              (value == null || value.isEmpty) ? missingPasswordError : null,
        ),
        SizedBox(height: gapSmall),
        ConfirmPasswordField(
          controller: confirmPasswordController,
          fieldWidth: fieldWidth,
          isEnabled: isEnabled,
          confirmPasswordLabel: confirmPasswordLabel,
          newPasswordController: newPasswordController,
          missingPasswordError: missingPasswordError,
          passwordsDoNotMatchError: passwordsDoNotMatchError,
          obscureText: !showConfirmPassword,
          onToggleVisibility: onToggleConfirmPassword,
        ),
      ],
    );
  }
}
