'use client';

import { AuthProvider } from '@/contexts/AuthContext';
import AuthGuard from '@/components/AuthGuard';
import Sidebar from '@/components/admin/Sidebar';
import ToastContainer from '@/components/Toast';
import { usePathname } from 'next/navigation';

export default function AdminLayout({
    children,
}: {
    children: React.ReactNode;
}) {
    const pathname = usePathname();
    const isLogin = pathname === '/admin/login' || pathname === '/admin/login/';

    return (
        <AuthProvider>
            <div className="min-h-screen bg-gray-50 dark:bg-gray-950">
                <ToastContainer />
                {isLogin ? (
                    children
                ) : (
                    <AuthGuard>
                        <Sidebar />
                        {/* Extra top padding on mobile so content clears the
                            fixed hamburger button; the desktop sidebar needs none. */}
                        <main className="lg:pr-64 min-h-screen pt-16 lg:pt-0">
                            {children}
                        </main>
                    </AuthGuard>
                )}
            </div>
        </AuthProvider>
    );
}
