"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _styles = require("./styles");
var _enums = require("../../../../enums");
var _RecommendedCommunities = _interopRequireDefault(require("../RecommendedCommunities"));
var _Categories = _interopRequireDefault(require("../Categories"));
var _TrendingCommunities = _interopRequireDefault(require("../TrendingCommunities"));
var _ExploreCommunityEmpty = _interopRequireDefault(require("../ExploreCommunityEmpty"));
var _ExploreEmpty = _interopRequireDefault(require("../ExploreEmpty"));
var _ExploreProvider = require("../../../../providers/ExploreProvider");
var _ExploreLoadingSkeleton = _interopRequireDefault(require("./ExploreLoadingSkeleton/ExploreLoadingSkeleton"));
var _hooks = require("../../../../hooks");
var _ErrorComponent = _interopRequireDefault(require("../../../../components/ErrorComponent/ErrorComponent"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const AmityExploreComponent = ({
  pageId = _enums.PageID.WildCardPage
}) => {
  const styles = (0, _styles.useStyles)();
  const {
    themeStyles
  } = (0, _hooks.useAmityPage)({
    pageId
  });
  const [refreshing, setRefreshing] = (0, _react.useState)(false);
  const {
    refresh,
    isLoading,
    isCategoryEmpty,
    isRecommendedCommunitiesEmpty,
    isTrendingCommunitiesEmpty,
    isAllError,
    isAllCommunitiesError
  } = (0, _ExploreProvider.useExplore)();
  const onRefresh = () => {
    setRefreshing(true);
    refresh();
    setRefreshing(false);
  };
  const isNothingToShow = !isLoading && isCategoryEmpty && isRecommendedCommunitiesEmpty && isTrendingCommunitiesEmpty;
  const isNoCommunities = !isLoading && isRecommendedCommunitiesEmpty && isTrendingCommunitiesEmpty && !isCategoryEmpty;
  const renderError = (0, _react.useCallback)(() => {
    return /*#__PURE__*/React.createElement(_ErrorComponent.default, {
      themeStyle: themeStyles,
      title: "Something went wrong",
      description: "Please try again."
    });
  }, [themeStyles]);
  if (isAllError) {
    return renderError();
  }
  return /*#__PURE__*/React.createElement(_reactNative.ScrollView, {
    style: styles.container,
    refreshControl: /*#__PURE__*/React.createElement(_reactNative.RefreshControl, {
      refreshing: refreshing,
      onRefresh: onRefresh,
      colors: ['lightblue'],
      tintColor: "lightblue"
    })
  }, isLoading && /*#__PURE__*/React.createElement(_ExploreLoadingSkeleton.default, {
    themeStyles: themeStyles
  }), isNothingToShow ? /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.emptyContainer
  }, /*#__PURE__*/React.createElement(_ExploreEmpty.default, {
    pageId: pageId
  })) : /*#__PURE__*/React.createElement(React.Fragment, null, !isCategoryEmpty && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.categoriesContainer
  }, /*#__PURE__*/React.createElement(_Categories.default, {
    pageId: pageId
  })), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.communitiesSection
  }, isAllCommunitiesError ? /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.sectionErrorContainer
  }, renderError()) : isNoCommunities ? /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.emptyContainer
  }, /*#__PURE__*/React.createElement(_ExploreCommunityEmpty.default, {
    pageId: pageId
  })) : /*#__PURE__*/React.createElement(React.Fragment, null, !isRecommendedCommunitiesEmpty && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.recommendContainer
  }, /*#__PURE__*/React.createElement(_RecommendedCommunities.default, {
    pageId: pageId
  })), !isTrendingCommunitiesEmpty && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.trendingContainer
  }, /*#__PURE__*/React.createElement(_TrendingCommunities.default, {
    pageId: pageId
  }))))));
};
var _default = exports.default = AmityExploreComponent;
//# sourceMappingURL=Explore.js.map