/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import { useMemo } from 'react'
import { ShieldCheck, KeyRound, Loader2 } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import { Dialog } from '@/components/dialog'
import type {
SecureVerificationState,
VerificationMethod,
VerificationMethods,
} from '../types'
interface SecureVerificationDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
methods: VerificationMethods
state: SecureVerificationState
onVerify: (method: VerificationMethod, code?: string) => void | Promise
onCancel: () => void
onCodeChange: (code: string) => void
onMethodChange: (method: VerificationMethod) => void
}
export function SecureVerificationDialog({
open,
onOpenChange,
methods,
state,
onVerify,
onCancel,
onCodeChange,
onMethodChange,
}: SecureVerificationDialogProps) {
const { t } = useTranslation()
const availableTabs: VerificationMethod[] = useMemo(() => {
const tabs: VerificationMethod[] = []
if (methods.has2FA) tabs.push('2fa')
if (methods.hasPasskey && methods.passkeySupported) tabs.push('passkey')
return tabs
}, [methods])
const activeMethod =
state.method ?? (availableTabs.length > 0 ? availableTabs[0] : null)
const title =
state.title ??
(availableTabs.length
? 'Additional verification required'
: 'Verification unavailable')
const description =
state.description ??
(availableTabs.length
? 'Confirm your identity before accessing this sensitive action.'
: 'Enable Two-factor Authentication or Passkey in your profile settings to continue.')
const handleVerify = () => {
if (!activeMethod) return
const payload = activeMethod === '2fa' ? state.code : undefined
onVerify(activeMethod, payload)
}
const verifyDisabled =
state.loading ||
(activeMethod === '2fa' && (!state.code.trim() || state.code.length < 6))
return (
)
}