"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 _hooks = require("../../../../hooks");
var _enums = require("../../../../enums");
var _native = require("@react-navigation/native");
var _BehaviourProvider = require("../../../../providers/BehaviourProvider");
var _CommunitySearchResult = _interopRequireDefault(require("../../../../components/CommunitySearchResult/CommunitySearchResult"));
var _icons = require("../../../../../core/assets/icons");
var _Typography = require("../../../../../core/components/Typography/Typography");
var _reactNativeSvg = require("react-native-svg");
var _Button = require("../../../../components/Button/Button");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const AmityMyCommunitiesComponent = ({
  pageId = _enums.PageID.WildCardPage
}) => {
  const componentId = _enums.ComponentID.my_communities;
  const {
    isExcluded,
    accessibilityId,
    themeStyles
  } = (0, _hooks.useAmityComponent)({
    pageId,
    componentId
  });
  const navigation = (0, _native.useNavigation)();
  const {
    AmityMyCommunitiesComponentBehaviour
  } = (0, _BehaviourProvider.useBehaviour)();
  const styles = (0, _styles.useStyles)(themeStyles);
  const {
    communities,
    onNextCommunityPage,
    loading
  } = (0, _hooks.useCommunities)();
  const onPressCommunity = (0, _react.useCallback)(({
    communityId
  }) => {
    if (AmityMyCommunitiesComponentBehaviour.onPressCommunity) return AmityMyCommunitiesComponentBehaviour.onPressCommunity();
    navigation.navigate('CommunityProfilePage', {
      communityId
    });
  }, [navigation, AmityMyCommunitiesComponentBehaviour]);
  const onPressCreateCommunity = (0, _react.useCallback)(() => {
    navigation.navigate('CreateCommunity');
  }, [navigation]);

  // Empty state cannot be customized
  const renderEmptyState = (0, _react.useCallback)(() => {
    return /*#__PURE__*/React.createElement(_reactNative.View, {
      style: styles.emptyContainer
    }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
      xml: (0, _icons.emptyCommunity)({})
    }), /*#__PURE__*/React.createElement(_Typography.Typography.BodyBold, {
      style: styles.emptyTitleText
    }, 'No community yet'), /*#__PURE__*/React.createElement(_Typography.Typography.Caption, {
      style: styles.emptyDescriptionText
    }, "Let's create your own communities"), /*#__PURE__*/React.createElement(_Button.Button, {
      type: "primary",
      icon: (0, _icons.plus)(),
      style: styles.createCommunityButton,
      onPress: onPressCreateCommunity
    }, /*#__PURE__*/React.createElement(_Typography.Typography.BodyBold, {
      style: styles.createCommunityButtonText
    }, 'Create community')));
  }, [styles, themeStyles, onPressCreateCommunity]);
  if (isExcluded) return null;
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.container,
    testID: accessibilityId,
    accessibilityLabel: accessibilityId
  }, !loading && (communities === null || communities === void 0 ? void 0 : communities.length) === 0 ? renderEmptyState() : /*#__PURE__*/React.createElement(_CommunitySearchResult.default, {
    pageId: pageId,
    componentId: componentId,
    isFirstTimeLoading: loading && !communities,
    isLoading: loading,
    communities: communities,
    onPressCommunity: onPressCommunity,
    onNextPage: onNextCommunityPage
  }));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(AmityMyCommunitiesComponent);
//# sourceMappingURL=MyCommunities.js.map