import { Link, usePage } from "@inertiajs/react"; import { ChevronDown, Menu, X } from "lucide-react"; import { useState } from "react"; import logo from "&/images/global/logo-qualimaine-RVB-defaut.png"; import useTrans from "@/hooks/use-translations"; import { GetTranslation } from "@/lib/utils"; interface NavLinkResolved { label: string; href: string; resolvedHref: string; } const NAV_LINKS = [ { label: "front.menus.about_us", href: "front.whoAreWeSection.slug" }, { label: "front.menus.engagements", href: "front.engagements.slug" }, { label: "front.menus.normes", href: "norms.slug" }, { label: "front.menus.contact", href: "footer.contactSlug" }, ]; function useSectionHref(slugKey: string) { const { url, props } = usePage() as unknown as { url: string; props: { appEnv: { locales: string[] } }; }; const slug = useTrans(slugKey); const isHome = url === "/" || props.appEnv.locales.some((locale) => url === `/${locale}`); if (isHome) return `#${slug}`; return `${route("front.homepage")}#${slug}`; } function LanguageDropdown() { const { appEnv, localizedUrls } = usePage().props as unknown as { appEnv: { locale: string; locales: string[] }; localizedUrls: Record; }; const [open, setOpen] = useState(false); const otherLocales = appEnv.locales.filter( (locale) => locale !== appEnv.locale, ); return (
{open && (
{otherLocales.map((locale) => ( {locale.toUpperCase()} ))}
)}
); } export default function Navbar() { const [mobileOpen, setMobileOpen] = useState(false); const navLinks: NavLinkResolved[] = [ { ...NAV_LINKS[0], resolvedHref: useSectionHref(NAV_LINKS[0].href) }, { ...NAV_LINKS[1], resolvedHref: useSectionHref(NAV_LINKS[1].href) }, { ...NAV_LINKS[2], resolvedHref: useSectionHref(NAV_LINKS[2].href) }, { ...NAV_LINKS[3], resolvedHref: useSectionHref(NAV_LINKS[3].href) }, ]; return (
{useTrans("front.logo_alt")}
{mobileOpen && (
{ setMobileOpen(false); }} > {GetTranslation("front.logo_alt")}
)}
); }