"use client" import { usePathname } from "next/navigation" import { Dialog, DialogTrigger, Modal, ModalOverlay, Popover, } from "react-aria-components" import { useIntl } from "react-intl" import { type Lang, languages, type LanguageSwitcherData, } from "@scandic-hotels/common/constants/language" import { Button } from "@scandic-hotels/design-system/Button" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import Link from "@scandic-hotels/design-system/Link" import { Typography } from "@scandic-hotels/design-system/Typography" import { languageSwitcherVariants } from "./variants" import styles from "./languageSwitcher.module.css" type LanguageSwitcherProps = { currentLanguage: Lang isMobile?: boolean type?: "footer" | "header" } export function replaceUrlPart(currentPath: string, newPart: string): string { const pathSegments = currentPath.split("/").filter((segment) => segment) const newPathSegments = newPart .replace(/\/$/, "") .split("/") .filter((segment) => segment) const isFullPathReplacement = newPathSegments.length > 1 if (isFullPathReplacement) { return `/${newPathSegments.join("/")}` } const updatedPathSegments = pathSegments.slice(1) const updatedPath = `/${newPathSegments.concat(updatedPathSegments).join("/")}` return updatedPath } export function LanguageSwitcher({ currentLanguage, isMobile = false, type = "header", }: LanguageSwitcherProps) { const classNames = languageSwitcherVariants({ position: type }) const isFooter = type === "footer" return (