import { useState } from 'react'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { useAuth } from '../../context/AuthContext'; export default function MainLayout({ children }) { const [isDropdownOpen, setIsDropdownOpen] = useState(false); const navigate = useNavigate(); const location = useLocation(); const { user, logout, isAuthenticated } = useAuth(); const userInitial = user?.username ? user.username[0].toUpperCase() : "U"; const handleLogout = () => { logout(); setIsDropdownOpen(false); navigate('/login'); }; const isActive = (path) => { return location.pathname === path || (path === '/editor' && location.pathname === '/'); }; return (
{/* HEADER */}
{/* Logo / Título */} Deck of Cards Logo {/* Texto del título */} Deck of Cards {/* Navegación y Usuario */}
{/* LINKS PRINCIPALES */}
Editor {/* Enlace al Historial */} {isAuthenticated && ( Historial )}
{/* SECCIÓN DE USUARIO / LOGIN */} {isAuthenticated ? (
{/* Dropdown Menu (Solo Usuario y Cerrar Sesión) */} {isDropdownOpen && ( <>
setIsDropdownOpen(false)} >

Usuario

{user?.username}

)}
) : ( // BOTONES PARA USUARIO NO LOGUEADO
Entrar Registrarse
)}
{/* CONTENIDO PRINCIPAL */}
{children}
); }