import React, { useState } from 'react'; import NotificationBell from './NotificationBell'; import { TeamPresence } from './TeamPresence'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { Menu, X, FolderOpen, Layers, ClipboardCheck, LogOut, TrendingUp, Sun, Moon, HelpCircle, Shield, Wrench, Terminal, LayoutDashboard, Package, Thermometer } from 'lucide-react'; import { clsx } from 'clsx'; import { useClerk, UserButton, useUser, OrganizationSwitcher, useOrganization } from '@clerk/clerk-react'; import { TechnicalManual } from './TechnicalManual'; import { useAuth } from '../context/useAuth'; // import { useSystemSettings } from '../context/SystemSettingsContext'; import { setApiOrgData } from '../services/api'; interface LayoutProps { children: React.ReactNode; } export const Layout: React.FC = ({ children }) => { const [isSidebarOpen, setIsSidebarOpen] = useState(false); const [isManualOpen, setIsManualOpen] = useState(false); const [isDarkMode, setIsDarkMode] = useState(() => { const saved = localStorage.getItem('theme'); return saved === 'dark' || (!saved && window.matchMedia('(prefers-color-scheme: dark)').matches); }); const location = useLocation(); const { signOut } = useClerk(); const { user } = useUser(); const { organization } = useOrganization(); const { isAdmin, isUser, isDeveloper, appUser } = useAuth(); // const { settings } = useSystemSettings(); // Sync Organization ID with API client React.useEffect(() => { if (organization?.id) { setApiOrgData(organization.id, organization.name); } else { setApiOrgData(null); } }, [organization]); // Helper to get role display name const getRoleDisplay = () => { switch (appUser?.role) { case 'admin': return { label: 'Admin', color: 'text-amber-500' }; case 'user': return { label: 'Usuário', color: 'text-green-500' }; case 'guest': return { label: 'Convidado', color: 'text-blue-400' }; default: return { label: 'Carregando...', color: 'text-text-muted' }; } }; const roleInfo = getRoleDisplay(); React.useEffect(() => { if (isDarkMode) { document.documentElement.classList.add('dark'); localStorage.setItem('theme', 'dark'); } else { document.documentElement.classList.remove('dark'); localStorage.setItem('theme', 'light'); } }, [isDarkMode]); const toggleTheme = () => setIsDarkMode(!isDarkMode); const navigate = useNavigate(); // Guest Redirection Logic React.useEffect(() => { if (appUser?.role === 'guest' && (location.pathname === '/' || location.pathname === '/projects')) { navigate('/guest-dashboard'); } }, [appUser, location.pathname, navigate]); interface NavItem { icon: React.ElementType; label: string; path: string; adminOnly?: boolean; } const navItems: NavItem[] = [ { icon: LayoutDashboard, label: 'Painel Principal', path: '/guest-dashboard' }, { icon: FolderOpen, label: 'Obras & Projetos', path: '/' }, { icon: Layers, label: 'Esquemas', path: '/schemes' }, { icon: ClipboardCheck, label: 'Inspeções', path: '/inspections' }, { icon: FolderOpen, label: 'Biblioteca', path: '/library', adminOnly: true }, { icon: Thermometer, label: 'Instrumentos', path: '/instruments' }, { icon: TrendingUp, label: 'Estudo Rend.', path: '/yield-study', adminOnly: true }, { icon: Package, label: 'Estoque', path: '/stock' }, { icon: Wrench, label: 'Calculadora', path: '/calculators' }, ]; const isActive = (path: string) => { if (path === '/' && location.pathname === '/') return true; if (path !== '/' && location.pathname.startsWith(path)) return true; return false; }; return (
{/* Sidebar Desktop - Fixed */} {/* Mobile Header */}
Logo SteelPaint
{/* Mobile Sidebar Overlay */} {isSidebarOpen && (
setIsSidebarOpen(false)} /> )} {/* Mobile Sidebar Drawer */}
Logo SteelPaint
{/* Main Content Area */}
{children}
{/* Floating Help Button */} {/* Technical Manual Modal */} setIsManualOpen(false)} />
); };