import React, { useEffect, useState } from 'react'; interface FlyToHistoryProps { onComplete: () => void; targetRef: React.RefObject; mode: 'vc' | 'tts'; } const FlyToHistory: React.FC = ({ onComplete, targetRef, mode }) => { const [style, setStyle] = useState({ top: '50%', left: '50%', transform: 'translate(-50%, -50%) scale(1.5)', opacity: 0, }); const isVoice = mode === 'vc'; // Distinct visuals for Voice vs Text const gradientClass = isVoice ? 'from-blue-600 via-indigo-500 to-purple-600' : 'from-teal-400 via-emerald-500 to-cyan-600'; const shadowColor = isVoice ? 'rgba(79, 70, 229, 0.6)' : 'rgba(16, 185, 129, 0.6)'; // Distinct icons const iconClass = isVoice ? 'fa-microphone-lines' : 'fa-keyboard'; useEffect(() => { // Initial reveal requestAnimationFrame(() => { setStyle(prev => ({ ...prev, opacity: 1, transform: 'translate(-50%, -50%) scale(1)' })); }); if (!targetRef.current) { setTimeout(onComplete, 800); return; } // 1. Get Target Coordinates const targetRect = targetRef.current.getBoundingClientRect(); const targetX = targetRect.left + targetRect.width / 2; const targetY = targetRect.top + targetRect.height / 2; // 2. Start Flight Animation const animationTimeout = setTimeout(() => { setStyle({ top: `${targetY}px`, left: `${targetX}px`, // Shrink, rotate, and fade out as it hits the target transform: 'translate(-50%, -50%) scale(0.1) rotate(-180deg)', opacity: 0.1, }); }, 250); // Small pause for user to recognize the icon // 3. Cleanup const endTimeout = setTimeout(() => { onComplete(); }, 1000); return () => { clearTimeout(animationTimeout); clearTimeout(endTimeout); }; }, [targetRef, onComplete]); return ( <> {/* Moving Object */}
{/* Main Icon Orb */}
{/* Inner Ping Effect */}
{/* Sparkles */}
{/* Trail Effect */}
{/* Screen Flash Overlay */}
); }; export default FlyToHistory;