import {
  PostsListContainer
} from "./chunk-W5LWTUM2.mjs";
import {
  PostItem_default
} from "./chunk-SM2J62MD.mjs";
import {
  useContentPosts
} from "./chunk-4XBVIJ24.mjs";

// tmp-babel/content-feed/web/PostList/index.js
import React from "react";
import { LoadingState } from "@baseapp-frontend/design-system/components/web/displays";
import { Box } from "@mui/material";
import { Virtuoso } from "react-virtuoso";
import { jsx as _jsx } from "react/jsx-runtime";
var Scroller = /* @__PURE__ */ React.forwardRef(function(_ref, ref) {
  var style = _ref.style, children = _ref.children;
  return /* @__PURE__ */ _jsx(PostsListContainer, {
    style,
    ref,
    children
  });
});
var PostList = function PostList2(_ref2) {
  var preloadedQuery = _ref2.preloadedQuery;
  var _useContentPosts = useContentPosts(preloadedQuery), contentPosts = _useContentPosts.data.contentPosts, loadNext = _useContentPosts.loadNext, isLoadingNext = _useContentPosts.isLoadingNext, hasNext = _useContentPosts.hasNext;
  var renderPostItem = function renderPostItem2(post) {
    if (!(post !== null && post !== void 0 && post.node)) return null;
    return /* @__PURE__ */ _jsx(PostItem_default, {
      postRef: post.node
    });
  };
  var renderLoadingState = function renderLoadingState2() {
    if (!isLoadingNext) return /* @__PURE__ */ _jsx(Box, {
      sx: {
        paddingTop: 3
      }
    });
    return /* @__PURE__ */ _jsx(LoadingState, {
      sx: {
        paddingTop: 3,
        paddingBottom: 1
      },
      CircularProgressProps: {
        size: 15
      },
      "aria-label": "loading more posts"
    });
  };
  var renderHeader = function renderHeader2() {
    var _contentPosts$edges;
    if ((contentPosts === null || contentPosts === void 0 || (_contentPosts$edges = contentPosts.edges) === null || _contentPosts$edges === void 0 ? void 0 : _contentPosts$edges.length) === 0) return null;
    return /* @__PURE__ */ _jsx("div", {
      className: "h-2"
    });
  };
  return /* @__PURE__ */ _jsx(Virtuoso, {
    useWindowScroll: true,
    data: contentPosts === null || contentPosts === void 0 ? void 0 : contentPosts.edges,
    overscan: 2e3,
    itemContent: function itemContent(_index, post) {
      return renderPostItem(post);
    },
    components: {
      Header: renderHeader,
      Footer: renderLoadingState,
      List: Scroller
    },
    endReached: function endReached() {
      if (hasNext) {
        loadNext(5);
      }
    }
  });
};
var PostList_default = PostList;

export {
  PostList_default
};
//# sourceMappingURL=chunk-FCWXZZIF.mjs.map