import { redirect } from 'next/navigation'
import { cookies } from 'next/headers'
import { getIronSession } from 'iron-session'
import { SessionData, sessionOptions } from '@/lib/session'
import { NavBar } from '@/components/shared/nav-bar'

export default async function AppLayout({ children }: { children: React.ReactNode }) {
  const session = await getIronSession<SessionData>(await cookies(), sessionOptions)

  if (!session.userId) {
    redirect('/login')
  }

  return (
    <div className="min-h-screen bg-background flex flex-col">
      <NavBar isDemo={session.isDemo} />
      <main className="flex-1 flex flex-col">
        {children}
      </main>
    </div>
  )
}
