"use strict";
const common_vendor = require("../../../../../common/vendor.js");
require("../../../../adapter-vue.js");
const TUIKit_utils_env = require("../../../../utils/env.js");
if (!Math) {
  BottomPopup();
}
const BottomPopup = () => "../../../common/BottomPopup/index.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  emits: ["onAtListOpen", "insertAt"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const emits = __emit;
    const MessageInputAt = common_vendor.ref();
    const memberListItems = common_vendor.ref();
    const showAtList = common_vendor.ref(false);
    const memberList = common_vendor.ref();
    const allMemberList = common_vendor.ref();
    const showMemberList = common_vendor.ref();
    const isGroup = common_vendor.ref(false);
    const position = common_vendor.ref({
      left: 0,
      top: 0
    });
    const selectedIndex = common_vendor.ref(0);
    const currentConversationID = common_vendor.ref("");
    const all = {
      userID: common_vendor.qt.TYPES.MSG_AT_ALL,
      nick: "所有人",
      isAll: true,
      avatar: "https://web.sdk.qcloud.com/im/assets/images/at.svg"
    };
    common_vendor.Jt.watch(common_vendor.o.CONV, {
      currentConversationID: (id) => {
        var _a, _b;
        if (id !== currentConversationID.value) {
          currentConversationID.value = id;
          memberList.value = [];
          allMemberList.value = [];
          showMemberList.value = [];
          isGroup.value = false;
          common_vendor.Jt.update(common_vendor.o.CUSTOM, "memberList", memberList.value);
          if ((_a = currentConversationID == null ? void 0 : currentConversationID.value) == null ? void 0 : _a.startsWith("GROUP")) {
            isGroup.value = true;
            const groupID = (_b = currentConversationID == null ? void 0 : currentConversationID.value) == null ? void 0 : _b.substring(5);
            common_vendor.es.switchGroup(groupID);
          } else {
            common_vendor.es.switchGroup("");
          }
        }
      }
    });
    common_vendor.Jt.watch(common_vendor.o.GRP, {
      currentGroupMemberList: (list) => {
        memberList.value = list;
        allMemberList.value = [all, ...memberList.value];
        showMemberList.value = allMemberList.value;
        common_vendor.Jt.update(common_vendor.o.CUSTOM, "memberList", memberList.value);
      }
    });
    const toggleAtList = (show) => {
      if (!isGroup.value) {
        return;
      }
      showAtList.value = show;
      if (showAtList.value) {
        emits("onAtListOpen");
      }
    };
    const handleAtListPosition = (positionData) => {
      position.value = positionData;
    };
    const setCurrentSelectIndex = (index) => {
      var _a, _b;
      selectedIndex.value = index;
      (_b = (_a = memberListItems.value) == null ? void 0 : _a[selectedIndex.value]) == null ? void 0 : _b.scrollIntoView(false);
    };
    const setShowMemberList = (list) => {
      showMemberList.value = list;
    };
    common_vendor.i.toggleAtList = toggleAtList;
    common_vendor.i.handleAtListPosition = handleAtListPosition;
    common_vendor.i.setCurrentSelectIndex = setCurrentSelectIndex;
    common_vendor.i.setShowMemberList = setShowMemberList;
    __expose({
      toggleAtList
    });
    common_vendor.watch(
      () => [position.value, MessageInputAt == null ? void 0 : MessageInputAt.value],
      () => {
        var _a;
        if (TUIKit_utils_env.isH5 || !(MessageInputAt == null ? void 0 : MessageInputAt.value) || !((_a = MessageInputAt == null ? void 0 : MessageInputAt.value) == null ? void 0 : _a.style)) {
          return;
        }
        MessageInputAt.value.style.left = position.value.left + "px";
        MessageInputAt.value.style.top = position.value.top - MessageInputAt.value.clientHeight + "px";
      }
    );
    const closeAt = () => {
      showAtList.value = false;
      showMemberList.value = allMemberList.value;
      position.value = {
        left: 0,
        top: 0
      };
    };
    const selectItem = (index) => {
      var _a;
      if (TUIKit_utils_env.isPC && common_vendor.i.selectItem) {
        common_vendor.i.selectItem(index);
      } else {
        if ((_a = showMemberList == null ? void 0 : showMemberList.value) == null ? void 0 : _a.length) {
          const item = showMemberList == null ? void 0 : showMemberList.value[index];
          emits("insertAt", {
            id: item == null ? void 0 : item.userID,
            label: (item == null ? void 0 : item.nick) || (item == null ? void 0 : item.userID)
          });
        }
      }
      closeAt();
    };
    const handleMemberAvatar = (item) => {
      return (item == null ? void 0 : item.avatar) || "https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png";
    };
    const handleMemberName = (item) => {
      return (item == null ? void 0 : item.nick) ? item == null ? void 0 : item.nick : item == null ? void 0 : item.userID;
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: !common_vendor.unref(TUIKit_utils_env.isPC)
      }, !common_vendor.unref(TUIKit_utils_env.isPC) ? {
        b: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.选择提醒的人"))
      } : {}, {
        c: common_vendor.f(common_vendor.unref(showMemberList), (item, index, i0) => {
          return {
            a: handleMemberAvatar(item),
            b: common_vendor.t(handleMemberName(item)),
            c: index,
            d: common_vendor.n(index === common_vendor.unref(selectedIndex) && "selected"),
            e: common_vendor.o$1(($event) => selectItem(index), index)
          };
        }),
        d: common_vendor.n(common_vendor.unref(TUIKit_utils_env.isPC) ? "message-input-at" : "message-input-at-h5"),
        e: common_vendor.o$1(closeAt),
        f: common_vendor.p({
          show: common_vendor.unref(showAtList)
        })
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-7a11d573"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-input/message-input-at/index.js.map
