Files
webb/src/components/tools/ProcessingOverlay.tsx
T

141 lines
6.2 KiB
TypeScript
Raw Normal View History

'use client';
import React, { useState, useEffect } from 'react';
import { Sparkles, Cpu, Layers, Zap, ShieldCheck } from 'lucide-react';
interface ProcessingOverlayProps {
toolName?: string;
stageMessages?: string[];
aspectRatio?: string;
}
export function ProcessingOverlay({
toolName = 'Neural Vision Model',
stageMessages,
aspectRatio = 'aspect-[4/3] sm:aspect-[16/10]',
}: ProcessingOverlayProps) {
const defaultStages = [
'Initializing volatile GPU tensor core...',
'Analyzing photographic topology & lighting coordinates...',
'Synthesizing generative neural model...',
'Reconstructing sub-pixel micro-details & HD polish...',
'Finalizing crystal-clear preview...',
];
const stages = stageMessages && stageMessages.length > 0 ? stageMessages : defaultStages;
const [currentStageIdx, setCurrentStageIdx] = useState(0);
const [progress, setProgress] = useState(12);
const [elapsedSec, setElapsedSec] = useState(0);
// Smooth elapsed timer
useEffect(() => {
const timer = setInterval(() => {
setElapsedSec((prev) => +(prev + 0.1).toFixed(1));
}, 100);
return () => clearInterval(timer);
}, []);
// Cycle through inference stages & smooth progress curve
useEffect(() => {
const stageInterval = setInterval(() => {
setCurrentStageIdx((prev) => (prev < stages.length - 1 ? prev + 1 : prev));
}, 900);
const progressInterval = setInterval(() => {
setProgress((prev) => {
if (prev >= 94) return 94; // Wait for server resolution
const delta = Math.max(1, Math.floor((95 - prev) * 0.15));
return Math.min(94, prev + delta);
});
}, 150);
return () => {
clearInterval(stageInterval);
clearInterval(progressInterval);
};
}, [stages.length]);
return (
<div className="absolute inset-0 z-30 flex items-center justify-center overflow-hidden rounded-2xl bg-black/60 backdrop-blur-md transition-all duration-300">
{/* 1. Moving Laser Scanning Beam */}
<div className="laser-scanner">
<div className="laser-scanner-line" />
</div>
{/* 2. Cybernetic Vision Grid Overlay */}
<div
className="absolute inset-0 pointer-events-none opacity-20 bg-[linear-gradient(to_right,#38bdf8_1px,transparent_1px),linear-gradient(to_bottom,#38bdf8_1px,transparent_1px)] bg-[size:32px_32px]"
aria-hidden="true"
/>
{/* 3. Corner Targeting Reticles */}
<div className="absolute top-4 left-4 w-7 h-7 border-t-2 border-l-2 border-cyan-400/80 rounded-tl-sm pointer-events-none animate-pulse" />
<div className="absolute top-4 right-4 w-7 h-7 border-t-2 border-r-2 border-cyan-400/80 rounded-tr-sm pointer-events-none animate-pulse" />
<div className="absolute bottom-4 left-4 w-7 h-7 border-b-2 border-l-2 border-cyan-400/80 rounded-bl-sm pointer-events-none animate-pulse" />
<div className="absolute bottom-4 right-4 w-7 h-7 border-b-2 border-r-2 border-cyan-400/80 rounded-br-sm pointer-events-none animate-pulse" />
{/* 4. Central Holographic HUD Card */}
<div className="relative z-30 max-w-sm sm:max-w-md w-11/12 p-6 sm:p-7 rounded-3xl bg-slate-950/85 border border-cyan-500/30 shadow-[0_0_50px_rgba(56,189,248,0.25)] text-center text-white space-y-5 backdrop-blur-xl">
{/* Top Badges */}
<div className="flex items-center justify-between text-[11px] font-mono font-semibold text-cyan-300 border-b border-cyan-500/20 pb-3">
<span className="flex items-center gap-1.5 uppercase tracking-wider">
<Cpu className="w-3.5 h-3.5 text-cyan-400 animate-spin" style={{ animationDuration: '6s' }} />
<span>GPU Tensor Model</span>
</span>
<span className="px-2 py-0.5 rounded-full bg-cyan-950/80 border border-cyan-400/30 text-cyan-300 font-mono">
{elapsedSec.toFixed(1)}s
</span>
</div>
{/* Radar Spinner & Icon */}
<div className="relative w-16 h-16 sm:w-20 sm:h-20 mx-auto flex items-center justify-center">
{/* Outer glowing pulsed ring */}
<div className="absolute inset-0 rounded-full border-2 border-cyan-400/20 animate-ping opacity-30" />
{/* Rotating gradient track */}
<div
className="absolute inset-0 rounded-full border-2 border-t-cyan-400 border-r-indigo-500 border-b-purple-500 border-l-transparent animate-spin"
style={{ animationDuration: '1.2s' }}
/>
{/* Inner pulsating core */}
<div className="w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-gradient-to-tr from-cyan-500 to-indigo-600 flex items-center justify-center shadow-lg shadow-cyan-500/50">
<Sparkles className="w-5 h-5 sm:w-6 sm:h-6 text-white animate-pulse" />
</div>
</div>
{/* Dynamic Stage Title & Progress */}
<div className="space-y-2">
<div className="flex items-center justify-between text-xs font-body font-medium">
<span className="text-white font-semibold flex items-center gap-1.5">
<Zap className="w-3.5 h-3.5 text-amber-400 animate-pulse" />
<span>Processing {toolName}</span>
</span>
<span className="font-mono text-cyan-400 font-bold">{progress}%</span>
</div>
{/* Glowing Animated Progress Bar */}
<div className="w-full h-2 rounded-full bg-slate-900 border border-cyan-500/30 overflow-hidden p-0.5">
<div
className="h-full rounded-full bg-gradient-to-r from-cyan-400 via-indigo-400 to-purple-400 transition-all duration-200 shadow-[0_0_12px_#38bdf8]"
style={{ width: `${progress}%` }}
/>
</div>
{/* Current Step Description */}
<p className="text-xs text-slate-300 font-body min-h-[36px] flex items-center justify-center leading-relaxed animate-fade-in">
{stages[currentStageIdx]}
</p>
</div>
{/* Reassurance Footer */}
<div className="pt-2 border-t border-cyan-500/20 flex items-center justify-center gap-1.5 text-[10px] text-slate-400 font-body">
<ShieldCheck className="w-3.5 h-3.5 text-emerald-400" />
<span>Volatile GPU RAM Execution · Zero Server Storage</span>
</div>
</div>
</div>
);
}