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); }
import { memo } from 'react';
import { ComponentID, ElementID, PageID } from '../../enums/enumUIKitID';
import { useAmityElement, useJoinCommunity } from '../../hooks';
import { Button, BUTTON_SIZE } from '../../components/Button/Button';
import { plus } from '../../../core/assets/icons';
import { useCustomRankingGlobalFeed } from '../../hooks/useCustomRankingGlobalFeed';
const CommunityJoinButton = ({
  pageId = PageID.WildCardPage,
  componentId = ComponentID.WildCardComponent,
  communityId,
  size = BUTTON_SIZE.SMALL,
  ...props
}) => {
  const {
    config,
    accessibilityId,
    isExcluded,
    themeStyles
  } = useAmityElement({
    pageId,
    componentId,
    elementId: ElementID.community_join_button
  });
  const {
    refresh,
    globalFeedPosts
  } = useCustomRankingGlobalFeed({
    enabled: false
  });
  const {
    joinCommunity,
    isPending
  } = useJoinCommunity({
    onSuccess: () => {
      globalFeedPosts.length === 0 && refresh();
    }
  });
  const handleJoinCommunity = () => {
    if (!communityId) return;
    joinCommunity(communityId);
  };
  if (isExcluded) return null;
  return /*#__PURE__*/React.createElement(Button, _extends({
    testID: accessibilityId,
    type: "primary",
    icon: plus(),
    iconProps: {
      xml: 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');
};
export default /*#__PURE__*/memo(CommunityJoinButton);
//# sourceMappingURL=CommunityJoinButtonElement.js.map