'use client'; import { useEffect, useRef, useState } from 'react'; import { useRouter, usePathname } from 'next/navigation'; import { useAuth } from '@/components/auth/AuthProvider'; import { useTheme } from '@/components/theme/ThemeProvider'; import api from '@/lib/api'; import PomodoroTimer from '@/components/timer/PomodoroTimer'; import { HomeIcon, ListIcon, CalendarIcon, BarChartIcon, PillIcon, SettingsIcon, LogOutIcon, ClockIcon, SunIcon, MoonIcon, } from '@/components/ui/Icons'; import Link from 'next/link'; const navItems = [ { href: '/dashboard', label: 'Today', icon: HomeIcon }, { href: '/dashboard/routines', label: 'Routines', icon: ListIcon }, { href: '/dashboard/tasks', label: 'Tasks', icon: ClockIcon }, { href: '/dashboard/history', label: 'History', icon: CalendarIcon }, { href: '/dashboard/stats', label: 'Stats', icon: BarChartIcon }, { href: '/dashboard/medications', label: 'Meds', icon: PillIcon }, ]; export default function DashboardLayout({ children, }: { children: React.ReactNode; }) { const { isAuthenticated, isLoading, logout } = useAuth(); const { isDark, toggleDark } = useTheme(); const router = useRouter(); const pathname = usePathname(); const [isTimerOpen, setIsTimerOpen] = useState(false); const tzSynced = useRef(false); useEffect(() => { if (!isLoading && !isAuthenticated) { router.push('/login'); } }, [isAuthenticated, isLoading, router]); // Sync timezone to backend once per session useEffect(() => { if (isAuthenticated && !tzSynced.current) { tzSynced.current = true; const offset = new Date().getTimezoneOffset(); const tzName = Intl.DateTimeFormat().resolvedOptions().timeZone; api.preferences.update({ timezone_offset: offset, timezone_name: tzName }).catch(() => {}); } }, [isAuthenticated]); if (isLoading) { return (

Loading...

); } if (!isAuthenticated) { return null; } // Hide chrome during active session run const isRunMode = pathname.includes('/run'); if (isRunMode) { return <>{children}; } return (
Synculous Synculous
setIsTimerOpen(!isTimerOpen)} />
{children}
); }