import { Link, usePage } from '@inertiajs/react'; import { ChevronDown, LayoutDashboard, Menu, Plus, Search, X, } from 'lucide-react'; import { Fragment, useEffect, useState } from 'react'; import type { ReactNode } from 'react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, } from '@/components/ui/sheet'; import { UserMenuContent } from '@/components/user-menu-content'; import { activeProcurementEntry, procurementNavigation, } from '@/lib/procurement-navigation'; import { roleLabels } from '@/types/procurement'; export function SgcWorkspaceShell({ children }: { children: ReactNode }) { const page = usePage(); const user = page.props.auth?.user; const publicNavigation = page.props.publicNavigation as | { paths: string[] } | undefined; const [mobileOpen, setMobileOpen] = useState(false); const [search, setSearch] = useState(''); const [expanded, setExpanded] = useState>({}); const access = page.props.organizationAccess as { active: boolean; permissions: string[]; } | null; const groups = procurementNavigation( access?.active ? access.permissions : (user?.purchasing_role ?? ''), page.props.payablesAvailable === true, publicNavigation?.paths, ); const activeId = activeProcurementEntry(groups, page.url); const activeGroup = groups.find((group) => group.entries.some((entry) => entry.id === activeId), ); const activeGroupId = activeGroup?.id; useEffect(() => { if (activeGroupId) setExpanded((previous) => previous[activeGroupId] ? previous : { ...previous, [activeGroupId]: true }, ); }, [activeId, activeGroupId]); const normalize = (text: string) => text .normalize('NFD') .replace(/[\u0300-\u036f]/g, '') .toLocaleLowerCase('pt'); const query = normalize(search.trim()); const visibleGroups = groups .map((group) => ({ ...group, entries: group.entries.filter( (entry) => !query || normalize( group.label + ' ' + (entry.section ?? '') + ' ' + entry.label, ).includes(query), ), })) .filter((group) => group.entries.length); const navigate = () => { setMobileOpen(false); setSearch(''); }; const brand = ( SGC SGC Sistema de Gestão de Contratações ); const searchField = (mobile = false) => (
); const navigation = ( ); const sidebarFooter = (

SGC · Espaço de trabalho

Aparência · Página inicial
); return (
{publicNavigation && (

Consulta pública de desenvolvimento · Sem organização seleccionada e sem registos privados. Alterações exigem autenticação.

)} Saltar para o conteúdo Menu do SGC Escolhe uma área da aplicação ou procura pelo nome. {brand} {searchField(true)} {navigation} {sidebarFooter}
{brand}

COMPRAS

{page.url.split('?')[0] === '/dashboard' ? 'Painel inicial' : (activeGroup?.label ?? 'Espaço de trabalho')}

{searchField()}
{page.props.canRequest === true && ( )} {user && ( )}
{children}
); }