'use client'; import { useEffect, useState } from 'react'; import { cn } from '@/shared/lib/cn'; type EndSessionStage = 'decision' | 'success' | 'unfinished'; interface EndSessionConfirmModalProps { open: boolean; currentGoal: string; onClose: () => void; onAdvanceGoal: (nextGoal: string) => Promise | boolean; // kept for compatibility if needed onFinishHere: () => Promise | boolean; // User achieved goal -> exit onEndSession: () => Promise | boolean; // User did not achieve -> exit } export const EndSessionConfirmModal = ({ open, currentGoal, onClose, onFinishHere, onEndSession, }: EndSessionConfirmModalProps) => { const [stage, setStage] = useState('decision'); const [isSubmitting, setIsSubmitting] = useState(false); const trimmedGoal = currentGoal.trim() || '목표 없음'; useEffect(() => { if (!open) { setTimeout(() => setStage('decision'), 300); // Reset after close animation setIsSubmitting(false); } }, [open]); const handleFinish = async () => { if (isSubmitting) return; setIsSubmitting(true); try { const didFinish = await onFinishHere(); if (didFinish) onClose(); } finally { setIsSubmitting(false); } }; const handleEnd = async () => { if (isSubmitting) return; setIsSubmitting(true); try { const didEnd = await onEndSession(); if (didEnd) onClose(); } finally { setIsSubmitting(false); } }; return (
{stage === 'decision' && (

Session Review

이번 세션의 목표를
달성하셨나요?

현재 목표

{trimmedGoal}

)} {stage === 'success' && (

완벽합니다.

성공적으로 목표를 완수했습니다.
스스로에게 보상을 줄 시간입니다.

)} {stage === 'unfinished' && (
🌱

괜찮습니다.
집중은 근육이니까요.

조금씩 단련해나가면 됩니다.
이 흐름을 다음 세션에 이어서 해볼까요?

)}
); };