import React, { useState, useEffect, useRef } from 'react'; interface Task { id: string; title: string; completed: boolean; } interface FocusModeOverlayProps { task: Task | null; duration: number; // in minutes onClose: () => void; onComplete: (taskId: string) => void; } export default function FocusModeOverlay({ task, duration, onClose, onComplete }: FocusModeOverlayProps) { const [timeLeft, setTimeLeft] = useState(duration * 60); const [isActive, setIsActive] = useState(false); const [isCompleting, setIsCompleting] = useState(false); const timerRef = useRef(null); useEffect(() => { if (isActive && timeLeft > 0) { timerRef.current = setInterval(() => { setTimeLeft((prev) => prev - 1); }, 1000); } else if (timeLeft === 0) { if (timerRef.current) clearInterval(timerRef.current); setIsActive(false); // Play sound? } return () => { if (timerRef.current) clearInterval(timerRef.current); }; }, [isActive, timeLeft]); const formatTime = (seconds: number) => { const m = Math.floor(seconds / 60); const s = seconds % 60; return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`; }; const handleToggleTimer = () => { setIsActive(!isActive); }; const handleReset = () => { setIsActive(false); setTimeLeft(duration * 60); }; const handleComplete = async () => { if (!task) return; setIsCompleting(true); // Small delay for animation await new Promise(resolve => setTimeout(resolve, 500)); onComplete(task.id); setIsCompleting(false); handleReset(); // Reset timer for next task }; // Calculate progress for circle // Circumference = 2 * PI * r // r = 120 const circumference = 2 * Math.PI * 120; const progress = timeLeft / (duration * 60); const dashoffset = circumference * (1 - progress); return (

DO THIS NOW

{task ? (
{task.title}
) : (
No tasks scheduled for today!
Time to relax or plan ahead.
)}
{formatTime(timeLeft)}
{task && ( )}
); }