import { redirect } from "next/navigation";

import { auth } from "@/src/auth";
import SignOutButton from "@/src/components/auth/SignOutButton";
import Navbar from "@/src/components/Navbar";
import { StabilimentoProvider } from "@/src/contexts/StabilimentoContext";

export default async function MainLayout({
    children,

}: {
    children: React.ReactNode;
}) {
    const session = await auth();

    if (!session?.user) {
        redirect("/login");
    }

    return (
        <StabilimentoProvider>
            <div>
                <Navbar actions={<SignOutButton />} />
                <main>{children}</main>
            </div>
        </StabilimentoProvider>
    );
}
