import { emojify as nodeEmojify } from "node-emoji";

// Zelfde landvlag-logica als src/lib/remark-flag-emoji.mjs (die geldt alleen
// voor de Markdown-body). Deze helper is voor losse frontmatter-strings
// (hosting, location, for_who, price_from, verdict, title, company, category)
// die niet door de Markdown-verwerking heen gaan.
function toFlagEmoji(countryCode: string): string {
  const codePoints = [...countryCode.toUpperCase()].map(
    (char) => 0x1f1e6 + (char.charCodeAt(0) - 65),
  );
  return String.fromCodePoint(...codePoints);
}

export function emojify(text: string): string {
  const withFlags = text.replace(/:flag_([a-z]{2}):/gi, (_match, cc) => toFlagEmoji(cc));
  return nodeEmojify(withFlags);
}
