"use client";

import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useSession } from "next-auth/react";
import Sidebar from "@/components/Sidebar";

export default function AuthLayout({ children }: { children: React.ReactNode }) {
    const { status } = useSession();
    const router = useRouter();

    useEffect(() => {
        if (status === "unauthenticated") {
            router.push("/");
        }
    }, [status, router]);

    if (status === "loading") {
        return (
            <div className="min-h-screen bg-[#0a0d0f] flex items-center justify-center">
                <span className="text-[#4aff8c]/40 font-mono text-xs tracking-widest animate-pulse">
                    CHARGEMENT...
                </span>
            </div>
        );
    }

    if (status !== "authenticated") return null;

    return (
        <div className="flex min-h-screen">
            <Sidebar />
            <main className="ml-56 flex-1 p-8">
                {children}
            </main>
        </div>
    );
}