import { useStyles } from './styles';
import { FlatList, View } from 'react-native';
import { useCommunityMemberCollection } from '../../../../../hooks/collections/community/useCommunityMemberCollection';
import MemberItem from '../MemberItem';
import MemberSkeleton from '../../../shared/components/MemberSkeleton';
import { MemberRoles } from '../../../../../../core/constants';
function useModeratorList({
  community
}) {
  const {
    styles,
    theme
  } = useStyles();
  const memberCollection = useCommunityMemberCollection({
    enabled: !!community,
    params: {
      communityId: community === null || community === void 0 ? void 0 : community.communityId,
      roles: [MemberRoles.COMMUNITY_MODERATOR],
      limit: 20
    }
  });
  return {
    styles,
    theme,
    collection: memberCollection
  };
}
const ModeratorList = ({
  community
}) => {
  const {
    styles,
    collection
  } = useModeratorList({
    community
  });
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container
  }, collection.isLoading && /*#__PURE__*/React.createElement(View, {
    style: styles.skeletonContainer
  }, /*#__PURE__*/React.createElement(MemberSkeleton, null), /*#__PURE__*/React.createElement(MemberSkeleton, null), /*#__PURE__*/React.createElement(MemberSkeleton, null)), /*#__PURE__*/React.createElement(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(View, {
      style: styles.skeletonContainer
    }, /*#__PURE__*/React.createElement(MemberSkeleton, null), /*#__PURE__*/React.createElement(MemberSkeleton, null), /*#__PURE__*/React.createElement(MemberSkeleton, null)) : null,
    renderItem: ({
      item
    }) => /*#__PURE__*/React.createElement(MemberItem, {
      member: item,
      key: item.userId,
      refreshMembers: collection.refetch,
      communityId: community.communityId
    })
  }));
};
export default ModeratorList;
//# sourceMappingURL=ModeratorList.js.map