"use client"; import { motion, useScroll, useTransform } from "framer-motion"; import { Brain, Search, Database, Zap, Shield, TrendingUp, CheckCircle, Activity, Cpu, Network, } from "lucide-react"; import { useRef, useEffect, useState } from "react"; export default function AIDiagnosis() { const containerRef = useRef(null); const canvasContainerRef = useRef(null); // Ref for the wrapper of the canvas const canvasRef = useRef(null); const [modelLoaded, setModelLoaded] = useState(false); const [scanProgress, setScanProgress] = useState(0); const { scrollYProgress } = useScroll({ target: containerRef, offset: ["start end", "end start"], }); const y = useTransform(scrollYProgress, [0, 0.5], [100, 0]); const opacity = useTransform(scrollYProgress, [0, 0.3], [0, 1]); const scale = useTransform(scrollYProgress, [0, 0.5], [0.95, 1]); // Subtle scale // Simulate scan progress useEffect(() => { const interval = setInterval(() => { setScanProgress((prev) => (prev >= 100 ? 0 : prev + 1)); }, 50); return () => clearInterval(interval); }, []); // Three.js setup useEffect(() => { if (typeof window === "undefined" || !canvasRef.current || !canvasContainerRef.current) return; let animationId: number | undefined; let scene: any; let camera: any; let renderer: any; let model: any; let controls: any; const initThreeJS = async () => { const THREE = await import("three"); const { GLTFLoader, OrbitControls } = await import("three-stdlib"); // Get initial dimensions from the parent container const width = canvasContainerRef.current?.clientWidth || 500; const height = canvasContainerRef.current?.clientHeight || 500; scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000); camera.position.set(0, 0, 5); renderer = new THREE.WebGLRenderer({ canvas: canvasRef.current!, alpha: true, antialias: true, }); renderer.setSize(width, height); renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); renderer.setClearColor(0x000000, 0); // Lighting scene.add(new THREE.AmbientLight(0xffffff, 0.8)); const dirLight1 = new THREE.DirectionalLight(0x6366f1, 1.2); dirLight1.position.set(5, 5, 5); scene.add(dirLight1); const dirLight2 = new THREE.DirectionalLight(0xa855f7, 0.8); dirLight2.position.set(-5, 3, -5); scene.add(dirLight2); // Controls controls = new OrbitControls(camera, renderer.domElement); controls.enableDamping = true; controls.dampingFactor = 0.05; controls.enableZoom = false; controls.autoRotate = true; controls.autoRotateSpeed = 1.5; // Handle Resize - Critical for responsiveness const handleResize = () => { if (!canvasContainerRef.current || !camera || !renderer) return; const newWidth = canvasContainerRef.current.clientWidth; const newHeight = canvasContainerRef.current.clientHeight; camera.aspect = newWidth / newHeight; camera.updateProjectionMatrix(); renderer.setSize(newWidth, newHeight); }; // Use ResizeObserver for robust sizing (handles container changes, not just window) const resizeObserver = new ResizeObserver(() => handleResize()); resizeObserver.observe(canvasContainerRef.current!); // Model loading const loader = new GLTFLoader(); const modelURL = "/human_body.glb"; try { const gltf = await loader.loadAsync(modelURL); model = gltf.scene; // Center & scale model const box = new THREE.Box3().setFromObject(model); const center = box.getCenter(new THREE.Vector3()); const size = box.getSize(new THREE.Vector3()); const maxDim = Math.max(size.x, size.y, size.z); const scaleFactor = 3 / maxDim; model.scale.setScalar(scaleFactor); model.position.sub(center.multiplyScalar(scaleFactor)); model.traverse((child: any) => { if (child.isMesh) { child.castShadow = false; child.receiveShadow = false; } }); scene.add(model); setModelLoaded(true); } catch (error) { console.warn("Using fallback geometry"); const geometry = new THREE.IcosahedronGeometry(1.5, 2); const material = new THREE.MeshStandardMaterial({ color: 0x6366f1, roughness: 0.3, metalness: 0.7, emissive: 0x3b82f6, emissiveIntensity: 0.2, wireframe: true, // Added wireframe for a more "tech" fallback look }); model = new THREE.Mesh(geometry, material); scene.add(model); setModelLoaded(true); } // Animation loop const animate = () => { animationId = requestAnimationFrame(animate); controls.update(); if (model) model.rotation.y += 0.002; renderer.render(scene, camera); }; animate(); // Clean up specifically for this closure return () => { resizeObserver.disconnect(); }; }; const cleanupPromise = initThreeJS(); return () => { cleanupPromise.then((cleanup) => cleanup && cleanup()); if (animationId !== undefined) cancelAnimationFrame(animationId); if (controls) controls.dispose(); if (renderer) renderer.dispose(); // Simplified scene disposal if (scene) scene.clear(); }; }, []); return (
{/* Ambient glows - Optimized for mobile by reducing blur radius slightly */} {/*
*/} {/* Subtle grid */}
{/* --- 3D Viewer Column --- */} {/* Order-2 on mobile ensures text comes first if desired, but default is fine */} {/* Background Blur blob */}
{/* Card Header */}

Neural Engine

Analysis Active

Live Feed
{/* Canvas Container - Responsive Aspect Ratio */}
{/* Decorative corners */}
{/* The actual canvas wrapper */}
{/* Loading State */} {!modelLoaded && (

Initializing Network...

)} {/* Scanning Animation Overlay */} {modelLoaded && (
)}
{/* Status footer */}
Analysis Progress {scanProgress}%
{[ { icon: Cpu, label: "CPU Load", value: "98%", color: "text-cyan-400" }, { icon: Network, label: "Net Load", value: "76%", color: "text-purple-400" }, { icon: Activity, label: "Accuracy", value: "99%", color: "text-green-400" }, ].map((stat, idx) => (

{stat.label}

{stat.value}

))}

Interactive 3D Visualization

{/* --- Text / Features Column --- */}

Neural Clinical
Synthesis

Enterprise-grade diagnostic assistance powered by advanced AI. Cross-reference clinical patterns against{" "} global medical databases with{" "} sub-second latency.

{/* Feature Cards - Stack on mobile, grid on tablet+ */} {[ { icon: Search, title: "Pattern Recognition", text: "AI-powered clinical marker identification with zero-bias analysis technology.", color: "from-cyan-500 to-cyan-500", iconColor: "text-cyan-400", }, { icon: Database, title: "Medical Database", text: "Instant access to verified institutional medical models and research.", color: "from-purple-500 to-pink-500", iconColor: "text-purple-400", }, ].map((item, i) => (

{item.title}

{item.text}

))} {/* Stats - Grid adjustments */} {[ { icon: Zap, value: "<500ms", label: "Query Time" }, { icon: Shield, value: "100%", label: "Secure" }, { icon: TrendingUp, value: "99.8%", label: "Accuracy" }, ].map((stat, i) => (

{stat.value}

{stat.label}

))}
{/* Trust Indicators */} {["FDA Compliant", "HIPAA Certified", "ISO 27001"].map((badge, i) => (
{badge}
))}
); }