'use client'; import { useState, useEffect } from 'react'; import { useRouter, usePathname } from 'next/navigation'; import { motion, AnimatePresence } from 'framer-motion'; import { logout } from '@/lib/api'; import Link from 'next/link'; import { LogOut, User, ListTodo, BarChart3, FolderOpen, Calendar, PieChart, MessageSquare, Zap, Shield, Bell, AlertCircle, Clock } from 'lucide-react'; import { getTasks } from '@/lib/api'; import { showToast } from '@/lib/toast'; interface DesignerHeaderProps { children?: React.ReactNode; } export default function DesignerHeader({ children }: DesignerHeaderProps) { const router = useRouter(); const pathname = usePathname(); const [showNotifications, setShowNotifications] = useState(false); const [notifications, setNotifications] = useState([ { id: 1, title: 'Welcome to TaskFlow', desc: 'System initialized and ready.', time: 'Now', icon: Bell, color: 'text-indigo-400' }, { id: 2, title: 'Security Protocol', desc: 'Secure connection established.', time: '1h ago', icon: Shield, color: 'text-emerald-400' }, { id: 3, title: 'Achievement Unlocked', desc: 'Productivity streak started!', time: '2h ago', icon: Zap, color: 'text-yellow-400' }, ]); useEffect(() => { const checkTaskAlerts = async () => { const userStr = localStorage.getItem('user'); if (!userStr) return; try { const user = JSON.parse(userStr); const tasks = await getTasks(user.id); const today = new Date().toISOString().split('T')[0]; const dueTodayTasks = tasks.filter(t => !t.completed && t.due_date && t.due_date.startsWith(today)); const overdueTasks = tasks.filter(t => !t.completed && t.due_date && new Date(t.due_date) < new Date(today)); if (dueTodayTasks.length > 0 || overdueTasks.length > 0) { const newAlerts = [ ...dueTodayTasks.map(t => ({ id: `due-${t.id}`, title: 'Task Due Today', desc: t.title, time: 'Now', icon: Clock, color: 'text-yellow-400' })), ...overdueTasks.map(t => ({ id: `overdue-${t.id}`, title: 'Task Overdue', desc: t.title, time: 'Past Due', icon: AlertCircle, color: 'text-red-400' })) ]; setNotifications(prev => { // Avoid duplicates const existingIds = new Set(prev.map(n => n.id)); const filteredNew = newAlerts.filter(n => !existingIds.has(n.id)); return [...filteredNew, ...prev]; }); if (dueTodayTasks.length > 0) { showToast.warning(`You have ${dueTodayTasks.length} task(s) due today!`); } if (overdueTasks.length > 0) { showToast.error(`You have ${overdueTasks.length} overdue task(s)!`); } } } catch (err) { console.error('Failed to check task alerts:', err); } }; checkTaskAlerts(); // Check every 5 minutes const interval = setInterval(checkTaskAlerts, 5 * 60 * 1000); return () => clearInterval(interval); }, []); const handleLogout = async () => { try { await logout(); router.push('/login'); router.refresh(); } catch (error) { console.error('Logout error:', error); router.push('/login'); } }; const navItems = [ { name: 'Dashboard', href: '/tasks', icon: BarChart3 }, { name: 'Projects', href: '/projects', icon: FolderOpen }, { name: 'Calendar', href: '/calendar', icon: Calendar }, { name: 'Analytics', href: '/analytics', icon: PieChart }, { name: 'AI Chat', href: '/chat', icon: MessageSquare }, ]; const isActive = (path: string) => pathname === path; return (
TaskFlow
{children}
{showNotifications && (

Notifications

{notifications.length > 0 ? notifications.map((n) => (

{n.title}

{n.time}

{n.desc}

)) : (

No active signals

)}
)}
); }