import { RefObject, useState, useEffect } from 'react'; import { SpeechBubbleTail } from './SpeechBubbleTail'; import { useCoachModalAnimation } from '@/hooks/useCoachModalAnimation'; interface Coach { id: string; name: string; description: string; } interface CoachAdPromptModalProps { show: boolean; onShowChange: (show: boolean) => void; triggerRef: RefObject; isGenerating: boolean; onCoachSelect: (coachId: string) => void; coaches: Coach[]; } export function CoachAdPromptModal({ show, onShowChange, triggerRef, isGenerating, onCoachSelect, coaches, }: CoachAdPromptModalProps) { const [step, setStep] = useState<'prompt' | 'selection'>('prompt'); // Reset step when modal is closed useEffect(() => { if (!show) { setStep('prompt'); } }, [show]); const { tailTarget, coachBubbleRef, coachBubbleContentRef, handleCloseModal, getOverlayClassName, getBubbleClassName, getBubbleStyle, } = useCoachModalAnimation(show, onShowChange, triggerRef); // Close modal (step reset is handled by useEffect when show changes) const handleClose = () => { handleCloseModal(); }; const handleConfirmPrompt = () => { setStep('selection'); }; const handleSelectCoach = (coachId: string) => { onCoachSelect(coachId); }; const handleBackToPrompt = () => { setStep('prompt'); }; return (
!isGenerating && handleClose()} >
e.stopPropagation()} > {/* Main Bubble */}
{step === 'prompt' ? ( <> {/* Step 1: Initial Prompt */}
👨‍🏫

您已經與學生對話一陣子了!

需要向我尋求建議嗎?

{/* Actions */}
) : ( <> {/* Step 2: Coach Selection */}

選擇您的教練

{/* Loading State */} {isGenerating && (
設定教練中...
)} {/* Coach Cards */}
{coaches.length === 0 ? (

目前沒有可用的教練

) : ( coaches.map((coach) => ( )) )}
{/* Back Button */}
)}
{/* Speech Bubble Tail - only show on prompt step */} {step === 'prompt' && tailTarget && }
); }