import React, { useState, useEffect, useCallback } from 'react'; import { X, ChevronRight, ChevronLeft } from 'lucide-react'; import { useLanguage } from '../contexts/LanguageContext'; interface Step { id: string; title: string; content: string; position: 'top' | 'bottom' | 'left' | 'right'; } export default function UserGuide({ isOpen, onClose }: { isOpen: boolean; onClose: () => void }) { const { t } = useLanguage(); const [currentStep, setCurrentStep] = useState(0); const [highlightStyle, setHighlightStyle] = useState({}); const steps: Step[] = [ { id: 'sidebar-upload-area', title: t.guide.step1Title, content: t.guide.step1Content, position: 'right', }, { id: 'sidebar-history', title: t.guide.step2Title, content: t.guide.step2Content, position: 'right', }, { id: 'file-preview-empty', title: t.guide.step3Title, content: t.guide.step3Content, position: 'right', }, { id: 'result-empty-state', title: t.guide.step4Title, content: t.guide.step4Content, position: 'left', }, { id: 'export-button', title: t.guide.stepExportTitle, content: t.guide.stepExportContent, position: 'left', }, ]; const updateHighlight = useCallback(() => { if (!isOpen || steps.length === 0) return; const element = document.getElementById(steps[currentStep].id); if (element) { const rect = element.getBoundingClientRect(); setHighlightStyle({ top: rect.top - 8, left: rect.left - 8, width: rect.width + 16, height: rect.height + 16, opacity: 1, }); element.scrollIntoView({ behavior: 'smooth', block: 'center' }); } else { setHighlightStyle({ opacity: 0 }); } }, [currentStep, isOpen, steps, t.guide]); useEffect(() => { if (isOpen) { updateHighlight(); window.addEventListener('resize', updateHighlight); } return () => window.removeEventListener('resize', updateHighlight); }, [isOpen, updateHighlight]); if (!isOpen) return null; const handleNext = () => { if (currentStep < steps.length - 1) { setCurrentStep(currentStep + 1); } else { onClose(); setCurrentStep(0); } }; const handlePrev = () => { if (currentStep > 0) { setCurrentStep(currentStep - 1); } }; return (
{/* Backdrop with hole */}
{/* Highlight border */}
{/* Tooltip */}
Step {currentStep + 1} of {steps.length}

{steps[currentStep].title}

{steps[currentStep].content}

); }