'use client'; import { useState, useRef, useEffect } from 'react'; interface PasswordVerificationModalProps { onVerify: (password: string) => Promise; onCancel: () => void; isOpen: boolean; } // TODO: make the modal below use the reusable Modal component export default function PasswordVerificationModal({ onVerify, onCancel, isOpen }: PasswordVerificationModalProps) { const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isVerifying, setIsVerifying] = useState(false); const modalRef = useRef(null); const inputRef = useRef(null); // Focus input when modal opens useEffect(() => { if (isOpen && inputRef.current) { setTimeout(() => { inputRef.current?.focus(); }, 100); } }, [isOpen]); // Handle click outside modal useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (modalRef.current && !modalRef.current.contains(event.target as Node)) { onCancel(); } }; if (isOpen) { document.addEventListener('mousedown', handleClickOutside); } return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [isOpen, onCancel]); // Handle ESC key to close modal useEffect(() => { const handleEscKey = (event: KeyboardEvent) => { if (event.key === 'Escape') { onCancel(); } }; if (isOpen) { window.addEventListener('keydown', handleEscKey); } return () => { window.removeEventListener('keydown', handleEscKey); }; }, [isOpen, onCancel]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); if (!password.trim()) { setError('Please enter a password'); return; } setIsVerifying(true); try { const success = await onVerify(password); if (!success) { setError('Incorrect password. Please try again.'); setPassword(''); inputRef.current?.focus(); } } catch (err) { setError('An error occurred while verifying the password. Please try again.'); } finally { setIsVerifying(false); } }; if (!isOpen) return null; return (
{/* Background elements */}

Password Protected

This clipboard is password protected. Please enter the password to access it.

{ setPassword(e.target.value); if (error) setError(''); }} placeholder="Enter password" className="w-full pl-10 pr-4 py-3 rounded-lg bg-surface/80 border-2 border-surface-hover focus:border-emerald-500 focus:outline-none focus:ring-0 transition-colors duration-300 ease-in-out text-text-primary placeholder-text-secondary/50 font-mono" autoComplete="off" />
{error && (
{error}
)}
); }