const emojiAssetModules = import.meta.glob('../assets/emoji/*.png', {
  eager: true,
  import: 'default',
}) as Record<string, string>;
const emojiPluginAssetModules = import.meta.glob(
  '../assets/emoji-plugin/*.png',
  {
    eager: true,
    import: 'default',
  },
) as Record<string, string>;

type EmojiMapping = Record<string, string>;

const createEmojiAssetUrlMap = (modules: EmojiMapping) =>
  Object.fromEntries(
    Object.entries(modules).map(([path, url]) => [path.split('/').pop()!, url]),
  ) as EmojiMapping;

const getEmojiFileName = (index: number) => `emoji_${index}@2x.png`;

const buildSequentialFileNameMap = (names: string[]) =>
  Object.fromEntries(
    names.map((name, index) => [name, getEmojiFileName(index)]),
  ) as EmojiMapping;

const buildEmojiSrcMap = (mapping: EmojiMapping, assetUrlMap: EmojiMapping) =>
  Object.fromEntries(
    Object.entries(mapping)
      .filter(([, fileName]) => Boolean(assetUrlMap[fileName]))
      .map(([key, fileName]) => [key, assetUrlMap[fileName]]),
  ) as EmojiMapping;

const emojiAssetUrlMap = createEmojiAssetUrlMap(emojiAssetModules);
const emojiPluginAssetUrlMap = createEmojiAssetUrlMap(emojiPluginAssetModules);

const emojiFileOrderNames: Array<string> = [
  '[NO]',
  '[OK]',
  '[下雨]',
  '[么么哒]',
  '[乒乓]',
  '[便便]',
  '[信封]',
  '[偷笑]',
  '[傲慢]',
  '[再见]',
  '[冷汗]',
  '[凋谢]',
  '[刀]',
  '[删除]',
  '[勾引]',
  '[发呆]',
  '[发抖]',
  '[可怜]',
  '[可爱]',
  '[右哼哼]',
  '[右太极]',
  '[右车头]',
  '[吐]',
  '[吓]',
  '[咒骂]',
  '[咖啡]',
  '[啤酒]',
  '[嘘]',
  '[回头]',
  '[困]',
  '[坏笑]',
  '[多云]',
  '[大兵]',
  '[大哭]',
  '[太阳]',
  '[奋斗]',
  '[奶瓶]',
  '[委屈]',
  '[害羞]',
  '[尴尬]',
  '[左哼哼]',
  '[左太极]',
  '[左车头]',
  '[差劲]',
  '[弱]',
  '[强]',
  '[彩带]',
  '[彩球]',
  '[得意]',
  '[微笑]',
  '[心碎了]',
  '[快哭了]',
  '[怄火]',
  '[怒]',
  '[惊恐]',
  '[惊讶]',
  '[憨笑]',
  '[手枪]',
  '[打哈欠]',
  '[抓狂]',
  '[折磨]',
  '[抠鼻]',
  '[抱抱]',
  '[抱拳]',
  '[拳头]',
  '[挥手]',
  '[握手]',
  '[撇嘴]',
  '[擦汗]',
  '[敲打]',
  '[晕]',
  '[月亮]',
  '[棒棒糖]',
  '[汽车]',
  '[沙发]',
  '[流汗]',
  '[流泪]',
  '[激动]',
  '[灯泡]',
  '[炸弹]',
  '[熊猫]',
  '[爆筋]',
  '[爱你]',
  '[爱心]',
  '[爱情]',
  '[猪头]',
  '[猫咪]',
  '[献吻]',
  '[玫瑰]',
  '[瓢虫]',
  '[疑问]',
  '[白眼]',
  '[皮球]',
  '[睡觉]',
  '[磕头]',
  '[示爱]',
  '[礼品袋]',
  '[礼物]',
  '[篮球]',
  '[米饭]',
  '[糗大了]',
  '[红双喜]',
  '[红灯笼]',
  '[纸巾]',
  '[胜利]',
  '[色]',
  '[药]',
  '[菜刀]',
  '[蛋糕]',
  '[蜡烛]',
  '[街舞]',
  '[衰]',
  '[西瓜]',
  '[调皮]',
  '[象棋]',
  '[跳绳]',
  '[跳跳]',
  '[车厢]',
  '[转圈]',
  '[鄙视]',
  '[酷]',
  '[钞票]',
  '[钻戒]',
  '[闪电]',
  '[闭嘴]',
  '[闹钟]',
  '[阴险]',
  '[难过]',
  '[雨伞]',
  '[青蛙]',
  '[面条]',
  '[鞭炮]',
  '[风车]',
  '[飞吻]',
  '[飞机]',
  '[饥饿]',
  '[香蕉]',
  '[骷髅]',
  '[麦克风]',
  '[麻将]',
  '[鼓掌]',
  '[龇牙]',
];

