import { useIntl } from "react-intl"

import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"

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

import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"

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

import { DropdownTypeEnum } from "@/types/components/dropdown/dropdown"
import {
  type LanguageSwitcherContainerProps,
  LanguageSwitcherTypesEnum,
} from "@/types/components/languageSwitcher/languageSwitcher"

export default function LanguageSwitcherContainer({
  children,
  type,
}: LanguageSwitcherContainerProps) {
  const { toggleDropdown } = useDropdownStore()
  const intl = useIntl()
  const isFooter = type === LanguageSwitcherTypesEnum.Footer
  const isMobileHeader = type === LanguageSwitcherTypesEnum.MobileHeader
  const position = isFooter
    ? DropdownTypeEnum.FooterLanguageSwitcher
    : DropdownTypeEnum.HamburgerMenu

  return (
    <div>
      {isMobileHeader ? (
        <div className={styles.backWrapper}>
          <button
            type="button"
            className={styles.backButton}
            onClick={() => toggleDropdown(position)}
          >
            <MaterialIcon
              icon="chevron_left"
              color="Icon/Interactive/Accent"
              size={20}
            />
            <Subtitle type="one" asChild>
              <span>
                {intl.formatMessage({
                  defaultMessage: "Main menu",
                })}
              </span>
            </Subtitle>
          </button>
        </div>
      ) : null}
      {isFooter ? (
        <div className={styles.closeWrapper}>
          <button
            type="button"
            className={styles.closeButton}
            aria-label={intl.formatMessage({
              defaultMessage: "Close menu",
            })}
            onClick={() => toggleDropdown(position)}
          >
            <span className={styles.bar} />
          </button>
        </div>
      ) : null}
      {children}
    </div>
  )
}
