"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 + FetchMore + Overlay)();
}
const Icon = () => "../../../common/Icon.js";
const Overlay = () => "../../../common/Overlay/index.js";
const Avatar = () => "../../../common/Avatar/index.js";
const FetchMore = () => "../../../common/FetchMore/index.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  props: {
    message: { default: () => ({}) }
  },
  emits: ["setReadReceiptPanelVisible"],
  setup(__props, { emit: __emit }) {
    const emits = __emit;
    const props = __props;
    let lastUnreadCursor = "";
    let lastReadCursor = "";
    const tabNameList = ["unread", "read"];
    const isListFetchCompleted = {
      unread: false,
      read: false,
      close: false
    };
    const isPullDownFetching = common_vendor.ref(false);
    const isPanelClose = common_vendor.ref(false);
    const isFirstLoadFinished = common_vendor.ref(false);
    const isStopFetchMore = common_vendor.ref(false);
    const currentTabName = common_vendor.ref("unread");
    const tabInfo = common_vendor.ref(generateInitalTabInfo());
    common_vendor.onMounted(async () => {
      await initAndRefetchReceiptInfomation();
      common_vendor.nextTick$1(() => {
        isFirstLoadFinished.value = true;
      });
    });
    common_vendor.watch(
      () => props.message.readReceiptInfo.readCount,
      () => {
        initAndRefetchReceiptInfomation();
      }
    );
    async function fetchGroupMessageRecriptMemberListByType(readType = "all") {
      const message = common_vendor.Jt.getMessageModel(props.message.ID);
      let unreadResult = {};
      let readResult = {};
      if (readType === "all" || readType === "unread") {
        unreadResult = await common_vendor.Qt.getGroupMessageReadMemberList({
          message,
          filter: 1,
          cursor: lastUnreadCursor,
          count: 100
        });
        if (unreadResult) {
          lastUnreadCursor = unreadResult.data.cursor;
          if (unreadResult.data.isCompleted) {
            isListFetchCompleted.unread = true;
          }
        }
      }
      if (readType === "all" || readType === "read") {
        readResult = await common_vendor.Qt.getGroupMessageReadMemberList({
          message,
          filter: 0,
          cursor: lastReadCursor,
          count: 100
        });
        if (readResult) {
          lastReadCursor = readResult.data.cursor;
          if (readResult.data.isCompleted) {
            isListFetchCompleted.read = true;
          }
        }
      }
      const { unreadCount: totalUnreadCount, readCount: totalReadCount } = message.readReceiptInfo;
      return {
        unreadResult: {
          count: totalUnreadCount,
          ...unreadResult.data
        },
        readResult: {
          count: totalReadCount,
          ...readResult.data
        }
      };
    }
    async function pullDownFetchMoreData() {
      if (isListFetchCompleted[currentTabName.value] || isPullDownFetching.value) {
        return;
      }
      isPullDownFetching.value = true;
      if (currentTabName.value === "unread" || currentTabName.value === "read") {
        const { unreadResult, readResult } = await fetchGroupMessageRecriptMemberListByType(currentTabName.value);
        checkStopFetchMore();
        try {
          tabInfo.value.unread.memberList = tabInfo.value.unread.memberList.concat(unreadResult.unreadUserInfoList || []);
          tabInfo.value.read.memberList = tabInfo.value.read.memberList.concat(readResult.readUserInfoList || []);
        } finally {
          isPullDownFetching.value = false;
        }
      }
    }
    async function initAndRefetchReceiptInfomation() {
      lastUnreadCursor = "";
      lastReadCursor = "";
      isStopFetchMore.value = false;
      isListFetchCompleted.unread = false;
      isListFetchCompleted.read = false;
      const { unreadResult, readResult } = await fetchGroupMessageRecriptMemberListByType("all");
      checkStopFetchMore();
      resetTabInfo("read", readResult.count, readResult.readUserInfoList);
      resetTabInfo("unread", unreadResult.count, unreadResult.unreadUserInfoList);
      resetTabInfo("close");
    }
    function checkStopFetchMore() {
      if (isListFetchCompleted.read && isListFetchCompleted.unread) {
        isStopFetchMore.value = true;
      }
    }
    function resetTabInfo(tabName, count, memberList) {
      tabInfo.value[tabName].count = count;
      tabInfo.value[tabName].memberList = memberList || [];
    }
    function generateInitalTabInfo() {
      return {
        read: {
          tabName: common_vendor.Wt.t("TUIChat.已读"),
          count: void 0,
          memberList: []
        },
        unread: {
          tabName: common_vendor.Wt.t("TUIChat.未读"),
          count: void 0,
          memberList: []
        },
        close: {
          tabName: common_vendor.Wt.t("TUIChat.关闭"),
          count: void 0,
          memberList: []
        }
      };
    }
    function toggleTabName(tabName) {
      currentTabName.value = tabName;
    }
    function closeReadReceiptPanel() {
      isPanelClose.value = true;
      setTimeout(() => {
        emits("setReadReceiptPanelVisible", false);
      }, 200);
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.消息详情")),
        b: common_vendor.o$1(closeReadReceiptPanel),
        c: common_vendor.p({
          size: "12px",
          hotAreaSize: "8",
          file: common_vendor.unref(common_assets.closeIcon$2)
        }),
        d: common_vendor.f(tabNameList, (tabName, k0, i0) => {
          return {
            a: common_vendor.t(common_vendor.unref(tabInfo)[tabName].tabName),
            b: common_vendor.t(common_vendor.unref(tabInfo)[tabName].count === void 0 ? "" : common_vendor.unref(tabInfo)[tabName].count),
            c: tabName,
            d: tabName === common_vendor.unref(currentTabName) ? 1 : "",
            e: common_vendor.o$1(($event) => toggleTabName(tabName), tabName)
          };
        }),
        e: common_vendor.unref(tabInfo)[common_vendor.unref(currentTabName)].count === 0 && common_vendor.unref(isFirstLoadFinished)
      }, common_vendor.unref(tabInfo)[common_vendor.unref(currentTabName)].count === 0 && common_vendor.unref(isFirstLoadFinished) ? {
        f: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.空"))
      } : common_vendor.unref(isFirstLoadFinished) ? common_vendor.e({
        h: common_vendor.unref(currentTabName) === "unread"
      }, common_vendor.unref(currentTabName) === "unread" ? {
        i: common_vendor.f(common_vendor.unref(tabInfo)[common_vendor.unref(currentTabName)].memberList, (item, k0, i0) => {
          return {
            a: "8316d693-2-" + i0 + ",8316d693-0",
            b: common_vendor.p({
              useSkeletonAnimation: true,
              url: item.avatar || ""
            }),
            c: common_vendor.t(item.nick || item.userID),
            d: item.userID
          };
        })
      } : {}, {
        j: common_vendor.unref(currentTabName) === "read"
      }, common_vendor.unref(currentTabName) === "read" ? {
        k: common_vendor.f(common_vendor.unref(tabInfo)[common_vendor.unref(currentTabName)].memberList, (item, k0, i0) => {
          return {
            a: "8316d693-3-" + i0 + ",8316d693-0",
            b: common_vendor.p({
              useSkeletonAnimation: true,
              url: item.avatar
            }),
            c: common_vendor.t(item.nick || item.userID),
            d: item.userID
          };
        })
      } : {}) : {}, {
        g: common_vendor.unref(isFirstLoadFinished),
        l: common_vendor.unref(isFirstLoadFinished)
      }, common_vendor.unref(isFirstLoadFinished) ? {
        m: common_vendor.o$1(pullDownFetchMoreData),
        n: common_vendor.p({
          isFetching: common_vendor.unref(isPullDownFetching),
          isTerminateObserve: common_vendor.unref(isStopFetchMore)
        })
      } : {}, {
        o: common_vendor.unref(TUIKit_utils_env.isMobile) ? 1 : "",
        p: common_vendor.unref(TUIKit_utils_env.isUniFrameWork) ? 1 : "",
        q: common_vendor.unref(TUIKit_utils_env.isMobile) && common_vendor.unref(isPanelClose) ? 1 : "",
        r: common_vendor.o$1(closeReadReceiptPanel),
        s: common_vendor.p({
          maskColor: "transparent"
        })
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-8316d693"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-list/read-receipt-panel/index.js.map
