"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _enums = require("../../../../enums");
var _hooks = require("../../../../hooks");
var _usePosts = require("../../../../hooks/usePosts");
var _components = require("../../../../components");
var _ImageGallery = _interopRequireDefault(require("../../../../elements/ImageGallery/ImageGallery"));
var _ImageFeedSkeleton = _interopRequireDefault(require("../../../../components/ImageFeedSkeleton/ImageFeedSkeleton"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const pageLimit = 10;
const AmityCommunityImageFeedComponent = /*#__PURE__*/(0, _react.forwardRef)(({
  pageId = _enums.PageID.WildCardPage,
  communityId
}, ref) => {
  const componentId = _enums.ComponentID.community_image_feed;
  const {
    community
  } = (0, _hooks.useCommunity)(communityId);
  const {
    accessibilityId,
    themeStyles
  } = (0, _hooks.useAmityComponent)({
    pageId,
    componentId
  });
  const imageDataTypes = (0, _react.useMemo)(() => ['image'], []);
  const {
    posts,
    loading,
    onNextPage
  } = (0, _usePosts.usePosts)({
    targetId: communityId,
    targetType: 'community',
    dataTypes: imageDataTypes,
    limit: pageLimit
  });
  const handleLoadMore = () => {
    if (onNextPage) {
      onNextPage();
    }
  };
  (0, _react.useImperativeHandle)(ref, () => ({
    handleLoadMore
  }));
  if (!(community !== null && community !== void 0 && community.isJoined) && !(community !== null && community !== void 0 && community.isPublic)) {
    return /*#__PURE__*/React.createElement(_components.Empty, {
      heightPercent: 0.3
    }, /*#__PURE__*/React.createElement(_components.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.default, {
      themeStyles: themeStyles
    });
  }
  if (!loading && (posts === null || posts === void 0 ? void 0 : posts.length) === 0) {
    return /*#__PURE__*/React.createElement(_components.Empty, {
      heightPercent: 0.3
    }, /*#__PURE__*/React.createElement(_components.Empty.Content, {
      title: "No photos yet",
      icon: "image"
    }));
  }
  return /*#__PURE__*/React.createElement(_ImageGallery.default, {
    isLoading: loading,
    posts: posts,
    onNextPage: onNextPage,
    accessibilityId: accessibilityId,
    themeStyles: themeStyles
  });
});
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(AmityCommunityImageFeedComponent);
//# sourceMappingURL=ImageFeed.js.map