"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import { locales, switchLocalePath, type Locale } from "@alterra/shared";

/** EN / ES links that keep the visitor on the same page in the other language. */
export default function LanguageSwitch({ lang, label, className = "" }: { lang: Locale; label: string; className?: string }) {
  const pathname = usePathname();
  return (
    <nav aria-label={label} className={`flex items-center gap-1 text-[0.68rem] font-semibold tracking-[0.18em] ${className}`}>
      {locales.map((l, i) => (
        <span key={l} className="flex items-center gap-1">
          {i > 0 && <span className="opacity-30">/</span>}
          {l === lang ? (
            <span aria-current="true" className="px-0.5 py-1 text-gold-light">
              {l.toUpperCase()}
            </span>
          ) : (
            <Link href={switchLocalePath(pathname, l)} hrefLang={l} lang={l} className="px-0.5 py-1 opacity-60 transition hover:opacity-100">
              {l.toUpperCase()}
            </Link>
          )}
        </span>
      ))}
    </nav>
  );
}
