import { useState, useEffect } from 'react';
import { NavLink, useNavigate, useLocation } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
function TeamNav({ onNav }) {
return (
{[
{ to: '/dashboard', label: 'Dashboard' },
{ to: '/requests', label: 'Requests' },
{ to: '/invoices', label: 'Invoices' },
{ to: '/companies', label: 'Companies' },
].map(({ to, label }) => (
`sidebar-link${isActive ? ' active' : ''}`}>
{label}
))}
);
}
function ClientNav({ onNav }) {
return (
{[
{ to: '/my-dashboard', label: 'Dashboard' },
{ to: '/my-projects', label: 'Projects' },
{ to: '/my-invoices', label: 'Invoices' },
{ to: '/my-company', label: 'Company' },
].map(({ to, label }) => (
`sidebar-link${isActive ? ' active' : ''}`}>
{label}
))}
);
}
export default function Layout({ children }) {
const { currentUser, logout } = useAuth();
const navigate = useNavigate();
const location = useLocation();
const [theme, setTheme] = useState(() => localStorage.getItem('theme') || 'dark');
const [menuOpen, setMenuOpen] = useState(false);
useEffect(() => {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
}, [theme]);
// Close menu on route change
useEffect(() => { setMenuOpen(false); }, [location.pathname]);
const toggleTheme = () => setTheme(t => t === 'dark' ? 'light' : 'dark');
const handleLogout = () => { logout(); navigate('/'); };
const initials = currentUser?.name
?.split(' ').map(n => n[0]).join('').toUpperCase().slice(0, 2);
return (
{/* Overlay */}
{menuOpen &&
setMenuOpen(false)} />}
{/* Mobile top bar inside main wrapper so it sits at the top */}
{children}
);
}