'use client'; import { useState } from 'react'; import { useTranslations } from 'next-intl'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faLock, faWifi, faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons'; interface OfflinePinVerifyProps { onSuccess: (userId: string) => void; onCancel?: () => void; } export default function OfflinePinVerify({ onSuccess, onCancel }: OfflinePinVerifyProps) { const t = useTranslations(); const [pin, setPin] = useState(''); const [showPin, setShowPin] = useState(false); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const [attempts, setAttempts] = useState(0); const handleVerifyPin = async () => { if (!pin || pin.length < 4) { setError(t('offline.pin.verify.enterPin')); return; } setIsLoading(true); setError(''); try { if (window.electron) { const result = await window.electron.offlinePinVerify(pin); if (result.success && result.userId) { console.log('[OfflinePin] PIN verified, accessing offline mode'); onSuccess(result.userId); } else { setAttempts(prev => prev + 1); setPin(''); if (attempts >= 2) { setError(t('offline.pin.verify.tooManyAttempts')); } else { setError(result.error || t('offline.pin.verify.incorrect')); } } } } catch (error) { console.error('[OfflinePin] Error verifying PIN:', error); setError(t('offline.pin.verify.error')); } finally { setIsLoading(false); } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleVerifyPin(); } }; return (
{t('offline.pin.verify.subtitle')}
{error}
{t('offline.pin.verify.attemptsRemaining', { count: 3 - attempts })}
)}