"use client" import type React from "react" import { useState } from "react" import { usePathname, useRouter } from "next/navigation" import { useAuth } from "@/lib/auth-context" import { Button } from "@/components/ui/button" import { ScrollArea } from "@/components/ui/scroll-area" import { Avatar, AvatarFallback } from "@/components/ui/avatar" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { LayoutDashboard, Users, CheckCircle, UserCog, Menu, X, Building2, LogOut, ChevronDown, ClipboardList, DollarSign, Tag, } from "lucide-react" import { cn } from "@/lib/utils" import { ModeToggle } from "@/components/mode-toggle" interface DashboardLayoutProps { children: React.ReactNode } export function DashboardLayout({ children }: DashboardLayoutProps) { const { user, logout } = useAuth() const [sidebarOpen, setSidebarOpen] = useState(false) const pathname = usePathname() const router = useRouter() const handleLogout = () => { logout() router.push("/login") } const isAdmin = user?.role === "admin" const navigation = [ { name: "Lista de Precios", href: "/dashboard/precios", icon: DollarSign, show: true, }, { name: "Categorías", href: "/dashboard/categorias", icon: Tag, show: isAdmin, }, { name: "Usuarios", href: "/dashboard/usuarios", icon: UserCog, show: isAdmin, }, ] const visibleNavigation = navigation.filter((item) => item.show) const getInitials = (name: string) => { return name .split(" ") .map((n) => n[0]) .join("") .toUpperCase() .slice(0, 2) } const getPageTitle = () => { const exactMatch = visibleNavigation.find((item) => item.href === pathname) if (exactMatch) return exactMatch.name const partialMatch = visibleNavigation.find( (item) => item.href !== "/dashboard" && pathname.startsWith(item.href) ) if (partialMatch) return partialMatch.name return "Panel de Control" } const SidebarContent = () => ( <>
Mi Cuenta Cerrar Sesión
) return (
{/* Sidebar Desktop */} {/* Sidebar Mobile */} {sidebarOpen && (
setSidebarOpen(false)} />
)} {/* Main Content */}
{/* Header */}

{getPageTitle()}

{user?.name}
{user?.role}
{/* Page Content */}
{children}
) }