"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../_vendor/@legendapp/state/index.cjs");
const messageStore = require("./message-store.cjs");
const paginationStore$ = index.observable({
  // 当前页码（从 0 开始）
  currentPage: 0,
  // 是否还有更多数据
  hasMore: true,
  // 是否正在加载
  isLoading: false,
  // 最后加载的游标（用于游标式分页）
  lastLoadedCursor: void 0,
  // 每页大小
  pageSize: 10,
  // 总数据量
  totalCount: 0
});
const paginationComputed$ = index.observable({
  // 是否还有更多消息
  hasMoreMessages: () => {
    return paginationStore$.hasMore.get();
  },
  // 是否正在加载消息
  isLoadingMessages: () => {
    return paginationStore$.isLoading.get();
  },
  // 加载进度（0-1）
  progress: () => {
    const current = paginationStore$.currentPage.get();
    const total = Math.ceil(paginationStore$.totalCount.get() / paginationStore$.pageSize.get());
    return total > 0 ? current / total : 0;
  }
});
const paginationActions = {
  // 设置加载状态
  setPaginationLoading: (isLoading) => {
    paginationStore$.isLoading.set(isLoading);
  },
  // 更新分页信息
  updatePagination: (hasMore, totalCount, cursor, isInitial = false) => {
    paginationStore$.hasMore.set(hasMore);
    paginationStore$.totalCount.set(totalCount);
    paginationStore$.isLoading.set(false);
    if (cursor) {
      paginationStore$.lastLoadedCursor.set(cursor);
    }
    if (isInitial) {
      paginationStore$.currentPage.set(1);
    } else {
      const currentPage = paginationStore$.currentPage.peek();
      paginationStore$.currentPage.set(currentPage + 1);
    }
  },
  // 重置分页状态
  resetPagination: () => {
    paginationStore$.currentPage.set(0);
    paginationStore$.hasMore.set(true);
    paginationStore$.isLoading.set(false);
    paginationStore$.lastLoadedCursor.set(void 0);
    paginationStore$.totalCount.set(0);
  },
  // 设置每页大小
  // ❌ 未使用
  setPageSize: (size) => {
    paginationStore$.pageSize.set(size);
  },
  // 递增页码
  // ❌ 未使用
  incrementPage: (increment = 1) => {
    const currentPage = paginationStore$.currentPage.peek();
    paginationStore$.currentPage.set(currentPage + increment);
  },
  // 加载错误时调用
  loadError: () => {
    paginationStore$.isLoading.set(false);
  },
  // 更新总数量
  // ❌ 未使用
  updateTotalCount: (count) => {
    paginationStore$.totalCount.set(Math.max(0, count));
  },
  // 重新计算是否还有更多数据
  // ❌ 未使用
  recalculateHasMore: () => {
    const totalCount = paginationStore$.totalCount.peek();
    const currentPage = paginationStore$.currentPage.peek();
    paginationStore$.pageSize.peek();
    const loadedCount = messageStore.messageStore$.messageOrder.peek().length;
    const hasMore = loadedCount < totalCount || currentPage === 0 && totalCount > 0;
    paginationStore$.hasMore.set(hasMore);
  }
};
exports.paginationActions = paginationActions;
exports.paginationComputed$ = paginationComputed$;
exports.paginationStore$ = paginationStore$;
//# sourceMappingURL=pagination-store.cjs.map
