"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const react = require("../../_vendor/@legendapp/state/react.cjs");
const React = require("react");
const usePagination = require("./hooks/use-pagination.cjs");
const useMessageVirtualizer = require("./hooks/use-message-virtualizer.cjs");
const scrollContainer = require("./components/scroll-container.cjs");
const messageStore = require("../../stores/message-store.cjs");
const paginationStore = require("../../stores/pagination-store.cjs");
const Conversation = react.observer(function Conversation2(props) {
  const {
    className,
    children,
    estimateSize = 120,
    overscan = 5,
    paddingTop = 16,
    paddingBottom = 32,
    chatId,
    onLoadMessages,
    pageSize = 10
  } = props;
  const currentMessages = react.use$(messageStore.messageComputed$.currentMessages);
  const totalCount = react.use$(paginationStore.paginationStore$.totalCount);
  const scrollContainerRef = React.useRef(null);
  const { loadMoreMessages, isLoading, hasMore } = usePagination.usePagination({
    chatId,
    onLoadMessages,
    scrollContainerRef,
    pageSize
  });
  const { virtualizer } = useMessageVirtualizer.useMessageVirtualizer({
    messages: currentMessages,
    scrollContainerRef,
    estimateSize,
    overscan,
    paddingTop,
    paddingBottom
  });
  const handleLoadMore = async () => {
    await loadMoreMessages();
    virtualizer.scrollToIndex(0, { align: "start", behavior: "smooth" });
  };
  const shouldShowLoadMore = hasMore && totalCount > pageSize;
  const shouldShowWelcome = react.use$(messageStore.messageComputed$.shouldShowWelcome);
  if (shouldShowWelcome) return null;
  return /* @__PURE__ */ jsxRuntime.jsx(
    scrollContainer.ScrollContainer,
    {
      className,
      scrollContainerRef,
      virtualizer,
      messages: currentMessages,
      shouldShowLoadMore,
      hasMore,
      isLoading,
      totalCount,
      onLoadMore: handleLoadMore,
      children
    }
  );
});
exports.Conversation = Conversation;
//# sourceMappingURL=conversation.cjs.map
