import { memo, useMemo, forwardRef, useImperativeHandle } from 'react';
import { ComponentID, PageID } from '../../../../enums';
import { useAmityComponent, useCommunity } from '../../../../hooks';
import { usePosts } from '../../../../hooks/usePosts';
import { Empty } from '../../../../components';
import ImageGallery from '../../../../elements/ImageGallery/ImageGallery';
import ImageFeedSkeleton from '../../../../components/ImageFeedSkeleton/ImageFeedSkeleton';
const pageLimit = 10;
const AmityCommunityImageFeedComponent = /*#__PURE__*/forwardRef(({
  pageId = PageID.WildCardPage,
  communityId
}, ref) => {
  const componentId = ComponentID.community_image_feed;
  const {
    community
  } = useCommunity(communityId);
  const {
    accessibilityId,
    themeStyles
  } = useAmityComponent({
    pageId,
    componentId
  });
  const imageDataTypes = useMemo(() => ['image'], []);
  const {
    posts,
    loading,
    onNextPage
  } = usePosts({
    targetId: communityId,
    targetType: 'community',
    dataTypes: imageDataTypes,
    limit: pageLimit
  });
  const handleLoadMore = () => {
    if (onNextPage) {
      onNextPage();
    }
  };
  useImperativeHandle(ref, () => ({
    handleLoadMore
  }));
  if (!(community !== null && community !== void 0 && community.isJoined) && !(community !== null && community !== void 0 && community.isPublic)) {
    return /*#__PURE__*/React.createElement(Empty, {
      heightPercent: 0.3
    }, /*#__PURE__*/React.createElement(Empty.Content, {
      title: "This community is private",
      description: "Join this community to see its content and members.",
      icon: "private"
    }));
  }
  if (loading && (!posts || (posts === null || posts === void 0 ? void 0 : posts.length) === 0)) {
    return /*#__PURE__*/React.createElement(ImageFeedSkeleton, {
      themeStyles: themeStyles
    });
  }
  if (!loading && (posts === null || posts === void 0 ? void 0 : posts.length) === 0) {
    return /*#__PURE__*/React.createElement(Empty, {
      heightPercent: 0.3
    }, /*#__PURE__*/React.createElement(Empty.Content, {
      title: "No photos yet",
      icon: "image"
    }));
  }
  return /*#__PURE__*/React.createElement(ImageGallery, {
    isLoading: loading,
    posts: posts,
    onNextPage: onNextPage,
    accessibilityId: accessibilityId,
    themeStyles: themeStyles
  });
});
export default /*#__PURE__*/memo(AmityCommunityImageFeedComponent);
//# sourceMappingURL=ImageFeed.js.map