/*
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 { useState } from 'react'
import { AlertTriangle } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Dialog } from '@/components/dialog'
interface StatusCodeRiskDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
detailItems: string[]
onConfirm: () => void
}
const CHECKLIST_KEYS = [
'High-risk status code retry risk check 1',
'High-risk status code retry risk check 2',
'High-risk status code retry risk check 3',
'High-risk status code retry risk check 4',
] as const
export function StatusCodeRiskDialog({
open,
onOpenChange,
detailItems,
onConfirm,
}: StatusCodeRiskDialogProps) {
const { t } = useTranslation()
const [checkedItems, setCheckedItems] = useState>(new Set())
const [confirmText, setConfirmText] = useState('')
const requiredText = t('High-risk status code retry confirmation text')
const allChecked = checkedItems.size === CHECKLIST_KEYS.length
const textMatches = confirmText.trim() === requiredText.trim()
const canConfirm = allChecked && textMatches
const handleConfirm = () => {
if (!canConfirm) return
setCheckedItems(new Set())
setConfirmText('')
onConfirm()
}
const handleCancel = () => {
setCheckedItems(new Set())
setConfirmText('')
onOpenChange(false)
}
const toggleCheck = (idx: number) => {
setCheckedItems((prev) => {
const next = new Set(prev)
if (next.has(idx)) next.delete(idx)
else next.add(idx)
return next
})
}
return (
)
}