import { useCallback, useState } from 'react';
import { View, ScrollView, RefreshControl } from 'react-native';
import { useStyles } from './styles';
import { PageID } from '../../../../enums';
import AmityRecommendedCommunityComponent from '../RecommendedCommunities';
import AmityCommunityCategoriesComponent from '../Categories';
import AmityTrendingCommunitiesComponent from '../TrendingCommunities';
import AmityExploreCommunityEmptyComponent from '../ExploreCommunityEmpty';
import AmityExploreEmptyComponent from '../ExploreEmpty';
import { useExplore } from '../../../../providers/ExploreProvider';
import ExploreLoadingSkeleton from './ExploreLoadingSkeleton/ExploreLoadingSkeleton';
import { useAmityPage } from '../../../../hooks';
import ErrorComponent from '../../../../components/ErrorComponent/ErrorComponent';
const AmityExploreComponent = ({
  pageId = PageID.WildCardPage
}) => {
  const styles = useStyles();
  const {
    themeStyles
  } = useAmityPage({
    pageId
  });
  const [refreshing, setRefreshing] = useState(false);
  const {
    refresh,
    isLoading,
    isCategoryEmpty,
    isRecommendedCommunitiesEmpty,
    isTrendingCommunitiesEmpty,
    isAllError,
    isAllCommunitiesError
  } = useExplore();
  const onRefresh = () => {
    setRefreshing(true);
    refresh();
    setRefreshing(false);
  };
  const isNothingToShow = !isLoading && isCategoryEmpty && isRecommendedCommunitiesEmpty && isTrendingCommunitiesEmpty;
  const isNoCommunities = !isLoading && isRecommendedCommunitiesEmpty && isTrendingCommunitiesEmpty && !isCategoryEmpty;
  const renderError = useCallback(() => {
    return /*#__PURE__*/React.createElement(ErrorComponent, {
      themeStyle: themeStyles,
      title: "Something went wrong",
      description: "Please try again."
    });
  }, [themeStyles]);
  if (isAllError) {
    return renderError();
  }
  return /*#__PURE__*/React.createElement(ScrollView, {
    style: styles.container,
    refreshControl: /*#__PURE__*/React.createElement(RefreshControl, {
      refreshing: refreshing,
      onRefresh: onRefresh,
      colors: ['lightblue'],
      tintColor: "lightblue"
    })
  }, isLoading && /*#__PURE__*/React.createElement(ExploreLoadingSkeleton, {
    themeStyles: themeStyles
  }), isNothingToShow ? /*#__PURE__*/React.createElement(View, {
    style: styles.emptyContainer
  }, /*#__PURE__*/React.createElement(AmityExploreEmptyComponent, {
    pageId: pageId
  })) : /*#__PURE__*/React.createElement(React.Fragment, null, !isCategoryEmpty && /*#__PURE__*/React.createElement(View, {
    style: styles.categoriesContainer
  }, /*#__PURE__*/React.createElement(AmityCommunityCategoriesComponent, {
    pageId: pageId
  })), /*#__PURE__*/React.createElement(View, {
    style: styles.communitiesSection
  }, isAllCommunitiesError ? /*#__PURE__*/React.createElement(View, {
    style: styles.sectionErrorContainer
  }, renderError()) : isNoCommunities ? /*#__PURE__*/React.createElement(View, {
    style: styles.emptyContainer
  }, /*#__PURE__*/React.createElement(AmityExploreCommunityEmptyComponent, {
    pageId: pageId
  })) : /*#__PURE__*/React.createElement(React.Fragment, null, !isRecommendedCommunitiesEmpty && /*#__PURE__*/React.createElement(View, {
    style: styles.recommendContainer
  }, /*#__PURE__*/React.createElement(AmityRecommendedCommunityComponent, {
    pageId: pageId
  })), !isTrendingCommunitiesEmpty && /*#__PURE__*/React.createElement(View, {
    style: styles.trendingContainer
  }, /*#__PURE__*/React.createElement(AmityTrendingCommunitiesComponent, {
    pageId: pageId
  }))))));
};
export default AmityExploreComponent;
//# sourceMappingURL=Explore.js.map