import { createClient } from "@/lib/supabase/server"
import { redirect } from "next/navigation"
import { AdminTabsWrapper } from "@/components/admin/admin-tabs-wrapper"
import { isAdminUser } from "@/lib/auth/is-admin"

export default async function AdminLayout({
  children,
}: {
  children: React.ReactNode
}) {
  const supabase = await createClient()

  const { data: { user } } = await supabase.auth.getUser()

  if (!user) {
    redirect("/auth/login")
  }

  if (!isAdminUser(user)) {
    redirect("/dashboard")
  }

  return <AdminTabsWrapper>{children}</AdminTabsWrapper>
}
