'use client'; import React, { useState, useEffect, useRef } from 'react'; import { Play, Pause, RotateCcw, SkipForward, Flame, Brain, Coffee, CheckCircle2, Sparkles } from 'lucide-react'; import { Task } from '@/lib/types'; import { playNotificationChime } from '@/lib/audio'; interface PomodoroViewProps { tasks: Task[]; onCompleteSession?: () => void; } type TimerMode = 'focus' | 'shortBreak' | 'longBreak'; const MODE_CONFIG: Record = { focus: { label: 'Focus Session', duration: 25 * 60, icon: Brain, color: 'text-amber-400 bg-amber-500/10 border-amber-500/30', ringColor: '#f59e0b', }, shortBreak: { label: 'Short Rest', duration: 5 * 60, icon: Coffee, color: 'text-cyan-400 bg-cyan-500/10 border-cyan-500/30', ringColor: '#06b6d4', }, longBreak: { label: 'Long Recovery', duration: 15 * 60, icon: Coffee, color: 'text-emerald-400 bg-emerald-500/10 border-emerald-500/30', ringColor: '#10b981', }, }; export const PomodoroView: React.FC = ({ tasks }) => { const [mode, setMode] = useState('focus'); const [timeLeft, setTimeLeft] = useState(MODE_CONFIG.focus.duration); const [isActive, setIsActive] = useState(false); const [completedSessions, setCompletedSessions] = useState(3); const [selectedTaskId, setSelectedTaskId] = useState(''); const timerRef = useRef(null); useEffect(() => { if (isActive) { timerRef.current = setInterval(() => { setTimeLeft((prev) => { if (prev <= 1) { clearInterval(timerRef.current!); setIsActive(false); playNotificationChime('complete'); if (mode === 'focus') { setCompletedSessions((c) => c + 1); } return 0; } return prev - 1; }); }, 1000); } else if (timerRef.current) { clearInterval(timerRef.current); } return () => { if (timerRef.current) clearInterval(timerRef.current); }; }, [isActive, mode]); const switchMode = (newMode: TimerMode) => { setIsActive(false); setMode(newMode); setTimeLeft(MODE_CONFIG[newMode].duration); playNotificationChime('click'); }; const handleToggleTimer = () => { setIsActive(!isActive); playNotificationChime('click'); }; const handleReset = () => { setIsActive(false); setTimeLeft(MODE_CONFIG[mode].duration); playNotificationChime('click'); }; const handleSkip = () => { setIsActive(false); if (mode === 'focus') { switchMode('shortBreak'); } else { switchMode('focus'); } }; const minutes = Math.floor(timeLeft / 60); const seconds = timeLeft % 60; const timeFormatted = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`; const currentDuration = MODE_CONFIG[mode].duration; const progressPercent = ((currentDuration - timeLeft) / currentDuration) * 100; // SVG ring properties const radius = 130; const circumference = 2 * Math.PI * radius; const strokeDashoffset = circumference - (progressPercent / 100) * circumference; const currentTask = tasks.find((t) => t.id === selectedTaskId); return (
{/* Mode Switcher */}
{(['focus', 'shortBreak', 'longBreak'] as const).map((m) => { const isSelected = mode === m; const Icon = MODE_CONFIG[m].icon; return ( ); })}
{/* Center Circular Countdown Card */}
{/* Ambient background glow */}
{/* Circular SVG Timer */}
{/* Background Track */} {/* Animated Progress Ring */} {/* Time Display Inside Circle */}
{timeFormatted} {isActive ? 'Session In Progress' : 'Paused'} {currentTask && ( 🎯 {currentTask.title} )}
{/* Control Buttons */}
{/* Focus Session Target & Task Pairing */}
{/* Daily Focus Sessions Card */}
Sessions Completed
{completedSessions} / 6 Sessions
{completedSessions * 25} Mins

Deep Work Today

{/* Task Attachment Picker */}
Pair with Task {selectedTaskId && ( )}
); };