'use client'; import React, { useState } from 'react'; import Image from 'next/image'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { BarChart3, Target, FolderGit2, Bot, ShieldCheck, Layers, LogOut, UserCheck, CalendarDays, Radio, Megaphone, Share2, Contact, Menu, X, Leaf, BookMarked, } from 'lucide-react'; import TenantSwitcher from '@/components/TenantSwitcher'; import type { DashboardModuleId } from '@/lib/tenant-modules'; import DateRangePicker from '@/components/DateRangePicker'; import { useDateRange } from '@/components/DateRangeContext'; import SyncNowButton from '@/components/SyncNowButton'; type NavItem = { href: string; label: string; icon: React.ComponentType<{ className?: string }>; iconClass: string; moduleId: DashboardModuleId; }; const NAV_ITEMS: NavItem[] = [ { href: '/dashboard/kpis', label: 'Métricas', icon: BarChart3, iconClass: 'text-brand-500', moduleId: 'kpis', }, { href: '/dashboard/crm', label: 'CRM', icon: Contact, iconClass: 'text-teal-500', moduleId: 'crm', }, { href: '/dashboard/seguimiento', label: 'Seguimiento', icon: Radio, iconClass: 'text-sky-500', moduleId: 'seguimiento', }, { href: '/dashboard/estrategia', label: 'Objetivos del Mes', icon: Target, iconClass: 'text-emerald-500', moduleId: 'estrategia', }, { href: '/dashboard/marca', label: 'Zona de marca', icon: BookMarked, iconClass: 'text-rose-500', moduleId: 'marca', }, { href: '/dashboard/ad-tracker', label: 'Ads', icon: Megaphone, iconClass: 'text-violet-500', moduleId: 'ad-tracker', }, { href: '/dashboard/social', label: 'Social', icon: Share2, iconClass: 'text-fuchsia-500', moduleId: 'social', }, { href: '/dashboard/organico', label: 'Orgánico', icon: Leaf, iconClass: 'text-lime-600', moduleId: 'organico', }, { href: '/dashboard/activos', label: 'Biblioteca de Activos', icon: FolderGit2, iconClass: 'text-blue-500', moduleId: 'activos', }, { href: '/dashboard/creatives', label: 'Pipeline creatividades', icon: FolderGit2, iconClass: 'text-orange-500', moduleId: 'creatives', }, { href: '/dashboard/asistente', label: 'Asistente IA Financiero', icon: Bot, iconClass: 'text-purple-500', moduleId: 'asistente', }, ]; function isActive(pathname: string, href: string): boolean { if (pathname === href) return true; if (href !== '/dashboard' && pathname.startsWith(href + '/')) return true; return false; } function NavLink({ item, onNavigate, }: { item: NavItem | (Omit & { moduleId?: string }); onNavigate?: () => void; }) { const pathname = usePathname(); const active = isActive(pathname, item.href); const Icon = item.icon; return ( {item.label} ); } export default function DashboardShell({ children, email, company, role, isAgency, viewName, enabledModules, clientLogoUrl, brandLabel, logoutAction, }: { children: React.ReactNode; email: string; company: string; role: string; isAgency: boolean; viewName?: string; /** null = show all (agency default). */ enabledModules?: Record | null; clientLogoUrl?: string | null; brandLabel?: string; logoutAction: () => void | Promise; }) { const [open, setOpen] = useState(false); const close = () => setOpen(false); const dateRange = useDateRange(); const pathname = usePathname(); const visibleNav = NAV_ITEMS.filter((item) => { if (isAgency) return true; if (!enabledModules) return true; return enabledModules[item.moduleId] !== false; }); const showClientBrand = Boolean(clientLogoUrl); const title = showClientBrand ? brandLabel || company : '4VENTURES'; const subtitle = showClientBrand ? isAgency ? 'Vista cliente' : 'Portal cliente' : 'Centro de Mando'; const sidebar = (
{clientLogoUrl ? ( // eslint-disable-next-line @next/next/no-img-element {title} ) : ( 4Ventures )}

{title}

{subtitle}

{email}

{company} {role}
RLS Activo
); return (
{open ? (
) : null}
{isAgency ? 'Contexto:' : 'Cliente / Portal:'}
{isAgency ? : null}
{children}
); }