'use client' import Link from 'next/link' import { usePathname, useSearchParams, useRouter } from 'next/navigation' import { cn } from '@/lib/utils' import { Lightbulb, Bell, Archive, Trash2, Plus, Sparkles, X, Tag, } from 'lucide-react' import { Button } from '@/components/ui/button' import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from '@/components/ui/tooltip' import { useLanguage } from '@/lib/i18n' import { NotebooksList } from './notebooks-list' import { useHomeViewOptional } from '@/context/home-view-context' import { useEffect, useState } from 'react' import { getTrashCount } from '@/app/actions/notes' const HIDDEN_ROUTES = ['/agents', '/chat', '/lab'] export function Sidebar({ className, user }: { className?: string, user?: any }) { const pathname = usePathname() const searchParams = useSearchParams() const router = useRouter() const { t } = useLanguage() const homeBridge = useHomeViewOptional() const [trashCount, setTrashCount] = useState(0) // Fetch trash count useEffect(() => { getTrashCount().then(setTrashCount) }, [pathname, searchParams]) // Hide sidebar on Agents, Chat IA and Lab routes if (HIDDEN_ROUTES.some(r => pathname.startsWith(r))) return null // Active label filter const activeLabel = searchParams.get('label') const activeLabels = searchParams.get('labels')?.split(',').filter(Boolean) || [] const clearLabelFilter = () => { const params = new URLSearchParams(searchParams) params.delete('label') router.push(`/?${params.toString()}`) } const clearLabelsFilter = (labelToRemove?: string) => { const params = new URLSearchParams(searchParams) if (labelToRemove) { const remaining = activeLabels.filter(l => l !== labelToRemove) if (remaining.length > 0) { params.set('labels', remaining.join(',')) } else { params.delete('labels') } } else { params.delete('labels') } router.push(`/?${params.toString()}`) } // Helper to determine if a link is active const isActive = (href: string, exact = false) => { if (href === '/') { // Home is active only if no special filters are applied return pathname === '/' && !searchParams.get('label') && !searchParams.get('archived') && !searchParams.get('trashed') } // For labels if (href.startsWith('/?label=')) { const labelParam = searchParams.get('label') // Extract label from href const labelFromHref = href.split('=')[1] return labelParam === labelFromHref } // For other routes return pathname === href } const NavItem = ({ href, icon: Icon, label, active, badge }: any) => ( {label} {badge > 0 && ( {badge} )} ) return ( ) }