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

import { GiftIcon, SearchIcon } from "@/components/Icons"
import LanguageSwitcher from "@/components/LanguageSwitcher"
import Link from "@/components/TempDesignSystem/Link"
import Caption from "@/components/TempDesignSystem/Text/Caption"
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 ? (
          <Caption type="regular" color="textMediumContrast" asChild>
            <Link
              href={header.data.topLink.link.url}
              color="peach80"
              variant="icon"
            >
              <GiftIcon width={20} height={20} />
              {header.data.topLink.title}
            </Link>
          </Caption>
        ) : null}
        <div className={styles.options}>
          <LanguageSwitcher type="desktopHeader" urls={languages.urls} />

          <Caption type="regular" color="textMediumContrast" asChild>
            <Link href="#" color="peach80" variant="icon">
              <SearchIcon width={20} height={20} />
              {intl.formatMessage({ id: "Find booking" })}
            </Link>
          </Caption>
          <HeaderLink href="#"></HeaderLink>
        </div>
      </div>
    </div>
  )
}
