import { Shield, AlertTriangle, RefreshCw } from 'lucide-react' import { useTranslation } from 'react-i18next' import { useDialogs } from '@/hooks/use-dialog' import { Button } from '@/components/ui/button' import { Card, CardContent, CardHeader } from '@/components/ui/card' import { Skeleton } from '@/components/ui/skeleton' import { StatusBadge } from '@/components/status-badge' import { useTwoFA } from '../hooks' import { TwoFABackupDialog } from './dialogs/two-fa-backup-dialog' import { TwoFADisableDialog } from './dialogs/two-fa-disable-dialog' import { TwoFASetupDialog } from './dialogs/two-fa-setup-dialog' // ============================================================================ // Two-Factor Authentication Card Component // ============================================================================ interface TwoFACardProps { loading: boolean } type DialogKey = 'setup' | 'disable' | 'backup' export function TwoFACard({ loading: pageLoading }: TwoFACardProps) { const { t } = useTranslation() const { status, loading, refetch } = useTwoFA(!pageLoading) const dialogs = useDialogs() if (pageLoading || loading) { return ( ) } return ( <>

{t('Two-Factor Authentication')}

{t('Add an extra layer of security to your account')}

{/* Status Section */}

{t('Two-Step Verification')}

{status.enabled ? ( ) : ( )} {status.locked && ( )}

{status.enabled ? t('Backup codes remaining: {{count}}', { count: status.backup_codes_remaining, }) : t('Add an extra layer of security to your account')}

{!status.enabled && ( )}
{/* Actions Section - Only show when enabled */} {status.enabled && (
)}
{/* Dialogs */} open ? dialogs.open('setup') : dialogs.close('setup') } onSuccess={refetch} /> open ? dialogs.open('disable') : dialogs.close('disable') } onSuccess={refetch} /> open ? dialogs.open('backup') : dialogs.close('backup') } onSuccess={refetch} /> ) }