---
import { languages } from '../i18n/ui';

// Get the current URL path
const { pathname } = Astro.url;

// Function to get the current language and generate the URL for a different language
function getTargetPath(targetLang) {
  // Check if the current path starts with a language code, if so, replace it
  const langPathRegex = /^\/(en|nl)\//;
  const matches = pathname.match(langPathRegex);
  
  if (matches) {
    return pathname.replace(langPathRegex, `/${targetLang}/`);
  }
  
  // If no language code in the path, assume we're at the root
  // and add the target language code
  return `/${targetLang}/`;
}
---

<div class="flex items-center space-x-2">
  {Object.entries(languages).map(([lang, label]) => (
    <a
      href={getTargetPath(lang)}
      class={`text-sm px-2 py-1 rounded ${pathname.includes(`/${lang}/`) || (pathname === '/' && lang === 'en') 
        ? 'bg-accent-blue/20 text-silver-metallic font-medium' 
        : 'text-silver-light/70 hover:text-silver-metallic'}`}
    >
      {label}
    </a>
  ))}
</div> 