"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _react = require("react");
var _styles = require("./styles");
var _enums = require("../../enums");
var _hooks = require("../../hooks");
var _BackButtonIconElement = _interopRequireDefault(require("../../elements/BackButtonIconElement/BackButtonIconElement"));
var _CategoryTitle = _interopRequireDefault(require("../../elements/CategoryTitle/CategoryTitle"));
var _CommunityRowItem = _interopRequireDefault(require("../../components/CommunityRowItem/CommunityRowItem"));
var _native = require("@react-navigation/native");
var _CommunityEmptyTitle = _interopRequireDefault(require("../../elements/CommunityEmptyTitle/CommunityEmptyTitle"));
var _CommunityEmptyImage = _interopRequireDefault(require("../../elements/CommunityEmptyImage/CommunityEmptyImage"));
var _CommunityListSkeleton = _interopRequireDefault(require("../../components/CommunityListSkeleton/CommunityListSkeleton"));
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const AmityCommunitiesByCategoryPage = ({
  route
}) => {
  const pageId = _enums.PageID.communities_by_category_page;
  const {
    category
  } = route.params;
  const {
    accessibilityId,
    themeStyles
  } = (0, _hooks.useAmityPage)({
    pageId
  });
  const {
    communities,
    loading,
    onNextCommunityPage
  } = (0, _hooks.useCommunities)({
    categoryId: category.categoryId,
    membership: 'all'
  });
  const styles = (0, _styles.useStyles)(themeStyles);
  const navigation = (0, _native.useNavigation)();
  const onPressCommunity = (0, _react.useCallback)(({
    communityId
  }) => {
    navigation.navigate('CommunityProfilePage', {
      communityId
    });
  }, [navigation]);
  return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    testID: accessibilityId,
    style: styles.safeArea
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.header
  }, /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    onPress: () => navigation.goBack()
  }, /*#__PURE__*/React.createElement(_BackButtonIconElement.default, {
    pageID: pageId,
    style: styles.headerIcon
  })), /*#__PURE__*/React.createElement(_CategoryTitle.default, {
    title: category.name,
    pageId: pageId
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.empty
  })), loading && !communities && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.loadingContainer
  }, /*#__PURE__*/React.createElement(_CommunityListSkeleton.default, {
    themeStyle: themeStyles,
    amount: 12,
    hasTitle: false
  })), !loading && (communities === null || communities === void 0 ? void 0 : communities.length) === 0 && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.emptyMessage
  }, /*#__PURE__*/React.createElement(_CommunityEmptyImage.default, {
    pageId: pageId
  }), /*#__PURE__*/React.createElement(_CommunityEmptyTitle.default, {
    pageId: pageId
  })), (communities === null || communities === void 0 ? void 0 : communities.length) > 0 && /*#__PURE__*/React.createElement(_reactNative.FlatList, {
    data: communities,
    renderItem: ({
      item
    }) => /*#__PURE__*/React.createElement(_reactNative.Pressable, {
      onPress: () => onPressCommunity({
        communityId: item.communityId
      })
    }, /*#__PURE__*/React.createElement(_CommunityRowItem.default, {
      community: item,
      pageId: pageId,
      showJoinButton: false
    })),
    keyExtractor: item => item.communityId,
    contentContainerStyle: styles.listContent,
    onEndReached: () => onNextCommunityPage === null || onNextCommunityPage === void 0 ? void 0 : onNextCommunityPage(),
    onEndReachedThreshold: 0.5,
    ListFooterComponent: loading ? /*#__PURE__*/React.createElement(_CommunityListSkeleton.default, {
      themeStyle: themeStyles,
      amount: 4
    }) : null
  }));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(AmityCommunitiesByCategoryPage);
//# sourceMappingURL=index.js.map