import { CompactEmoji, fromUnicodeToHexcode } from 'emojibase';
import joypixels from 'emojibase-data/en/shortcodes/joypixels.json';
import emojibase from 'emojibase-data/en/shortcodes/emojibase.json';

// Light emoji module. Holds the shortcode lookups + types + group enum — the
// only emoji surface the broadly-imported HTML parser (and thus the boot
// graph, via RoomNavItem/SpaceTabs → InviteUserPrompt → react-custom-html-parser)
// actually needs. The heavy `compact.json` dataset (~506 KB) that builds the
// `emojis` / `emojiGroups` arrays for the picker + autocomplete lives in
// `./emoji-data` so it only loads inside the lazy Room/Settings chunks instead
// of the initial bundle. Don't re-import `compact.json` here or the split
// regresses.
export type IEmoji = CompactEmoji & {
  shortcode: string;
};

export enum EmojiGroupId {
  People = 'People',
  Nature = 'Nature',
  Food = 'Food',
  Activity = 'Activity',
  Travel = 'Travel',
  Object = 'Object',
  Symbol = 'Symbol',
  Flag = 'Flag',
}

export type IEmojiGroup = {
  id: EmojiGroupId;
  order: number;
  emojis: IEmoji[];
};

export const getShortcodesFor = (hexcode: string): string[] | string | undefined =>
  joypixels[hexcode] || emojibase[hexcode];

export const getShortcodeFor = (hexcode: string): string | undefined => {
  const shortcode = joypixels[hexcode] || emojibase[hexcode];
  return Array.isArray(shortcode) ? shortcode[0] : shortcode;
};

export const getHexcodeForEmoji = fromUnicodeToHexcode;
