import React, { useCallback, useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { RefreshCw, FilePlus } from "lucide-react"; import { useToast } from "@/hooks/use-toast"; import { MultipleFileUploadZone } from "../file-upload/multiple-file-upload-zone"; export default function ClaimDocumentsUploadMultiple() { const { toast } = useToast(); // Internal configuration const MAX_FILES = 10; const ACCEPTED_FILE_TYPES = "application/pdf,image/jpeg,image/jpg,image/png,image/webp"; const TITLE = "Upload Claim Document(s)"; const DESCRIPTION = "You can upload up to 10 files. Allowed types: PDF, JPG, PNG, WEBP."; // Internal state const [uploadedFiles, setUploadedFiles] = useState([]); const [isUploading, setIsUploading] = useState(false); // forwarded to upload zone const [isExtracting, setIsExtracting] = useState(false); // Called by MultipleFileUploadZone whenever its internal list changes. const handleFileUpload = useCallback((files: File[]) => { setUploadedFiles(files); }, []); // Dummy save (simulate async). Replace with real API call when needed. const handleSave = useCallback(async (files: File[]) => { // simulate network / processing time await new Promise((res) => setTimeout(res, 800)); console.log( "handleSave called for files:", files.map((f) => f.name) ); }, []); // Extract handler — calls handleSave (dummy) and shows toasts. const handleExtract = useCallback(async () => { if (uploadedFiles.length === 0) { toast({ title: "No files", description: "Please upload at least one file before extracting.", variant: "destructive", }); return; } if (isExtracting) return; setIsExtracting(true); try { await handleSave(uploadedFiles); toast({ title: "Extraction started", description: `Processing ${uploadedFiles.length} file(s).`, variant: "default", }); // If you want to clear the upload zone after extraction, you'll need a small // change in MultipleFileUploadZone to accept a reset signal from parent. // We intentionally leave files intact here. } catch (err) { toast({ title: "Extraction failed", description: "There was an error starting extraction. Please try again.", variant: "destructive", }); // eslint-disable-next-line no-console console.error("extract error", err); } finally { setIsExtracting(false); } }, [uploadedFiles, handleSave, isExtracting, toast]); return (
{TITLE} {DESCRIPTION} {/* File Upload Section */}
{/* Show list of files received from the upload zone */} {uploadedFiles.length > 0 && (

Uploaded ({uploadedFiles.length}/{MAX_FILES})

    {uploadedFiles.map((file, index) => (
  • {file.name}
  • ))}
)}
{/* Action Button */}
); }