'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 />
                        <main className="lg:pr-64 min-h-screen">
                            {children}
                        </main>
                    </AuthGuard>
                )}
            </div>
        </AuthProvider>
    );
}
