"use strict";
const common_vendor = require("../../../../../common/vendor.js");
require("../../../../adapter-vue.js");
const common_assets = require("../../../../../common/assets.js");
const TUIKit_constant = require("../../../../constant.js");
const TUIKit_utils_env = require("../../../../utils/env.js");
const TUIKit_components_TUIChat_utils_utils = require("../../utils/utils.js");
const TUIKit_components_TUIChat_emojiConfig_index = require("../../emoji-config/index.js");
const TUIKit_components_TUIChat_config = require("../../config.js");
if (!Math) {
  Icon();
}
const Icon = () => "../../../common/Icon.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "emoji-picker-dialog",
  emits: ["insertEmoji", "onClose", "sendMessage"],
  setup(__props, { emit: __emit }) {
    var _a;
    const faceIcon = TUIKit_components_TUIChat_config.ChatConfig.getTheme() === "dark" ? common_assets.faceIconDark : common_assets.faceIconLight;
    const emits = __emit;
    const currentTabIndex = common_vendor.ref(0);
    const currentConversation = common_vendor.ref();
    common_vendor.ref();
    const emojiPickerListRef = common_vendor.ref();
    const featureConfig = TUIKit_components_TUIChat_config.ChatConfig.getFeatureConfig();
    const list = common_vendor.ref(initEmojiList());
    const currentTabItem = common_vendor.ref(list == null ? void 0 : list.value[0]);
    const currentEmojiList = common_vendor.ref((_a = list == null ? void 0 : list.value[0]) == null ? void 0 : _a.list);
    common_vendor.onMounted(() => {
      common_vendor.Jt.watch(common_vendor.o.CONV, {
        currentConversation: onCurrentConversationUpdate
      });
    });
    common_vendor.onUnmounted(() => {
      common_vendor.Jt.unwatch(common_vendor.o.CONV, {
        currentConversation: onCurrentConversationUpdate
      });
    });
    const toggleEmojiTab = (index) => {
      var _a2;
      currentTabIndex.value = index;
      currentTabItem.value = list == null ? void 0 : list.value[index];
      currentEmojiList.value = (_a2 = list == null ? void 0 : list.value[index]) == null ? void 0 : _a2.list;
      if (!TUIKit_utils_env.isUniFrameWork) {
        (emojiPickerListRef == null ? void 0 : emojiPickerListRef.value) && (emojiPickerListRef.value.scrollTop = 0);
      }
    };
    const select = (item, index) => {
      var _a2, _b, _c;
      const options = {
        emoji: { key: item, name: TUIKit_components_TUIChat_emojiConfig_index.convertKeyToEmojiName(item) },
        type: (_a2 = currentTabItem == null ? void 0 : currentTabItem.value) == null ? void 0 : _a2.type
      };
      switch ((_b = currentTabItem == null ? void 0 : currentTabItem.value) == null ? void 0 : _b.type) {
        case TUIKit_constant.EMOJI_TYPE.BASIC:
          options.url = ((_c = currentTabItem == null ? void 0 : currentTabItem.value) == null ? void 0 : _c.url) + TUIKit_components_TUIChat_emojiConfig_index.BASIC_EMOJI_URL_MAPPING[item];
          if (TUIKit_utils_env.isUniFrameWork) {
            common_vendor.index.$emit("insert-emoji", options);
          } else {
            emits("insertEmoji", options);
          }
          break;
        case TUIKit_constant.EMOJI_TYPE.BIG:
          sendFaceMessage(index, currentTabItem.value);
          break;
        case TUIKit_constant.EMOJI_TYPE.CUSTOM:
          sendFaceMessage(index, currentTabItem.value);
          break;
      }
      TUIKit_utils_env.isPC && emits("onClose");
    };
    const sendFaceMessage = (index, listItem) => {
      var _a2, _b, _c, _d, _e;
      const options = {
        to: ((_b = (_a2 = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _a2.groupProfile) == null ? void 0 : _b.groupID) || ((_d = (_c = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _c.userProfile) == null ? void 0 : _d.userID),
        conversationType: (_e = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _e.type,
        payload: {
          index: listItem.emojiGroupID,
          data: listItem.list[index]
        },
        needReadReceipt: TUIKit_components_TUIChat_utils_utils.isEnabledMessageReadReceiptGlobal()
      };
      common_vendor.Qt.sendFaceMessage(options);
    };
    function sendMessage() {
      common_vendor.index.$emit("send-message-in-emoji-picker");
    }
    function onCurrentConversationUpdate(conversation) {
      currentConversation.value = conversation;
    }
    function initEmojiList() {
      return TUIKit_components_TUIChat_emojiConfig_index.EMOJI_GROUP_LIST.filter((item) => {
        if (item.type === TUIKit_constant.EMOJI_TYPE.BASIC) {
          return featureConfig.InputEmoji;
        }
        if (item.type === TUIKit_constant.EMOJI_TYPE.BIG) {
          return featureConfig.InputStickers;
        }
        if (item.type === TUIKit_constant.EMOJI_TYPE.CUSTOM) {
          return featureConfig.InputStickers;
        }
      });
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.f(common_vendor.unref(currentEmojiList), (childrenItem, childrenIndex, i0) => {
          return common_vendor.e(common_vendor.unref(currentTabItem).type === common_vendor.unref(TUIKit_constant.EMOJI_TYPE).BASIC ? {
            a: common_vendor.unref(currentTabItem).url + common_vendor.unref(TUIKit_components_TUIChat_emojiConfig_index.BASIC_EMOJI_URL_MAPPING)[childrenItem]
          } : common_vendor.unref(currentTabItem).type === common_vendor.unref(TUIKit_constant.EMOJI_TYPE).BIG ? {
            b: common_vendor.unref(currentTabItem).url + childrenItem + "@2x.png"
          } : {
            c: common_vendor.unref(currentTabItem).url + childrenItem
          }, {
            d: childrenIndex,
            e: common_vendor.o$1(($event) => select(childrenItem, childrenIndex), childrenIndex)
          });
        }),
        b: common_vendor.unref(currentTabItem).type === common_vendor.unref(TUIKit_constant.EMOJI_TYPE).BASIC,
        c: common_vendor.unref(currentTabItem).type === common_vendor.unref(TUIKit_constant.EMOJI_TYPE).BIG,
        d: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "emoji-picker-h5-list"),
        e: common_vendor.f(common_vendor.unref(list), (item, index, i0) => {
          return common_vendor.e({
            a: item.type === common_vendor.unref(TUIKit_constant.EMOJI_TYPE).BASIC
          }, item.type === common_vendor.unref(TUIKit_constant.EMOJI_TYPE).BASIC ? {
            b: "194fb307-0-" + i0,
            c: common_vendor.p({
              file: common_vendor.unref(faceIcon)
            })
          } : item.type === common_vendor.unref(TUIKit_constant.EMOJI_TYPE).BIG ? {
            e: item.url + item.list[0] + "@2x.png"
          } : {
            f: item.url + item.list[0]
          }, {
            d: item.type === common_vendor.unref(TUIKit_constant.EMOJI_TYPE).BIG,
            g: index,
            h: common_vendor.o$1(($event) => toggleEmojiTab(index), index)
          });
        }),
        f: common_vendor.unref(TUIKit_utils_env.isUniFrameWork)
      }, common_vendor.unref(TUIKit_utils_env.isUniFrameWork) ? {
        g: common_vendor.o$1(sendMessage)
      } : {}, {
        h: !common_vendor.unref(TUIKit_utils_env.isPC) ? 1 : ""
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-194fb307"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-input-toolbar/emoji-picker/emoji-picker-dialog.js.map
