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

import { GiftIcon, SearchIcon } from "@/components/Icons"
import LanguageSwitcher from "@/components/LanguageSwitcher"
import { getIntl } from "@/i18n"

import HeaderLink from "../HeaderLink"

import styles from "./topMenu.module.css"

export default async function TopMenu() {
  // cached
  const intl = await getIntl()
  // both preloaded
  const languages = await getLanguageSwitcher()
  const header = await getHeader()

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

  return (
    <div className={styles.topMenu}>
      <div className={styles.content}>
        {header.data.topLink.link ? (
          <HeaderLink
            className={styles.topLink}
            href={header.data.topLink.link.url}
          >
            <GiftIcon width={20} height={20} color="burgundy" />
            {header.data.topLink.title}
          </HeaderLink>
        ) : null}
        <div className={styles.options}>
          <LanguageSwitcher type="desktopHeader" urls={languages.urls} />
          <HeaderLink href="#">
            <SearchIcon width={20} height={20} color="burgundy" />
            {intl.formatMessage({ id: "Find booking" })}
          </HeaderLink>
        </div>
      </div>
    </div>
  )
}
