'use client' import React, { useState, useRef, useEffect } from 'react' import { ArrowRight, Globe, ChevronDown } from 'lucide-react' import { usePathname } from 'next/navigation' export interface NavItem { id?: string label: string href: string } interface HeaderProps { companyName?: string | null tagline?: string | null items?: NavItem[] phone?: string | null homeHref?: string currentLocale?: string contactHref?: string | null contactLabel?: string | null phoneLabel?: string | null } export function Header({ companyName, tagline, items, phone, homeHref = '/', currentLocale = 'pl', contactHref, contactLabel, phoneLabel, }: HeaderProps) { const pathname = usePathname() || '' const [langDropdownOpen, setLangDropdownOpen] = useState(false) const dropdownRef = useRef(null) // Close dropdown on outside click useEffect(() => { function handleClickOutside(event: MouseEvent) { if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { setLangDropdownOpen(false) } } document.addEventListener('mousedown', handleClickOutside) return () => document.removeEventListener('mousedown', handleClickOutside) }, []) // Function to switch locale in URL const getSwitchedLocalePath = (targetLocale: string) => { if (currentLocale === targetLocale) return pathname if (pathname.startsWith(`/${currentLocale}`)) { return pathname.replace(`/${currentLocale}`, `/${targetLocale}`) } return `/${targetLocale}${pathname}` } // Filter out duplicated "Kontakt" from menu items since it has a dedicated right CTA button const filteredNavItems = items?.filter( (item) => !item.label.toLowerCase().includes('kontakt') ) const languages = [ { code: 'pl', label: 'PL' }, { code: 'en', label: 'UK' }, ] const activeLang = languages.find((l) => l.code === currentLocale) || languages[0] return (
{/* Top Black Utility Bar */} {(tagline || phone) && (
{tagline && (
{tagline}
)} {phone && (
{phoneLabel && ( {phoneLabel} )} {phone}
)}
)} {/* Main Navigation Bar */}
POI
{companyName && ( {companyName} )} {tagline && ( {tagline} )}
{/* Navigation Items */} {filteredNavItems && filteredNavItems.length > 0 && ( )}
{/* Wysuwany przełącznik języków */}
{langDropdownOpen && ( )}
{/* Right CTA Button */} {contactHref && contactLabel && ( {contactLabel} )}
) }