"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _styles = require("./styles");
var _reactNative = require("react-native");
var _useCommunityMemberCollection = require("../../../../../hooks/collections/community/useCommunityMemberCollection");
var _MemberItem = _interopRequireDefault(require("../MemberItem"));
var _MemberSkeleton = _interopRequireDefault(require("../../../shared/components/MemberSkeleton"));
var _constants = require("../../../../../../core/constants");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function useModeratorList({
  community
}) {
  const {
    styles,
    theme
  } = (0, _styles.useStyles)();
  const memberCollection = (0, _useCommunityMemberCollection.useCommunityMemberCollection)({
    enabled: !!community,
    params: {
      communityId: community === null || community === void 0 ? void 0 : community.communityId,
      roles: [_constants.MemberRoles.COMMUNITY_MODERATOR],
      limit: 20
    }
  });
  return {
    styles,
    theme,
    collection: memberCollection
  };
}
const ModeratorList = ({
  community
}) => {
  const {
    styles,
    collection
  } = useModeratorList({
    community
  });
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.container
  }, collection.isLoading && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.skeletonContainer
  }, /*#__PURE__*/React.createElement(_MemberSkeleton.default, null), /*#__PURE__*/React.createElement(_MemberSkeleton.default, null), /*#__PURE__*/React.createElement(_MemberSkeleton.default, null)), /*#__PURE__*/React.createElement(_reactNative.FlatList, {
    data: collection.data,
    showsVerticalScrollIndicator: false,
    contentContainerStyle: styles.contentContainer,
    onEndReached: () => {
      var _collection$fetchNext;
      if (collection.hasNextPage && !collection.isFetchingNextPage) (_collection$fetchNext = collection.fetchNextPage) === null || _collection$fetchNext === void 0 || _collection$fetchNext.call(collection);
    },
    ListFooterComponent: collection.isFetchingNextPage ? /*#__PURE__*/React.createElement(_reactNative.View, {
      style: styles.skeletonContainer
    }, /*#__PURE__*/React.createElement(_MemberSkeleton.default, null), /*#__PURE__*/React.createElement(_MemberSkeleton.default, null), /*#__PURE__*/React.createElement(_MemberSkeleton.default, null)) : null,
    renderItem: ({
      item
    }) => /*#__PURE__*/React.createElement(_MemberItem.default, {
      member: item,
      key: item.userId,
      refreshMembers: collection.refetch,
      communityId: community.communityId
    })
  }));
};
var _default = exports.default = ModeratorList;
//# sourceMappingURL=ModeratorList.js.map