import type { Language } from "@/i18n/resolver";

const LANGUAGES: readonly Language[] = ["ru", "en", "es", "fr", "it", "ja", "ko", "zh", "de"];
const X_DEFAULT_LANGUAGE: Language = "ru";

export interface HreflangEntry {
  lang: Language | "x-default";
  href: string;
}

/**
 * Builds the full set of reciprocal hreflang links for a given path.
 * Returns 9 language entries + 1 x-default entry (pointing to ru).
 */
export function buildHreflangSet(args: {
  canonicalOrigin: string;
  pathWithoutLocale: string;
}): HreflangEntry[] {
  const { canonicalOrigin, pathWithoutLocale } = args;

  const entries: HreflangEntry[] = LANGUAGES.map((lang) => ({
    lang,
    href: `${canonicalOrigin}/${lang}${pathWithoutLocale}`,
  }));

  entries.push({
    lang: "x-default",
    href: `${canonicalOrigin}/${X_DEFAULT_LANGUAGE}${pathWithoutLocale}`,
  });

  return entries;
}
