"use client" import { useState, useCallback } from "react" import { motion, AnimatePresence } from "framer-motion" import type { AnalysisResult } from "@/app/page" interface UploadSectionProps { onResult: (result: AnalysisResult) => void profileName?: string } export function UploadSection({ onResult, profileName = "أنا" }: UploadSectionProps) { const [isDragging, setIsDragging] = useState(false) const [uploadedFile, setUploadedFile] = useState(null) const [isAnalyzing, setIsAnalyzing] = useState(false) const [isDone, setIsDone] = useState(false) const [error, setError] = useState(null) const handleDragOver = useCallback((e: React.DragEvent) => { e.preventDefault(); setIsDragging(true) }, []) const handleDragLeave = useCallback((e: React.DragEvent) => { e.preventDefault(); setIsDragging(false) }, []) const handleDrop = useCallback((e: React.DragEvent) => { e.preventDefault(); setIsDragging(false) if (e.dataTransfer.files.length > 0) handleFileUpload(e.dataTransfer.files[0]) }, []) const handleFileInput = (e: React.ChangeEvent) => { if (e.target.files?.[0]) handleFileUpload(e.target.files[0]) } const handleFileUpload = async (file: File) => { setUploadedFile(file) setIsAnalyzing(true) setIsDone(false) setError(null) try { const formData = new FormData() formData.append("file", file) const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL ?? "http://localhost:8000" const res = await fetch(`${backendUrl}/api/analyze`, { method: "POST", body: formData }) if (!res.ok) { const errData = await res.json().catch(() => ({})) throw new Error(errData.detail || "فشل التحليل") } const data: AnalysisResult = await res.json() onResult(data) setIsDone(true) setTimeout(() => { document.getElementById("results")?.scrollIntoView({ behavior: "smooth" }) }, 300) } catch (err) { setError(err instanceof Error ? err.message : "تعذّر الاتصال بالخادم. تأكد من تشغيل الباكند.") setIsDone(false) } finally { setIsAnalyzing(false) } } const removeFile = () => { setUploadedFile(null) setIsAnalyzing(false) setIsDone(false) setError(null) } return (
تحليل سريع وآمن

ارفع تقريرك الطبي

قم برفع ملفات PDF أو صور التقارير الطبية وسنقوم بتحليلها فوراً باستخدام أحدث تقنيات الذكاء الاصطناعي

{/* منطقة الرفع */}
{!uploadedFile ? (

اسحب الملفات هنا أو انقر للتحميل

PDF, PNG, JPG حتى 10MB

{[ { icon: "PDF", color: "bg-destructive/10 text-destructive" }, { icon: "PNG", color: "bg-primary/10 text-primary-foreground" }, { icon: "JPG", color: "bg-secondary/30 text-secondary-foreground" }, ].map((type) => (
{type.icon}
))}
) : (
{uploadedFile.name}
{(uploadedFile.size / 1024 / 1024).toFixed(2)} MB
{!isAnalyzing && ( )}
{isAnalyzing && (
جاري تحليل التقرير...
)} {isDone && !isAnalyzing && (
تم التحليل بنجاح!
)} {error && !isAnalyzing && (
{error}
)}
)}
بياناتك آمنة ومشفرة بالكامل
) }