import { redirect } from 'next/navigation'
import { createClient } from '@/lib/supabase/server'
import { getUserSession } from '@/lib/auth/permissions'
import { isAtLeastRole } from '@/lib/auth/permissions-shared'
import AppShell from '@/components/layout/app-shell'
import AppHeader from '@/components/layout/app-header'
import PlanningNav from '@/components/planning/planning-nav'

export default async function KalenderLayout({ children }: { children: React.ReactNode }) {
  const supabase = await createClient()
  const { data: claimsData } = await supabase.auth.getClaims()
  if (!claimsData?.claims) redirect('/login')


 const session = await getUserSession()
 const isAdmin = session ? isAtLeastRole(session,'admin') : false

 return (
 <AppShell>
 {/* tdd-guard:skip — layout only composes other components.
 h-dvh wrapper constrains the kalender layout to viewport height so the
 inner overflow-auto grid container is the only thing that scrolls. */}
 <div className="h-dvh flex flex-col overflow-hidden">
 <AppHeader title="Einsatzplanung"/>
 <PlanningNav isAdmin={isAdmin} />
 <div className="flex-1 min-h-0 flex flex-col overflow-hidden">
 {children}
 </div>
 </div>
 </AppShell>
 )
}
