"use client"
import { cx } from "class-variance-authority"
import NextLink from "next/link"

import ScandicLogoIcon from "@scandic-hotels/design-system/Icons/ScandicLogoIcon"

import useDropdownStore from "@/stores/main-menu"

import useLang from "@/hooks/useLang"

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

import { DropdownTypeEnum } from "@/types/components/dropdown/dropdown"

interface LogoLinkProps extends React.HTMLAttributes<HTMLAnchorElement> {
  isInverted?: boolean
}

export function LogoLink({
  isInverted = false,
  "aria-label": ariaLabel,
  ...props
}: LogoLinkProps) {
  const lang = useLang()
  const { toggleDropdown, isHamburgerMenuOpen } = useDropdownStore()

  function handleNavigate() {
    if (isHamburgerMenuOpen) {
      toggleDropdown(DropdownTypeEnum.HamburgerMenu)
    }
  }

  return (
    <NextLink
      className={styles.logoLink}
      href={`/${lang}`}
      onClick={handleNavigate}
      {...props}
    >
      <ScandicLogoIcon
        className={cx(styles.logoIcon, {
          [styles.inverted]: isInverted,
        })}
        width="103px"
        height="22px"
        // eslint-disable-next-line formatjs/no-literal-string-in-jsx
        aria-label="Scandic"
      />
    </NextLink>
  )
}
