'use client'; import { useRef, useEffect } from 'react'; import { AlertTriangle, ArrowRight, BrainCircuit, CheckCircle2, Loader2, ShieldCheck, UserRound, XCircle, Zap } from 'lucide-react'; import { scrollToSection } from '@/config/navigation'; import { useAppStore } from '@/store/useAppStore'; import { apiService } from '@/services/api'; import { Button } from '@/components/ui/Button'; import { Card } from '@/components/ui/Card'; import { InlineError } from '@/components/ui/InlineError'; import { Reveal } from '@/components/ui/Reveal'; import { SectionHeader } from '@/components/ui/SectionHeader'; function NeuralNetworkCanvas() { const canvasRef = useRef(null); useEffect(() => { const canvas = canvasRef.current; if (!canvas) return; const ctx = canvas.getContext('2d'); if (!ctx) return; let animationFrameId: number; let width = (canvas.width = canvas.offsetWidth); let height = (canvas.height = canvas.offsetHeight); const handleResize = () => { if (!canvas) return; width = canvas.width = canvas.offsetWidth; height = canvas.height = canvas.offsetHeight; }; window.addEventListener('resize', handleResize); const particleCount = 45; const particles: { x: number; y: number; vx: number; vy: number; radius: number }[] = []; for (let i = 0; i < particleCount; i++) { particles.push({ x: Math.random() * width, y: Math.random() * height, vx: (Math.random() - 0.5) * 0.7, vy: (Math.random() - 0.5) * 0.7, radius: Math.random() * 2 + 1.5, }); } const connectionDistance = 110; const draw = () => { ctx.clearRect(0, 0, width, height); // Draw lines ctx.lineWidth = 0.8; for (let i = 0; i < particleCount; i++) { const p1 = particles[i]; for (let j = i + 1; j < particleCount; j++) { const p2 = particles[j]; const dx = p1.x - p2.x; const dy = p1.y - p2.y; const dist = Math.sqrt(dx * dx + dy * dy); if (dist < connectionDistance) { const alpha = (1 - dist / connectionDistance) * 0.65; ctx.strokeStyle = `rgba(59, 130, 246, ${alpha})`; ctx.beginPath(); ctx.moveTo(p1.x, p1.y); ctx.lineTo(p2.x, p2.y); ctx.stroke(); } } } // Draw dots for (let i = 0; i < particleCount; i++) { const p = particles[i]; p.x += p.vx; p.y += p.vy; if (p.x < 0 || p.x > width) p.vx = -p.vx; if (p.y < 0 || p.y > height) p.vy = -p.vy; ctx.fillStyle = '#3b82f6'; ctx.beginPath(); ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2); ctx.fill(); } animationFrameId = requestAnimationFrame(draw); }; animationFrameId = requestAnimationFrame(draw); return () => { window.removeEventListener('resize', handleResize); cancelAnimationFrame(animationFrameId); }; }, []); return ; } export function ExtractionSection() { const { isExtracting, features, setPredicting, error, setError } = useAppStore(); const sapLead = features?.sapLead; const handlePredict = async () => { if (!features) return; setPredicting(true); setError(null); try { const prediction = await apiService.predictConversion(features); useAppStore.getState().setPrediction(prediction); setPredicting(false); scrollToSection('prediction'); } catch (err: unknown) { console.error(err); setPredicting(false); const message = err instanceof Error ? err.message : 'Prediction failed. Check that XGBoost API is running.'; setError(message); } }; const showPredictError = error?.includes('Prediction failed'); return (
{features && ( {features.extractionProvider === 'llama' ? 'LLaMA 3 (Groq)' : 'Local fallback'} )} {showPredictError && ( setError(null)} /> )} {isExtracting ? (

Extracting features…

) : features ? (

Extracted Signals

Products, topics, and labels from LLaMA

{features.rawFeatures?.length ? ( features.rawFeatures.map((f, i) => (
{f.label} {f.name}
)) ) : (

No labeled signals detected.

)}

Privacy Redaction

PII scrubbed before cloud inference

{features.privacy?.redactionCount ?? 0} item {(features.privacy?.redactionCount ?? 0) === 1 ? '' : 's'} redacted

Detected entities

{features.privacy?.entities?.length ? ( features.privacy.entities.map((entity, index) => (
{entity.type.replaceAll('_', ' ')} {entity.value}
)) ) : (

No sensitive entities detected.

)}

Behavioral signals

{[ { label: 'Intent', value: features.customerBehaviorSummary?.intentSignals ?? 0 }, { label: 'Hesitation', value: features.customerBehaviorSummary?.hesitationScore ?? 0 }, { label: 'Urgency', value: features.customerBehaviorSummary?.urgencySignals ?? 0 }, { label: 'Words', value: features.customerBehaviorSummary?.wordCount ?? 0 }, ].map((metric) => (
{metric.label}

{metric.value}

))}

Objections

Friction points raised in the conversation

{features.objections.length > 0 ? ( features.objections.map((obj, i) => ( {obj} )) ) : (

No objections detected.

)}
{sapLead && (
{sapLead.leadCreated ? : }

SAP Lead Creation

C4C lead sync result

{sapLead.sapStatus}
{[ { label: 'Lead Created', value: sapLead.leadCreated ? 'Yes' : 'No' }, { label: 'Lead Number', value: sapLead.leadId || 'Not returned' }, { label: 'Creation Status', value: sapLead.httpStatus ? `${sapLead.sapStatus} (${sapLead.httpStatus})` : sapLead.sapStatus, }, { label: 'SAP Object ID', value: sapLead.objectId || 'Not returned' }, { label: 'Errors', value: sapLead.error || 'None' }, ].map((item) => (
{item.label}

{item.value}

))}
)}
) : ( {/* Empty state: brain as animated 3D background */}
{/* Neural Network Canvas with Blur */}

Semantic Feature Extraction

Speech Intelligence and Intent Detection processes speech transcripts to identify purchase intent, client objections, PII privacy redactions, and customer behavior metrics.

{['Intent Detection', 'PII Redaction', 'Objection Mining', 'Diarization'].map((tag) => ( {tag} ))}
)}
); }