"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Feed = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _Divider = _interopRequireDefault(require("../../../../../components/Divider"));
var _PostFeedSkeleton = _interopRequireDefault(require("../../../../../components/PostFeedSkeleton"));
var _Content = _interopRequireDefault(require("../../../../post/components/Content"));
var _AmityPostContentComponentStyle = require("../../../../../enums/AmityPostContentComponentStyle");
var _styles = require("./styles");
var _Gallery = require("../../../../../components/Gallery");
var _useFeed = require("./hooks/useFeed");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const Feed = exports.Feed = /*#__PURE__*/(0, _react.forwardRef)(function Feed({
  userId,
  isBrand,
  isUserLoading
}, ref) {
  const {
    styles
  } = (0, _styles.useStyles)();
  const {
    feedId,
    posts,
    hasMore,
    isLoading,
    isLoadingFirstPage,
    isBlockedByMe,
    isPrivate,
    emptyConfig,
    privateConfig,
    privateInfoConfig,
    blockedConfig,
    blockedInfoConfig
  } = (0, _useFeed.useFeed)({
    userId,
    isBrand,
    isUserLoading,
    ref
  });
  if (isBlockedByMe) {
    return /*#__PURE__*/React.createElement(_reactNative.View, {
      testID: feedId,
      style: styles.container
    }, /*#__PURE__*/React.createElement(_Gallery.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(_reactNative.View, {
      testID: feedId,
      style: styles.container
    }, /*#__PURE__*/React.createElement(_Gallery.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(_reactNative.View, {
    testID: feedId,
    style: styles.container
  }, /*#__PURE__*/React.createElement(_reactNative.FlatList, {
    data: posts ?? [],
    scrollEnabled: false,
    keyExtractor: item => item.postId.toString(),
    viewabilityConfig: {
      viewAreaCoveragePercentThreshold: 60
    },
    ListFooterComponent: isLoading || isLoadingFirstPage ? /*#__PURE__*/React.createElement(_PostFeedSkeleton.default, null) : null,
    ListEmptyComponent: isLoading || isLoadingFirstPage ? null : /*#__PURE__*/React.createElement(_Gallery.Gallery.Empty, {
      heightPercent: 0.4,
      title: emptyConfig === null || emptyConfig === void 0 ? void 0 : emptyConfig.text,
      icon: "post"
    }),
    renderItem: ({
      item,
      index
    }) => /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_Content.default, {
      post: item,
      isCommunityNameShown: false,
      AmityPostContentComponentStyle: _AmityPostContentComponentStyle.AmityPostContentComponentStyleEnum.feed
    }), index === posts.length - 1 && !hasMore ? null : /*#__PURE__*/React.createElement(_Divider.default, null))
  }));
});
//# sourceMappingURL=Feed.js.map