import { Link, usePage } from '@inertiajs/react'; import type { ProfileAccess } from '@/types/profile-access'; export function profileLinks(access: ProfileAccess | null | undefined) { if (!access) return []; return [ ...(access.mine ? [{ title: 'Minhas oportunidades', href: access.mine }] : []), ...(access.create ? [{ title: 'Nova oportunidade', href: access.create }] : []), { title: access.mine ? 'Autorizações de Promotor' : 'Solicitar perfil de Promotor', href: access.request, }, ...(!access.mine && access.review ? [{ title: 'Revisão de oportunidades', href: access.review }] : []), ...(access.audit ? [{ title: 'Auditoria de acessos', href: access.audit }] : []), ...(access.technicalSupport ? [ { title: typeof access.technicalSupportUnread === 'number' && Number.isSafeInteger(access.technicalSupportUnread) && access.technicalSupportUnread > 0 ? `Suporte técnico · ${access.technicalSupportUnread} por consultar` : 'Suporte técnico', href: access.technicalSupport, }, ] : []), ...(access.administration ? [{ title: 'Gestão de perfis', href: access.administration }] : []), ...(access.administration ? [ { title: 'Configuração dos perfis', href: '/management/profile-install', }, ] : []), ]; } export default function ProfileNavigation() { const { profileAccess } = usePage<{ profileAccess?: ProfileAccess | null; }>().props; if (!profileAccess) return null; const links = profileLinks(profileAccess); const workHrefs = [ profileAccess.mine, profileAccess.create, profileAccess.review, ].filter(Boolean); const work = links.filter((link) => workHrefs.includes(link.href)); const access = links.filter((link) => !workHrefs.includes(link.href)); return ( ); }