"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _CommunityRowItem = _interopRequireDefault(require("../CommunityRowItem/CommunityRowItem"));
var _CommunityListSkeleton = _interopRequireDefault(require("../CommunityListSkeleton/CommunityListSkeleton"));
var _enums = require("../../enums");
var _hooks = require("../../hooks");
var _native = require("@react-navigation/native");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const CommunitySearchResult = ({
  pageId = _enums.PageID.WildCardPage,
  componentId = _enums.ComponentID.WildCardComponent,
  communities,
  isFirstTimeLoading = false,
  isLoading = false,
  onNextPage,
  onPressCommunity
}) => {
  const navigation = (0, _native.useNavigation)();
  const {
    themeStyles
  } = (0, _hooks.useAmityComponent)({
    pageId,
    componentId
  });
  const styles = {
    container: {
      flex: 1
    },
    listSkeleton: {
      paddingTop: 16,
      paddingHorizontal: 16
    },
    list: {
      flex: 1,
      paddingTop: 16
    },
    listContent: {
      paddingHorizontal: 16,
      gap: 16
    }
  };
  const onNavigateCommunity = (0, _react.useCallback)(({
    communityId
  }) => {
    navigation.navigate('CommunityProfilePage', {
      communityId
    });
  }, [navigation]);
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.container
  }, isFirstTimeLoading && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.listSkeleton
  }, /*#__PURE__*/React.createElement(_CommunityListSkeleton.default, {
    themeStyle: themeStyles,
    amount: 12,
    hasTitle: false
  })), /*#__PURE__*/React.createElement(_reactNative.FlatList, {
    onEndReached: () => {
      onNextPage === null || onNextPage === void 0 || onNextPage();
    },
    data: communities,
    renderItem: ({
      item
    }) => /*#__PURE__*/React.createElement(_reactNative.Pressable, {
      onPress: () => {
        if (onPressCommunity) onPressCommunity === null || onPressCommunity === void 0 || onPressCommunity({
          communityId: item.communityId,
          communityName: item.displayName
        });else onNavigateCommunity({
          communityId: item.communityId
        });
      }
    }, /*#__PURE__*/React.createElement(_CommunityRowItem.default, {
      community: item,
      pageId: pageId,
      componentId: componentId,
      showJoinButton: false
    })),
    keyExtractor: (item, index) => (item.communityId ?? index).toString() + '_' + index,
    onEndReachedThreshold: 0.5,
    style: styles.list,
    contentContainerStyle: styles.listContent,
    ListFooterComponent: isLoading && communities ? /*#__PURE__*/React.createElement(_CommunityListSkeleton.default, {
      themeStyle: themeStyles,
      amount: 4,
      hasTitle: false
    }) : null
  }));
};
var _default = exports.default = CommunitySearchResult;
//# sourceMappingURL=CommunitySearchResult.js.map