"use strict";
const common_vendor = require("../../../../../common/vendor.js");
require("../../../../adapter-vue.js");
const common_assets = require("../../../../../common/assets.js");
const TUIKit_utils_env = require("../../../../utils/env.js");
if (!Math) {
  (Icon + Avatar + Drawer)();
}
const Icon = () => "../../../common/Icon.js";
const Avatar = () => "../../../common/Avatar/index.js";
const Drawer = () => "../../../common/Drawer/index.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  props: {
    groupID: { default: "" }
  },
  setup(__props) {
    const props = __props;
    const drawerDomInstanceRef = common_vendor.ref();
    const groupApplicationCount = common_vendor.ref(0);
    const isGroupApplicationDrawerShow = common_vendor.ref(false);
    const customGroupApplicationList = common_vendor.ref([]);
    common_vendor.watch(isGroupApplicationDrawerShow, (newVal) => {
      if (newVal) {
        generateCustomGroupApplicationList().then((list) => {
          customGroupApplicationList.value = list;
          groupApplicationCount.value = list.length;
        });
      }
    });
    common_vendor.watch(() => customGroupApplicationList.value.length, (newVal, oldVal) => {
      if (oldVal > 0 && newVal === 0) {
        isGroupApplicationDrawerShow.value = false;
      }
    });
    async function getCurrentGroupApplicationList() {
      const result = await common_vendor.es.getGroupApplicationList();
      const currentGroupApplicationList = result.data.applicationList.filter((application) => application.groupID === props.groupID);
      return currentGroupApplicationList;
    }
    function toggleGroupApplicationDrawerShow() {
      isGroupApplicationDrawerShow.value = !isGroupApplicationDrawerShow.value;
    }
    async function generateCustomGroupApplicationList() {
      const applicationList = await getCurrentGroupApplicationList();
      if (applicationList.length === 0) {
        return [];
      }
      const userIDList = applicationList.map((application) => application.applicationType === 0 ? application.applicant : application.userID);
      const { data: userProfileList } = await common_vendor.Zt.getUserProfile({ userIDList });
      const mappingFromUserID2Profile = {};
      userProfileList.forEach((profile) => {
        mappingFromUserID2Profile[profile.userID] = profile;
      });
      const groupApplicationList = applicationList.map((application) => {
        const profile = mappingFromUserID2Profile[application.applicationType === 0 ? application.applicant : application.userID];
        return {
          nick: profile.nick || profile.userID || "anonymous",
          avatar: profile.avatar || "",
          isRemoved: false,
          application
        };
      });
      return groupApplicationList;
    }
    function handleApplication(customApplication, action, index) {
      common_vendor.es.handleGroupApplication({
        handleAction: action,
        application: customApplication.application
      }).then(() => {
        customGroupApplicationList.value[index].isRemoved = true;
        setTimeout(() => {
          customGroupApplicationList.value.splice(index, 1);
          groupApplicationCount.value -= 1;
        }, 150);
      }).catch(() => {
      });
    }
    common_vendor.onMounted(() => {
      getCurrentGroupApplicationList().then((applicationList) => {
        groupApplicationCount.value = applicationList.length;
      });
      common_vendor.Jt.watch(common_vendor.o.GRP, {
        groupSystemNoticeList: onGroupSystemNoticeListUpdated
      });
    });
    common_vendor.onUnmounted(() => {
      common_vendor.Jt.unwatch(common_vendor.o.GRP, {
        groupSystemNoticeList: onGroupSystemNoticeListUpdated
      });
    });
    function onGroupSystemNoticeListUpdated() {
      generateCustomGroupApplicationList().then((list) => {
        customGroupApplicationList.value = list;
        groupApplicationCount.value = list.length;
      });
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.unref(groupApplicationCount) > 0
      }, common_vendor.unref(groupApplicationCount) > 0 ? {
        b: common_vendor.t(common_vendor.unref(groupApplicationCount)),
        c: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.条入群申请")),
        d: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.点击处理")),
        e: common_vendor.o$1(toggleGroupApplicationDrawerShow)
      } : {}, {
        f: common_vendor.unref(TUIKit_utils_env.isPC)
      }, common_vendor.unref(TUIKit_utils_env.isPC) ? {
        g: common_vendor.p({
          file: common_vendor.unref(common_assets.closeIcon$1),
          size: "16px"
        })
      } : {
        h: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("关闭"))
      }, {
        i: common_vendor.o$1(toggleGroupApplicationDrawerShow),
        j: common_vendor.f(common_vendor.unref(customGroupApplicationList), (item, index, i0) => {
          return {
            a: "4c42d719-2-" + i0 + ",4c42d719-0",
            b: common_vendor.p({
              url: item.avatar,
              useSkeletonAnimation: true
            }),
            c: common_vendor.t(item.nick),
            d: common_vendor.o$1(($event) => handleApplication(item, "Agree", index), item.nick),
            e: common_vendor.o$1(($event) => handleApplication(item, "Reject", index), item.nick),
            f: item.nick,
            g: item.isRemoved ? 1 : ""
          };
        }),
        k: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.申请加入")),
        l: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.同意")),
        m: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.拒绝")),
        n: common_vendor.sr(drawerDomInstanceRef, "4c42d719-0", {
          "k": "drawerDomInstanceRef"
        }),
        o: common_vendor.o$1(toggleGroupApplicationDrawerShow),
        p: common_vendor.p({
          visible: common_vendor.unref(isGroupApplicationDrawerShow),
          zIndex: 998,
          popDirection: common_vendor.unref(TUIKit_utils_env.isMobile) ? "bottom" : "right",
          isFullScreen: common_vendor.unref(TUIKit_utils_env.isMobile),
          overlayColor: common_vendor.unref(TUIKit_utils_env.isMobile) ? void 0 : "transparent",
          drawerStyle: {
            bottom: {
              minHeight: "60vh",
              maxHeight: "80vh",
              borderRadius: "12px 12px 0 0"
            },
            right: {
              width: "360px",
              borderRadius: "12px 0 0 12px",
              boxShadow: "0 0 10px 0 #d0d0d0"
            }
          }
        })
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4c42d719"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-list/message-group-application/index.js.map
