'use client' import { useState } from 'react' import { trpc } from '@/lib/trpc/client' import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog' import { Button } from '@/components/ui/button' import { Label } from '@/components/ui/label' import { Textarea } from '@/components/ui/textarea' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { AlertTriangle, Loader2, ShieldAlert } from 'lucide-react' import { toast } from 'sonner' interface COIDeclarationDialogProps { open: boolean assignmentId: string projectTitle: string onComplete: (hasConflict: boolean) => void } export function COIDeclarationDialog({ open, assignmentId, projectTitle, onComplete, }: COIDeclarationDialogProps) { const [hasConflict, setHasConflict] = useState(null) const [conflictType, setConflictType] = useState('') const [description, setDescription] = useState('') const [showConfirmation, setShowConfirmation] = useState(false) const declareCOI = trpc.evaluation.declareCOI.useMutation({ onSuccess: (data) => { if (data.hasConflict) { toast.info('Conflict of interest recorded. This project will be reassigned to another juror.') } setShowConfirmation(false) onComplete(data.hasConflict) }, onError: (error) => { toast.error(error.message || 'Failed to submit COI declaration') setShowConfirmation(false) }, }) const handleSubmit = () => { if (hasConflict === null) return // If declaring a conflict, show confirmation first if (hasConflict && !showConfirmation) { setShowConfirmation(true) return } declareCOI.mutate({ assignmentId, hasConflict, conflictType: hasConflict ? conflictType : undefined, description: hasConflict ? description : undefined, }) } const canSubmit = hasConflict !== null && (!hasConflict || (hasConflict && conflictType)) && !declareCOI.isPending return ( {showConfirmation ? ( <> Confirm Conflict of Interest

Are you sure you want to declare a conflict of interest with “{projectTitle}”?

This action cannot be undone. The project will be removed from your assignments and reassigned to another juror.
) : ( <> Conflict of Interest Declaration Before evaluating “{projectTitle}”, please declare whether you have any conflict of interest with this project.
{hasConflict && ( <>