import type { ProfileAccess } from '@/types/profile-access'; import { Link, router, usePage } from '@inertiajs/react'; import { LogOut } from 'lucide-react'; import { logout } from '@/routes'; import { useEffect, useId, useRef, useState } from 'react'; import type { OpportunityManagementAccess } from '@/types/opportunity-management'; import { portalNavigation, currentNavigationGroup, currentNavigationItem, type PortalNavItem, } from '@/lib/portal-navigation'; export function PortalGroupedMenu() { const { props, url } = usePage<{ auth: { user: { name?: string; email?: string } | null; canManagePortal: boolean; }; existingBusinessEnabled?: boolean; businessReviewUrl?: string | null; educationEnabled?: boolean; aiEnabled?: boolean; legacyContentEnabled?: boolean; portalOperator?: string | null; profileAccess?: ProfileAccess | null; opportunityManagement?: OpportunityManagementAccess | null; }>(); const groups = portalNavigation({ authenticated: !!props.auth?.user, manager: !!props.auth?.canManagePortal, businesses: props.existingBusinessEnabled, businessReviewUrl: props.businessReviewUrl, education: props.educationEnabled, ai: props.aiEnabled, legacyContent: props.legacyContentEnabled, opportunityManagement: props.opportunityManagement, profileAccess: props.profileAccess, }); const current = currentNavigationGroup(groups, url); const currentItem = currentNavigationItem(groups, url); const [open, setOpen] = useState(null); const [branch, setBranch] = useState(null); const [offset, setOffset] = useState(0); const [loggingOut, setLoggingOut] = useState(false); const root = useRef(null); const id = useId(); useEffect(() => { const position = () => { const button = open ? document.getElementById(`${id}-${open}-button`) : null; if (!button || window.innerWidth < 640) { setOffset(0); return; } const rect = button.getBoundingClientRect(); const width = Math.min(288, window.innerWidth - 32); setOffset( Math.max( 16, Math.min(rect.left, window.innerWidth - width - 16), ) - rect.left, ); }; position(); window.addEventListener('resize', position); return () => window.removeEventListener('resize', position); }, [open, id]); useEffect(() => { const outside = (event: PointerEvent) => { if ( event.target instanceof Node && !root.current?.contains(event.target) ) { setOpen(null); setBranch(null); } }; document.addEventListener('pointerdown', outside); return () => document.removeEventListener('pointerdown', outside); }, []); const close = () => { setOpen(null); setBranch(null); }; const items = (children: PortalNavItem[]) => children.map((item) => (
  • {item.children ? ( <> {branch === item.id && (
      {items(item.children)}
    )} ) : ( {item.label} )}
  • )); return (
    { if (event.key !== 'Escape') return; event.preventDefault(); if (branch) { document.getElementById(`${id}-${branch}-button`)?.focus(); setBranch(null); } else if (open) { document.getElementById(`${id}-${open}-button`)?.focus(); close(); } }} >
    InvesteMoz

    Iniciativa privada e independente de apoio ao investimento. Orientação e acompanhamento internos; decisões oficiais cabem às instituições competentes. {props.portalOperator && ( <> Operador: {props.portalOperator}. )}

    {props.auth?.user && ( )}
    ); }