import { cookies } from "next/headers"
import { AppSidebar } from "./sidebar"
import {
    SidebarInset,
    SidebarProvider,
} from "@/components/ui/sidebar"
import { redirect } from "next/navigation"

export default async function Layout({ children }: { children: React.ReactNode }) {

    const isLoggedIn = (await cookies()).get('is_logged_in')?.value === 'true'

    console.log(isLoggedIn)

    if (!isLoggedIn) {
        redirect('/login')
    }

    return (
        <SidebarProvider
            style={
                {
                    "--sidebar-width": "calc(var(--spacing) * 72)",
                    "--header-height": "calc(var(--spacing) * 12)",
                } as React.CSSProperties
            }
        >
            <AppSidebar variant="inset" />
            <SidebarInset>
                {children}
            </SidebarInset>
        </SidebarProvider>

    )
}