import { useCallback } from 'react';
import { View, FlatList, Pressable } from 'react-native';
import CommunityRowItem from '../CommunityRowItem/CommunityRowItem';
import CommunityListSkeleton from '../CommunityListSkeleton/CommunityListSkeleton';
import { ComponentID, PageID } from '../../enums';
import { useAmityComponent } from '../../hooks';
import { useNavigation } from '@react-navigation/native';
const CommunitySearchResult = ({
  pageId = PageID.WildCardPage,
  componentId = ComponentID.WildCardComponent,
  communities,
  isFirstTimeLoading = false,
  isLoading = false,
  onNextPage,
  onPressCommunity
}) => {
  const navigation = useNavigation();
  const {
    themeStyles
  } = 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 = useCallback(({
    communityId
  }) => {
    navigation.navigate('CommunityProfilePage', {
      communityId
    });
  }, [navigation]);
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container
  }, isFirstTimeLoading && /*#__PURE__*/React.createElement(View, {
    style: styles.listSkeleton
  }, /*#__PURE__*/React.createElement(CommunityListSkeleton, {
    themeStyle: themeStyles,
    amount: 12,
    hasTitle: false
  })), /*#__PURE__*/React.createElement(FlatList, {
    onEndReached: () => {
      onNextPage === null || onNextPage === void 0 || onNextPage();
    },
    data: communities,
    renderItem: ({
      item
    }) => /*#__PURE__*/React.createElement(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, {
      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, {
      themeStyle: themeStyles,
      amount: 4,
      hasTitle: false
    }) : null
  }));
};
export default CommunitySearchResult;
//# sourceMappingURL=CommunitySearchResult.js.map