'use client'; import React, { useState, useEffect } from 'react'; import { usePathname } from 'next/navigation'; import Link from 'next/link'; import { MagnifyingGlassIcon, ChevronRightIcon, HomeIcon, BellIcon, Cog6ToothIcon } from '@heroicons/react/24/outline'; import CommandPalette from '@/components/ui/CommandPalette'; import { getUser } from '@/lib/auth'; import { CRMCustomerFilter } from '@/components/crm/CRMCustomerFilter'; export const TopBar: React.FC = () => { const pathname = usePathname(); const [isCommandPaletteOpen, setIsCommandPaletteOpen] = useState(false); const [user, setUser] = useState(null); // Verifica se está em uma rota do CRM const isInCRM = pathname?.startsWith('/crm') || false; useEffect(() => { const userData = getUser(); setUser(userData); }, []); const generateBreadcrumbs = () => { const paths = pathname?.split('/').filter(Boolean) || []; const isCustomer = pathname?.startsWith('/cliente'); const homePath = isCustomer ? '/cliente/dashboard' : '/dashboard'; const breadcrumbs: Array<{ name: string; href: string; icon?: React.ComponentType<{ className?: string }> }> = [ { name: 'Home', href: homePath, icon: HomeIcon } ]; let currentPath = ''; paths.forEach((path, index) => { currentPath += `/${path}`; // Mapeamento de nomes amigáveis const nameMap: Record = { 'dashboard': 'Dashboard', 'clientes': 'Clientes', 'projetos': 'Projetos', 'financeiro': 'Financeiro', 'configuracoes': 'Configurações', 'novo': 'Novo', 'cliente': 'Portal', 'leads': 'Leads', 'listas': 'Listas', }; if (path !== 'dashboard' && !(isCustomer && path === 'cliente')) { // Evita duplicar Home/Dashboard ou Portal breadcrumbs.push({ name: nameMap[path] || path.charAt(0).toUpperCase() + path.slice(1), href: currentPath, }); } }); return breadcrumbs; }; const breadcrumbs = generateBreadcrumbs(); const isCustomer = pathname?.startsWith('/cliente'); const homePath = isCustomer ? '/cliente/dashboard' : '/dashboard'; return ( <>
{/* Logo Mobile */}
{user?.logoUrl ? ( {user?.company ) : ( (user?.company?.charAt(0)?.toUpperCase() || 'A') )}
{/* Breadcrumbs Desktop */} {/* CRM Customer Filter - aparece apenas em rotas CRM */} {isInCRM && (
)} {/* Search Bar Trigger */}
{/* Command Palette */} ); };