"use strict";
const common_vendor = require("../../../../common/vendor.js");
const TUIKit_components_TUIChat_emojiConfig_customEmoji = require("./custom-emoji.js");
const TUIKit_components_TUIChat_emojiConfig_defaultEmoji = require("./default-emoji.js");
const TUIKit_components_TUIChat_emojiConfig_locales_zh_cn = require("./locales/zh_cn.js");
const TUIKit_constant = require("../../../constant.js");
const TUIKit_utils_env = require("../../../utils/env.js");
const BASIC_EMOJI_URL = TUIKit_components_TUIChat_emojiConfig_defaultEmoji.DEFAULT_BASIC_EMOJI_URL;
const BASIC_EMOJI_URL_MAPPING = TUIKit_components_TUIChat_emojiConfig_defaultEmoji.DEFAULT_BASIC_EMOJI_URL_MAPPING;
const EMOJI_GROUP_LIST = [
  {
    emojiGroupID: 0,
    type: TUIKit_constant.EMOJI_TYPE.BASIC,
    url: BASIC_EMOJI_URL,
    list: Object.keys(BASIC_EMOJI_URL_MAPPING)
  },
  ...TUIKit_components_TUIChat_emojiConfig_defaultEmoji.BIG_EMOJI_GROUP_LIST,
  ...TUIKit_components_TUIChat_emojiConfig_customEmoji.CUSTOM_BIG_EMOJI_GROUP_LIST
];
const convertKeyToEmojiName = (key) => {
  return TUIKit_utils_env.isWeChat ? TUIKit_components_TUIChat_emojiConfig_locales_zh_cn.Emoji[key] : common_vendor.Wt.t(`Emoji.${key}`);
};
const transformTextWithKeysToEmojiNames = (text) => {
  if (!text) {
    return "";
  }
  const reg = /(\[.+?\])/g;
  let txt = text;
  if (reg.test(text)) {
    txt = text.replace(reg, (match) => BASIC_EMOJI_URL_MAPPING[match] ? convertKeyToEmojiName(match) : match);
  }
  return txt;
};
const transformTextWithEmojiNamesToKeys = (text) => {
  if (!text) {
    return "";
  }
  const reg = /(\[.+?\])/g;
  let txt = text;
  if (reg.test(text)) {
    txt = text.replace(reg, (match) => TUIKit_components_TUIChat_emojiConfig_defaultEmoji.BASIC_EMOJI_NAME_TO_KEY_MAPPING[match] || match);
  }
  return txt;
};
const parseTextToRenderArray = (text) => {
  const emojiRegex = /\[([^\]]+)\]/g;
  const result = [];
  let match;
  let lastIndex = 0;
  while ((match = emojiRegex.exec(text)) !== null) {
    const startIndex = match.index;
    const endIndex = emojiRegex.lastIndex;
    const emojiKey = match[0];
    if (startIndex > lastIndex) {
      result.push({ type: "text", content: text.substring(lastIndex, startIndex) });
    }
    const emojiUrl = BASIC_EMOJI_URL + BASIC_EMOJI_URL_MAPPING[emojiKey];
    if (emojiUrl) {
      result.push({ type: "image", content: emojiUrl, emojiKey });
    } else {
      result.push({ type: "text", content: emojiKey });
    }
    lastIndex = endIndex;
    emojiRegex.lastIndex = lastIndex;
  }
  if (lastIndex < text.length) {
    result.push({ type: "text", content: text.substring(lastIndex) });
  }
  return result;
};
exports.BASIC_EMOJI_URL_MAPPING = BASIC_EMOJI_URL_MAPPING;
exports.EMOJI_GROUP_LIST = EMOJI_GROUP_LIST;
exports.convertKeyToEmojiName = convertKeyToEmojiName;
exports.parseTextToRenderArray = parseTextToRenderArray;
exports.transformTextWithEmojiNamesToKeys = transformTextWithEmojiNamesToKeys;
exports.transformTextWithKeysToEmojiNames = transformTextWithKeysToEmojiNames;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/emoji-config/index.js.map
