/**
 * Twemoji CDN helpers. The new UI renders unicode emoji via
 * Twemoji 14 SVGs from jsdelivr — no npm package, just an <img>
 * pointed at the CDN.
 */

export function emojiToCodepoint(emoji: string): string {
	const codepoints: string[] = [];
	for (let i = 0; i < emoji.length; i++) {
		const code = emoji.codePointAt(i);
		if (code === undefined) continue;
		if (code === 0xfe0f) continue; // skip variation selector
		codepoints.push(code.toString(16));
		if (code > 0xffff) i++; // skip surrogate pair
	}
	return codepoints.join('-');
}

export function getTwemojiUrl(emoji: string): string {
	return `https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/${emojiToCodepoint(emoji)}.svg`;
}
