import { forwardRef } from 'react';
import { View, FlatList } from 'react-native';
import Divider from '../../../../../components/Divider';
import PostFeedSkeleton from '../../../../../components/PostFeedSkeleton';
import AmityPostContentComponent from '../../../../post/components/Content';
import { AmityPostContentComponentStyleEnum } from '../../../../../enums/AmityPostContentComponentStyle';
import { useStyles } from './styles';
import { Gallery } from '../../../../../components/Gallery';
import { useFeed } from './hooks/useFeed';
export const Feed = /*#__PURE__*/forwardRef(function Feed({
  userId,
  isBrand,
  isUserLoading
}, ref) {
  const {
    styles
  } = useStyles();
  const {
    feedId,
    posts,
    hasMore,
    isLoading,
    isLoadingFirstPage,
    isBlockedByMe,
    isPrivate,
    emptyConfig,
    privateConfig,
    privateInfoConfig,
    blockedConfig,
    blockedInfoConfig
  } = useFeed({
    userId,
    isBrand,
    isUserLoading,
    ref
  });
  if (isBlockedByMe) {
    return /*#__PURE__*/React.createElement(View, {
      testID: feedId,
      style: styles.container
    }, /*#__PURE__*/React.createElement(Gallery.Empty, {
      heightPercent: 0.4,
      icon: "block",
      title: blockedConfig === null || blockedConfig === void 0 ? void 0 : blockedConfig.text,
      description: blockedInfoConfig === null || blockedInfoConfig === void 0 ? void 0 : blockedInfoConfig.text
    }));
  }
  if (isPrivate) {
    return /*#__PURE__*/React.createElement(View, {
      testID: feedId,
      style: styles.container
    }, /*#__PURE__*/React.createElement(Gallery.Empty, {
      heightPercent: 0.4,
      icon: "private",
      title: privateConfig === null || privateConfig === void 0 ? void 0 : privateConfig.text,
      description: privateInfoConfig === null || privateInfoConfig === void 0 ? void 0 : privateInfoConfig.text
    }));
  }
  return /*#__PURE__*/React.createElement(View, {
    testID: feedId,
    style: styles.container
  }, /*#__PURE__*/React.createElement(FlatList, {
    data: posts ?? [],
    scrollEnabled: false,
    keyExtractor: item => item.postId.toString(),
    viewabilityConfig: {
      viewAreaCoveragePercentThreshold: 60
    },
    ListFooterComponent: isLoading || isLoadingFirstPage ? /*#__PURE__*/React.createElement(PostFeedSkeleton, null) : null,
    ListEmptyComponent: isLoading || isLoadingFirstPage ? null : /*#__PURE__*/React.createElement(Gallery.Empty, {
      heightPercent: 0.4,
      title: emptyConfig === null || emptyConfig === void 0 ? void 0 : emptyConfig.text,
      icon: "post"
    }),
    renderItem: ({
      item,
      index
    }) => /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(AmityPostContentComponent, {
      post: item,
      isCommunityNameShown: false,
      AmityPostContentComponentStyle: AmityPostContentComponentStyleEnum.feed
    }), index === posts.length - 1 && !hasMore ? null : /*#__PURE__*/React.createElement(Divider, null))
  }));
});
//# sourceMappingURL=Feed.js.map