import React, { useState } from 'react'; import { motion } from 'framer-motion'; import { Scale, Calendar, Users, MapPin, FileText, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Card } from '@/components/ui/card'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { useToast } from '@/hooks/use-toast'; import { cn } from '@/lib/utils'; interface CreateCaseModalProps { isOpen: boolean; onClose: () => void; onCaseCreated: (caseData: any) => void; } interface CaseFormData { caseType: string; jurisdiction: string; petitioner: string; respondent: string; judge: string; filingDate: string; description: string; priority: 'low' | 'medium' | 'high' | 'urgent'; tags: string[]; } export function CreateCaseModal({ isOpen, onClose, onCaseCreated }: CreateCaseModalProps) { const [formData, setFormData] = useState({ caseType: '', jurisdiction: 'ILLINOIS-COOK', petitioner: '', respondent: '', judge: '', filingDate: new Date().toISOString().split('T')[0], description: '', priority: 'medium', tags: [], }); const [tagInput, setTagInput] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const { toast } = useToast(); const caseTypes = [ 'CIVIL', 'CRIMINAL', 'FAMILY', 'CORPORATE', 'PROPERTY', 'EMPLOYMENT', 'PERSONAL_INJURY', 'INTELLECTUAL_PROPERTY', 'BANKRUPTCY', 'IMMIGRATION' ]; const jurisdictions = [ 'ILLINOIS-COOK', 'ILLINOIS-DUPAGE', 'ILLINOIS-LAKE', 'ILLINOIS-WILL', 'ILLINOIS-KANE', 'FEDERAL-NORTHERN', 'FEDERAL-CENTRAL', 'FEDERAL-SOUTHERN' ]; const handleInputChange = (field: keyof CaseFormData, value: string) => { setFormData(prev => ({ ...prev, [field]: value })); }; const handleAddTag = () => { const tag = tagInput.trim(); if (tag && !formData.tags.includes(tag)) { setFormData(prev => ({ ...prev, tags: [...prev.tags, tag] })); setTagInput(''); } }; const handleRemoveTag = (tagToRemove: string) => { setFormData(prev => ({ ...prev, tags: prev.tags.filter(tag => tag !== tagToRemove) })); }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { e.preventDefault(); handleAddTag(); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsSubmitting(true); try { const response = await fetch('/api/v1/cases/create', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('chittychain_token')}`, }, body: JSON.stringify({ ...formData, metadata: { description: formData.description, priority: formData.priority, tags: formData.tags, createdAt: new Date().toISOString(), } }), }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.error || 'Failed to create case'); } const caseData = await response.json(); onCaseCreated(caseData); toast({ title: "Case Created Successfully", description: `Case ${caseData.caseNumber} has been created and secured on the blockchain.`, }); // Reset form setFormData({ caseType: '', jurisdiction: 'ILLINOIS-COOK', petitioner: '', respondent: '', judge: '', filingDate: new Date().toISOString().split('T')[0], description: '', priority: 'medium', tags: [], }); setTagInput(''); } catch (error) { console.error('Case creation error:', error); toast({ title: "Case Creation Failed", description: error instanceof Error ? error.message : 'Unknown error occurred', variant: "destructive", }); } finally { setIsSubmitting(false); } }; if (!isOpen) return null; return ( e.stopPropagation()} className="w-full max-w-2xl max-h-[90vh] overflow-y-auto" > {/* Header */}

Create New Case

Initialize a blockchain-secured legal case

{/* Form */}
{/* Case Type & Jurisdiction */}
{/* Parties */}
handleInputChange('petitioner', e.target.value)} placeholder="Enter petitioner name" className="bg-gray-900/50 border-gray-800 text-white" required />
handleInputChange('respondent', e.target.value)} placeholder="Enter respondent name (optional)" className="bg-gray-900/50 border-gray-800 text-white" />
{/* Judge & Filing Date */}
handleInputChange('judge', e.target.value)} placeholder="Judge name (if assigned)" className="bg-gray-900/50 border-gray-800 text-white" />
handleInputChange('filingDate', e.target.value)} className="bg-gray-900/50 border-gray-800 text-white" required />
{/* Priority */}
{/* Description */}