---
import type { Locale } from '../i18n';
import { locales, t } from '../i18n';

interface Props {
  current: Locale;
}

const { current } = Astro.props;

const pathname = Astro.url.pathname;
const prefix = `/${current}`;
const rest = pathname.startsWith(prefix)
  ? pathname.slice(prefix.length) || '/'
  : pathname;

const labelFor: Record<Locale, string> = {
  en: 'EN',
  sl: 'SI',
};
---

<nav class="lang-switch" aria-label={t(current).switcher.label}>
  {
    locales.map((loc) => {
      const href = `/${loc}${rest.startsWith('/') ? rest : `/${rest}`}`;
      return (
        <a href={href} class={loc === current ? 'active' : ''} lang={loc} hreflang={loc}>
          {labelFor[loc]}
        </a>
      );
    })
  }
</nav>
