import { useEffect, useMemo, useState } from 'react' import { ROLE_LABELS, ROLE_NAV_ITEMS } from '../config/permissions.js' import { profileRepository } from '../repositories/profileRepository.js' import { BrandLogo } from './Brand.jsx' // Todos os itens de navegação com seus ícones e metadados const ALL_NAV_ITEMS = [ { href: '/inicio', label: 'Painel', icon: 'pulse', activePaths: ['/inicio', '/home', '/dashboard'] }, { href: '/agenda', label: 'Agenda', icon: 'calendar' }, { href: '/pacientes', label: 'Pacientes', icon: 'users', exact: true }, { href: '/prontuario', label: 'Prontuário', icon: 'file' }, { href: '/laudos', label: 'Relatórios médicos', icon: 'clipboard' }, { href: '/camunicacao', label: 'Comunicação', icon: 'message', activePaths: ['/camunicacao', '/comunicacao', '/mensagens'], }, { href: '/relatorios', label: 'Relatórios', icon: 'chart' }, { href: '/profissionais', label: 'Profissionais', icon: 'users' }, { href: '/usuarios', label: 'Usuários', icon: 'shield' }, { href: '/configuracoes', label: 'Configurações', icon: 'settings', activePaths: ['/configuracoes', '/config'] }, ] const titles = { '/inicio': 'Painel', '/home': 'Painel', '/dashboard': 'Painel', '/agenda': 'Agenda', '/consultas': 'Consultas', '/laudos': 'Relatórios médicos', '/pacientes': 'Pacientes', '/prontuario': 'Prontuário', '/camunicacao': 'Comunicação', '/comunicacao': 'Comunicação', '/mensagens': 'Comunicação', '/relatorios': 'Relatórios', '/profissionais': 'Profissionais', '/perfil': 'Perfil', '/configuracoes': 'Configurações', '/config': 'Configurações', '/usuarios': 'Usuários', } export function AppShell({ children, currentPath, navigate, role, routeTitle }) { const [menuOpen, setMenuOpen] = useState(false) const [quickSearch, setQuickSearch] = useState('') const [viewerProfile, setViewerProfile] = useState({ name: 'Usuário', role: 'Usuário do Sistema' }) const pageTitle = useMemo(() => { if (currentPath.startsWith('/pacientes/') && routeTitle) { return routeTitle } return routeTitle || titles[currentPath] || 'MediConnect' }, [currentPath, routeTitle]) // Filtra os itens de navegação com base no role do usuário const navItems = useMemo(() => { if (!role) return [] const allowedPaths = ROLE_NAV_ITEMS[role]?.map((item) => item.path) ?? [] return ALL_NAV_ITEMS.filter((item) => allowedPaths.some( (allowed) => item.href === allowed || item.activePaths?.includes(allowed), ), ) }, [role]) useEffect(() => { let active = true profileRepository .getCurrentUserProfile() .then((profile) => { if (!active || !profile) return setViewerProfile({ name: profile.name || 'Usuário', role: ROLE_LABELS[role] || profile.role || 'Usuário do Sistema', }) }) .catch(() => { // Fallback: usa o label do role diretamente if (active && role) { setViewerProfile((prev) => ({ ...prev, role: ROLE_LABELS[role] || 'Usuário do Sistema', })) } }) return () => { active = false } }, [role]) function goTo(path) { setMenuOpen(false) navigate(path) } return (
Pular para conteúdo {menuOpen ? (
setQuickSearch(event.target.value)} placeholder="Buscar paciente, prontuário..." value={quickSearch} />
{quickSearch ? (
Busca local ativa por {quickSearch}.
) : null}
{pageTitle}
{children}
) } function NavItem({ active, item, onNavigate }) { return ( { event.preventDefault() onNavigate(item.href) }} > {item.label} ) } function isActive(pathname, item) { if (item.activePaths?.some((path) => pathname === path || pathname.startsWith(`${path}/`))) { return true } if (item.activePrefixes?.some((path) => pathname.startsWith(path))) { return true } if (item.exact) { return pathname === item.href } return pathname === item.href || pathname.startsWith(`${item.href}/`) } function AppIcon({ className = 'size-5', name }) { const common = { className, fill: 'none', stroke: 'currentColor', strokeLinecap: 'round', strokeLinejoin: 'round', strokeWidth: 1.8, viewBox: '0 0 24 24', } if (name === 'calendar') { return ( ) } if (name === 'users') { return ( ) } if (name === 'file') { return ( ) } if (name === 'clipboard') { return ( ) } if (name === 'message') { return ( ) } if (name === 'chart') { return ( ) } if (name === 'shield') { return ( ) } if (name === 'settings') { return ( ) } return ( ) } function BellIcon({ className = 'size-5' }) { return ( ) } function ChevronDownIcon({ className = 'size-4' }) { return ( ) } function SearchIcon({ className = 'size-4' }) { return ( ) } function getInitials(name) { return String(name || 'US') .split(' ') .filter(Boolean) .slice(0, 2) .map((part) => part[0]) .join('') .toUpperCase() }