export const emojiMap: { [key: string]: string } =
  buildSequentialFileNameMap(emojiFileOrderNames);
export const emojiName: Array<string> = [
  '[龇牙]',
  '[调皮]',
  '[流汗]',
  '[偷笑]',
  '[再见]',
  '[敲打]',
  '[擦汗]',
  '[猪头]',
  '[玫瑰]',
  '[流泪]',
  '[大哭]',
  '[嘘]',
  '[酷]',
  '[抓狂]',
  '[委屈]',
  '[便便]',
  '[炸弹]',
  '[菜刀]',
  '[可爱]',
  '[色]',
  '[害羞]',
  '[得意]',
  '[吐]',
  '[微笑]',
  '[怒]',
  '[尴尬]',
  '[惊恐]',
  '[冷汗]',
  '[爱心]',
  '[示爱]',
  '[白眼]',
  '[傲慢]',
  '[难过]',
  '[惊讶]',
  '[疑问]',
  '[困]',
  '[么么哒]',
  '[憨笑]',
  '[爱情]',
  '[衰]',
  '[撇嘴]',
  '[阴险]',
  '[奋斗]',
  '[发呆]',
  '[右哼哼]',
  '[抱抱]',
  '[坏笑]',
  '[飞吻]',
  '[鄙视]',
  '[晕]',
  '[大兵]',
  '[可怜]',
  '[强]',
  '[弱]',
  '[握手]',
  '[胜利]',
  '[抱拳]',
  '[凋谢]',
  '[米饭]',
  '[蛋糕]',
  '[西瓜]',
  '[啤酒]',
  '[瓢虫]',
  '[勾引]',
  '[OK]',
  '[爱你]',
  '[咖啡]',
  '[月亮]',
  '[刀]',
  '[发抖]',
  '[差劲]',
  '[拳头]',
  '[心碎了]',
  '[太阳]',
  '[礼物]',
  '[皮球]',
  '[骷髅]',
  '[挥手]',
  '[闪电]',
  '[饥饿]',
  '[咒骂]',
  '[折磨]',
  '[抠鼻]',
  '[鼓掌]',
  '[糗大了]',
  '[左哼哼]',
  '[打哈欠]',
  '[快哭了]',
  '[吓]',
  '[篮球]',
  '[乒乓]',
  '[NO]',
  '[跳跳]',
  '[怄火]',
  '[转圈]',
  '[磕头]',
  '[回头]',
  '[跳绳]',
  '[激动]',
  '[街舞]',
  '[献吻]',
  '[左太极]',
  '[右太极]',
  '[闭嘴]',
  '[猫咪]',
  '[红双喜]',
  '[鞭炮]',
  '[红灯笼]',
  '[麻将]',
  '[麦克风]',
  '[礼品袋]',
  '[信封]',
  '[象棋]',
  '[彩带]',
  '[蜡烛]',
  '[爆筋]',
  '[棒棒糖]',
  '[奶瓶]',
  '[面条]',
  '[香蕉]',
  '[飞机]',
  '[左车头]',
  '[车厢]',
  '[右车头]',
  '[多云]',
  '[下雨]',
  '[钞票]',
  '[熊猫]',
  '[灯泡]',
  '[风车]',
  '[闹钟]',
  '[雨伞]',
  '[彩球]',
  '[钻戒]',
  '[沙发]',
  '[纸巾]',
  '[手枪]',
  '[青蛙]',
];
export const emojiPlusBaseUrl = 'emoji-plugin/';
export const emojiPlusName: Array<string> = [
  '[TUIEmoji_Expect]',
  '[TUIEmoji_Blink]',
  '[TUIEmoji_Guffaw]',
  '[TUIEmoji_KindSmile]',
  '[TUIEmoji_Haha]',
  '[TUIEmoji_Cheerful]',
  '[TUIEmoji_Smile]',
  '[TUIEmoji_Sorrow]',
  '[TUIEmoji_Speechless]',
  '[TUIEmoji_Amazed]',
  '[TUIEmoji_Complacent]',
  '[TUIEmoji_Lustful]',
  '[TUIEmoji_Stareyes]',
  '[TUIEmoji_Giggle]',
  '[TUIEmoji_Daemon]',
  '[TUIEmoji_Rage]',
  '[TUIEmoji_Yawn]',
  '[TUIEmoji_TearsLaugh]',
  '[TUIEmoji_Silly]',
  '[TUIEmoji_Wail]',
  '[TUIEmoji_Kiss]',
  '[TUIEmoji_Trapped]',
  '[TUIEmoji_Fear]',
  '[TUIEmoji_BareTeeth]',
  '[TUIEmoji_FlareUp]',
  '[TUIEmoji_Tact]',
  '[TUIEmoji_Shit]',
  '[TUIEmoji_ShutUp]',
  '[TUIEmoji_Sigh]',
  '[TUIEmoji_Hehe]',
  '[TUIEmoji_Silent]',
  '[TUIEmoji_Skull]',
  '[TUIEmoji_Mask]',
  '[TUIEmoji_Beer]',
  '[TUIEmoji_Cake]',
  '[TUIEmoji_RedPacket]',
  '[TUIEmoji_Bombs]',
  '[TUIEmoji_Ai]',
  '[TUIEmoji_Celebrate]',
  '[TUIEmoji_Bless]',
  '[TUIEmoji_Flower]',
  '[TUIEmoji_Watermelon]',
  '[TUIEmoji_Cow]',
  '[TUIEmoji_Fool]',
  '[TUIEmoji_Surprised]',
  '[TUIEmoji_Askance]',
  '[TUIEmoji_Monster]',
  '[TUIEmoji_Pig]',
  '[TUIEmoji_Coffee]',
  '[TUIEmoji_Ok]',
  '[TUIEmoji_Heart]',
  '[TUIEmoji_Sun]',
  '[TUIEmoji_Moon]',
  '[TUIEmoji_Star]',
  '[TUIEmoji_Rich]',
  '[TUIEmoji_Fortune]',
  '[TUIEmoji_857]',
  '[TUIEmoji_666]',
  '[TUIEmoji_Prohibit]',
  '[TUIEmoji_Convinced]',
  '[TUIEmoji_Knife]',
  '[TUIEmoji_Like]',
];
export const emojiPlusUrlMapping: { [key: string]: string } =
  buildSequentialFileNameMap(emojiPlusName);

export const emojiSrcMap: { [key: string]: string } = buildEmojiSrcMap(
  emojiMap,
  emojiAssetUrlMap,
);
export const emojiPlusSrcMap: { [key: string]: string } = buildEmojiSrcMap(
  emojiPlusUrlMapping,
  emojiPluginAssetUrlMap,
);
export const emojiTokenSrcMap: { [key: string]: string } = {
  ...emojiSrcMap,
  ...emojiPlusSrcMap,
};
