"use strict";
const common_vendor = require("../../../../../common/vendor.js");
require("../../../../adapter-vue.js");
const TUIKit_utils_env = require("../../../../utils/env.js");
if (!Math) {
  (Transfer + Dialog)();
}
const Dialog = () => "../../../common/Dialog/index.js";
const Transfer = () => "../../../common/Transfer/index.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  props: {
    // type: voiceCall/groupCall/...
    type: {
      type: String,
      default: ""
    },
    currentConversation: {
      type: Object,
      default: () => ({})
    },
    isGroup: {
      type: Boolean,
      default: false
    }
  },
  emits: ["submit", "cancel"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const show = common_vendor.ref(false);
    const groupID = common_vendor.ref("");
    const memberList = common_vendor.ref([]);
    const searchMemberList = common_vendor.ref([]);
    const selfUserID = common_vendor.ref("");
    const titleMap = {
      voiceCall: "发起群语音",
      videoCall: "发起群视频"
    };
    const title = common_vendor.computed(() => {
      return titleMap[props.type] ? titleMap[props.type] : "";
    });
    common_vendor.Zt.getUserProfile().then((res) => {
      var _a;
      if ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.userID) {
        selfUserID.value = res.data.userID;
      }
    });
    common_vendor.watch(
      () => {
        var _a;
        return [(_a = props == null ? void 0 : props.currentConversation) == null ? void 0 : _a.conversationID, show.value];
      },
      (newVal, oldVal) => {
        if (newVal && newVal !== oldVal) {
          if (props.isGroup && show.value) {
            groupID.value = props.currentConversation.groupProfile.groupID;
            common_vendor.es.getGroupMemberList({
              groupID: groupID.value
            }).then((res) => {
              var _a, _b;
              memberList.value = (_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.memberList) == null ? void 0 : _b.filter(
                (user) => (user == null ? void 0 : user.userID) !== selfUserID.value
              );
              searchMemberList.value = memberList.value;
            });
          } else {
            groupID.value = "";
            memberList.value = [];
            searchMemberList.value = memberList.value;
          }
        }
      },
      {
        immediate: true
      }
    );
    const search = (searchInfo) => {
      var _a;
      const results = (_a = memberList.value) == null ? void 0 : _a.filter(
        (member) => (member == null ? void 0 : member.userID) === searchInfo
      );
      searchMemberList.value = (results == null ? void 0 : results.length) ? results : memberList.value;
    };
    const submit = (selectedMemberList) => {
      const userIDList = [];
      selectedMemberList == null ? void 0 : selectedMemberList.forEach((user) => {
        (user == null ? void 0 : user.userID) && userIDList.push(user.userID);
      });
      if (props.type === "voiceCall") {
        emits("submit", { userIDList, groupID: groupID.value, type: 1 });
      } else if (props.type === "videoCall") {
        emits("submit", { userIDList, groupID: groupID.value, type: 2 });
      }
      searchMemberList.value = memberList.value;
      toggleShow(false);
    };
    const cancel = () => {
      searchMemberList.value = memberList.value;
      emits("cancel");
      toggleShow(false);
    };
    const toggleShow = (showStatus) => {
      show.value = showStatus;
    };
    __expose({
      toggleShow
    });
    return (_ctx, _cache) => {
      return {
        a: common_vendor.o$1(search),
        b: common_vendor.o$1(submit),
        c: common_vendor.o$1(cancel),
        d: common_vendor.p({
          isSearch: true,
          title: common_vendor.unref(title),
          list: common_vendor.unref(searchMemberList),
          isH5: !common_vendor.unref(TUIKit_utils_env.isPC),
          isRadio: false
        }),
        e: common_vendor.o$1(toggleShow),
        f: common_vendor.p({
          show: common_vendor.unref(show),
          isH5: !common_vendor.unref(TUIKit_utils_env.isPC),
          isHeaderShow: false,
          isFooterShow: false,
          background: false
        })
      };
    };
  }
});
wx.createComponent(_sfc_main);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-input-toolbar/user-selector/index.js.map
