'use client'; import {useState} from 'react'; import {useTranslations} from '@/lib/i18n'; import {Lock, Wifi, Eye, EyeOff, LogOut} from 'lucide-react'; import {removeCookie} from '@/lib/utils/cookies'; import * as tauri from '@/lib/tauri'; import Button from '@/components/ui/Button'; 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 { const result = await tauri.offlinePinVerify(pin); if (result.success && result.userId) { 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) { setError(t('offline.pin.verify.error')); } finally { setIsLoading(false); } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleVerifyPin(); } }; const handleLogout = async () => { removeCookie("token"); await tauri.removeToken(); tauri.logout(); }; return (
{t('offline.pin.verify.subtitle')}
{error}
{t('offline.pin.verify.attemptsRemaining', {count: 3 - attempts})}
)}