import React, { useState } from 'react'; import { TextField, Box, IconButton, Switch, FormGroup, Typography, InputAdornment, } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { TickCircle, Eye, EyeSlash, CloseCircle } from 'iconsax-react'; import { PasswordValidationItem } from './PasswordValidation'; import { Icon } from '@rkheftan/harmony-ui'; interface PasswordSectionProps { showPasswordSection: boolean; setShowPasswordSection: (checked: boolean) => void; password: string; setPassword: (password: string) => void; confirmPassword: string; setConfirmPassword: (confirmPassword: string) => void; matchPassword: boolean; hasNumber: boolean; hasMinLength: boolean; hasUpperAndLower: boolean; hasSpecialChar: boolean; validPassword: boolean; showValidations: boolean; } export function PasswordSection({ showPasswordSection, setShowPasswordSection, password, setPassword, confirmPassword, setConfirmPassword, matchPassword, hasNumber, hasMinLength, hasUpperAndLower, hasSpecialChar, validPassword, showValidations, }: PasswordSectionProps) { const { t } = useTranslation('completionForm'); const [showPasswordText, setShowPasswordText] = useState(false); const [showPasswordRepetitionText, setShowPasswordRepetitionText] = useState(false); const handleTogglePasswordSection = ( e: React.ChangeEvent, ) => { setShowPasswordSection(e.target.checked); }; const handleTogglePasswordEye = () => setShowPasswordText((prev) => !prev); const handleTogglePasswordRepetitionEye = () => setShowPasswordRepetitionText((prev) => !prev); return ( <> {t('completion.determinePassword')} {showPasswordSection && ( setPassword(e.target.value)} variant="outlined" type={showPasswordText ? 'text' : 'password'} sx={{ flex: '1 1 260px', '& .MuiInputBase-input': { pr: 8, // Increased padding to accommodate both icons }, }} InputProps={{ endAdornment: ( {showPasswordText ? ( ) : ( )} {validPassword && ( )} ), }} /> setConfirmPassword(e.target.value)} error={confirmPassword.length > 0 && !matchPassword} helperText={ confirmPassword.length > 0 && !matchPassword ? t('completion.notCompatibility') : ' ' } type={showPasswordRepetitionText ? 'text' : 'password'} sx={{ flex: '1 1 260px', }} InputProps={{ endAdornment: ( {showPasswordRepetitionText ? ( ) : ( )} {confirmPassword.length > 0 && ( )} ), }} /> {password && showValidations && ( )} )} ); }