import React,{useEffect,useRef} from 'react'; const sections = { human_resources:['human_resources'], commercial:['services','billing','billing_support'], purchasing:['purchasing'], stock:['stock'], workshop:['workshop'], finance:['treasury','receivables','costs'], accounting:['accounting'], }; export function moduleGroups(groups, module) { if(!sections[module])return []; const own=groups.filter(g => sections[module].includes(g.id)); if(['commercial','human_resources'].includes(module))return own; const shared=groups.flatMap(g=>g.items).filter(i=>['clients','services','service_drafts','billing_drafts'].includes(i.id)); return shared.length?[...own,{id:'shared_records',label:'Cadastros e rascunhos do módulo',items:shared}]:own; } export function moduleFunctionAllowed(context,groups,module,id){return Boolean(context?.modules?.some(m=>m.id===module)&&(id==='home'||moduleGroups(groups,module).some(g=>g.items.some(i=>i.id===id))));} export default function ModuleNavigation({groups, context, page, navigate, openPage, user, busy, logout}) { const active=context?.modules?.find(m=>m.id===context.module_id); const menu=useRef(null); useEffect(()=>{const close=e=>{if(!menu.current?.contains(e.target))for(const d of menu.current?.querySelectorAll('details[open]')??[])d.open=false;};window.addEventListener('pointerdown',close);return()=>window.removeEventListener('pointerdown',close);},[]); const choose=(event,module,id)=>{event.currentTarget.closest('details').open=false;openPage(module,id);}; return
{user.name}{context.single_installation&&Trocar função QA}
; }