2026-02-06 19:51:04 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { usePathname } from "next/navigation";
|
|
|
|
|
import { SidebarProvider, SidebarTrigger, SidebarInset } from "@/components/ui/sidebar";
|
|
|
|
|
import { AppSidebar } from "@/components/app-sidebar";
|
|
|
|
|
import { useAuth } from "@/hooks/use-auth";
|
|
|
|
|
import { Loader2 } from "lucide-react";
|
|
|
|
|
|
|
|
|
|
// Rutas públicas que no muestran el sidebar
|
|
|
|
|
const PUBLIC_ROUTES = ["/login"];
|
|
|
|
|
|
|
|
|
|
interface MainLayoutProps {
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function MainLayout({ children }: MainLayoutProps) {
|
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
const { isLoading, isAuthenticated } = useAuth();
|
|
|
|
|
|
|
|
|
|
const isPublicRoute = PUBLIC_ROUTES.includes(pathname);
|
|
|
|
|
|
|
|
|
|
// Mostrar loading mientras se verifica la autenticación
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="min-h-screen flex items-center justify-center bg-background">
|
|
|
|
|
<div className="flex flex-col items-center gap-4">
|
|
|
|
|
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
|
|
|
|
<p className="text-sm text-muted-foreground">Cargando...</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rutas públicas: sin sidebar
|
|
|
|
|
if (isPublicRoute) {
|
|
|
|
|
return <>{children}</>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Si no está autenticado y no es ruta pública, el AuthProvider redirigirá
|
|
|
|
|
// Pero mostramos loading por si acaso
|
|
|
|
|
if (!isAuthenticated) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="min-h-screen flex items-center justify-center bg-background">
|
|
|
|
|
<div className="flex flex-col items-center gap-4">
|
|
|
|
|
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
|
|
|
|
<p className="text-sm text-muted-foreground">Redirigiendo...</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rutas privadas: con sidebar
|
|
|
|
|
return (
|
|
|
|
|
<SidebarProvider>
|
|
|
|
|
<AppSidebar />
|
|
|
|
|
<SidebarInset>
|
|
|
|
|
<main>
|
2026-05-07 15:52:12 +00:00
|
|
|
<div className="header-gradient border-b">
|
|
|
|
|
<div className="flex items-center px-4 py-2">
|
|
|
|
|
<SidebarTrigger />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-06 19:51:04 +00:00
|
|
|
{children}
|
|
|
|
|
</main>
|
|
|
|
|
</SidebarInset>
|
|
|
|
|
</SidebarProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|