"use client"; import type { RemixiconComponentType } from "@remixicon/react"; import { usePathname } from "next/navigation"; import * as React from "react"; import { SidebarGroup, SidebarGroupContent, SidebarMenu, SidebarMenuButton, SidebarMenuItem, } from "@/components/ui/sidebar"; import Link from "next/link"; export function NavSecondary({ items, ...props }: { items: { title: string; url: string; icon: RemixiconComponentType; }[]; } & React.ComponentPropsWithoutRef) { const pathname = usePathname(); const isLinkActive = React.useCallback( (url: string) => { const normalizedPathname = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname; const normalizedUrl = url.endsWith("/") && url !== "/" ? url.slice(0, -1) : url; // Verifica se é exatamente igual ou se o pathname começa com a URL return ( normalizedPathname === normalizedUrl || normalizedPathname.startsWith(normalizedUrl + "/") ); }, [pathname] ); return ( {items.map((item) => { const itemIsActive = isLinkActive(item.url); return ( {item.title} ); })} ); }