"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _enumUIKitID = require("../../enums/enumUIKitID");
var _hooks = require("../../hooks");
var _Button = require("../../components/Button/Button");
var _icons = require("../../../core/assets/icons");
var _useCustomRankingGlobalFeed = require("../../hooks/useCustomRankingGlobalFeed");
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const CommunityJoinButton = ({
  pageId = _enumUIKitID.PageID.WildCardPage,
  componentId = _enumUIKitID.ComponentID.WildCardComponent,
  communityId,
  size = _Button.BUTTON_SIZE.SMALL,
  ...props
}) => {
  const {
    config,
    accessibilityId,
    isExcluded,
    themeStyles
  } = (0, _hooks.useAmityElement)({
    pageId,
    componentId,
    elementId: _enumUIKitID.ElementID.community_join_button
  });
  const {
    refresh,
    globalFeedPosts
  } = (0, _useCustomRankingGlobalFeed.useCustomRankingGlobalFeed)({
    enabled: false
  });
  const {
    joinCommunity,
    isPending
  } = (0, _hooks.useJoinCommunity)({
    onSuccess: () => {
      globalFeedPosts.length === 0 && refresh();
    }
  });
  const handleJoinCommunity = () => {
    if (!communityId) return;
    joinCommunity(communityId);
  };
  if (isExcluded) return null;
  return /*#__PURE__*/React.createElement(_Button.Button, _extends({
    testID: accessibilityId,
    type: "primary",
    icon: (0, _icons.plus)(),
    iconProps: {
      xml: (0, _icons.plus)(),
      color: themeStyles.isDarkTheme ? themeStyles.colors.base : themeStyles.colors.baseShade4
    },
    onPress: handleJoinCommunity,
    disabled: isPending,
    size: size
  }, props), (config === null || config === void 0 ? void 0 : config.text) || 'Join');
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(CommunityJoinButton);
//# sourceMappingURL=CommunityJoinButtonElement.js.map