import { getHeader, getLanguageSwitcher } from "@/lib/trpc/memoizedRequests"

import { auth } from "@/auth"
import { isValidSession } from "@/utils/session"

import MobileMenu from "../MobileMenu"

export default async function MobileMenuWrapper({
  children,
}: React.PropsWithChildren) {
  // preloaded
  const languages = await getLanguageSwitcher()
  const header = await getHeader()
  const session = await auth()

  if (!languages || !header) {
    return null
  }

  return (
    <MobileMenu
      languageUrls={languages.urls}
      topLink={header.data.topLink}
      isLoggedIn={isValidSession(session)}
    >
      {children}
    </MobileMenu>
  )
}
