'use client' import type * as React from 'react' import { cn } from '../../../utils/cn' import { useDeferredError } from '../../../hooks/ui/use-deferred-error' import { Button } from '../../ui/button' import { Input } from '../../ui/input' import { BackToLoginLink } from './back-to-login-link' export interface PasswordResetFormProps { /** Controlled field values */ password: string confirmPassword: string onPasswordChange: (value: string) => void onConfirmPasswordChange: (value: string) => void /** Primary submit ("Reset Password") */ onSubmit: () => void /** Secondary action ("Cancel") */ onCancel: () => void /** In-card "Back to Login" shown on tablet/mobile; desktop uses the shell footer. */ onBackToLogin?: () => void /** Disables just the primary submit (fields stay editable). */ submitDisabled?: boolean loading?: boolean disabled?: boolean errors?: { password?: string confirmPassword?: string } title?: string subtitle?: string newPasswordLabel?: string confirmPasswordLabel?: string newPasswordPlaceholder?: string confirmPasswordPlaceholder?: string submitLabel?: string cancelLabel?: string className?: string } /** * Password Reset form. Presentational + controlled — the consumer owns state, * validation and submission. Covers the empty and filled states from the auth * redesign. "Back to Login" is provided by the AuthShell footer (desktop). */ export function PasswordResetForm({ password, confirmPassword, onPasswordChange, onConfirmPasswordChange, onSubmit, onCancel, onBackToLogin, submitDisabled = false, loading = false, disabled = false, errors, title = 'Reset your Password', subtitle = 'Enter your new password below', newPasswordLabel = 'New Password', confirmPasswordLabel = 'Confirm Password', newPasswordPlaceholder = 'Enter your Password', confirmPasswordPlaceholder = 'Enter your Password', submitLabel = 'Reset Password', cancelLabel = 'Cancel', className, }: PasswordResetFormProps) { const fieldsDisabled = disabled || loading // Validation messages are deferred while the user is typing (shown on blur or after a pause). const passwordErr = useDeferredError(errors?.password, password) const confirmErr = useDeferredError(errors?.confirmPassword, confirmPassword) const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter' && !fieldsDisabled && !submitDisabled) { onSubmit() } } return (
{/* Header */}

{title}

{subtitle}

{/* New password */} onPasswordChange(event.target.value)} onKeyDown={handleKeyDown} /> {/* Confirm password */} onConfirmPasswordChange(event.target.value)} onKeyDown={handleKeyDown} /> {/* Actions — Cancel + Reset, side by side on every breakpoint */}
{/* Back to Login — in-card on tablet/mobile; desktop shows it in the shell footer */} {onBackToLogin && }
) }