import { Link, usePage } from '@inertiajs/react'; import { ChevronDown, LayoutDashboard, Menu, Plus, Search, X, } from 'lucide-react'; import { useEffect, useState } from 'react'; import type { ReactNode } from 'react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, 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 [mobileOpen, setMobileOpen] = useState(false); const [search, setSearch] = useState(''); const [expanded, setExpanded] = useState>({}); const groups = procurementNavigation( user?.purchasing_role ?? '', page.props.payablesAvailable === true, ); 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.label).includes(query), ), })) .filter((group) => group.entries.length); const navigate = () => { setMobileOpen(false); setSearch(''); }; const brand = ( SGC Compras Sistema de Gestão de Compras ); const searchField = (mobile = false) => (
); const navigation = ( ); const sidebarFooter = (

SGC · Espaço de trabalho

Aparência · Página inicial
); return (
Saltar para o conteúdo Menu de Compras Escolhe uma área da aplicação ou procura pelo nome. {brand} {searchField(true)} {navigation} {sidebarFooter}

COMPRAS

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

{searchField()}
{user && ( )}
{children}
); }