import { serverClient } from "@/lib/trpc/server"

import NavigationMenuList from "./NavigationMenuList"

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

export default async function NavigationMenu({
  isMobile,
}: NavigationMenuProps) {
  const headerData = await serverClient().contentstack.base.header()

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

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

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