"use client" import { usePathname } from "next/navigation" import { useCallback, useEffect, useState, useRef } from "react" import classNames from "clsx" import type { Locale as LocaleType, CookiesStore } from "@/utils/constants" import { LOCALES } from "@/utils/constants" import { Arrow } from "./Arrow" import { LocaleFlag } from "./LocaleFlag" export interface LocalesProps { currentLocale: string cookiesStore: CookiesStore } export const Locales = (props: LocalesProps): JSX.Element => { const { currentLocale, cookiesStore } = props const pathname = usePathname() const [hiddenMenu, setHiddenMenu] = useState(true) const languageClickRef = useRef(null) const handleHiddenMenu = useCallback(() => { setHiddenMenu((oldHiddenMenu) => { return !oldHiddenMenu }) }, []) useEffect(() => { const handleClickEvent = (event: MouseEvent): void => { if (languageClickRef.current == null || event.target == null) { return } if (!languageClickRef.current.contains(event.target as Node)) { setHiddenMenu(true) } } window.document.addEventListener("click", handleClickEvent) return () => { return window.removeEventListener("click", handleClickEvent) } }, []) const handleLocale = async (locale: LocaleType): Promise => { const { setLocale } = await import("@/i18n/i18n.server") setLocale(locale) } if (pathname.startsWith("/blog")) { return <> } return (
    {LOCALES.filter((locale) => { return locale !== currentLocale }).map((locale) => { return (
  • { return await handleLocale(locale) }} >
  • ) })}
) }