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

import NavigationMenuList from "./NavigationMenuList"

import type { NavigationMenuProps } from "@/types/components/header/navigationMenu"

export default async function NavigationMenu({
  isMobile,
}: NavigationMenuProps) {
  const header = await getHeader()

  if (!header) {
    return null
  }

  const filteredItems = header.data.menuItems.filter(
    ({ link, submenu }) => submenu.length || link
  )

  if (!filteredItems?.length) {
    return null
  }

  return <NavigationMenuList isMobile={isMobile} items={filteredItems} />
}
