"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.usePostShareAction = usePostShareAction;
var _enums = require("../../../../../enums");
var _bottomSheetSlice = require("../../../../../../core/stores/slices/bottomSheetSlice");
var _useShareableLink = require("../../../../../../core/hooks/useShareableLink");
var _types = require("../../../../../../social/types");
var _CopyLinkAction = require("../../../../../elements/CopyLinkAction");
var _ShareAction = require("../../../../../elements/ShareAction");
var _reactNativeHapticFeedback = _interopRequireDefault(require("react-native-haptic-feedback"));
var _useFollowInfo = require("../../../../../hooks/objects/user/useFollowInfo");
var _useSocialSettings = _interopRequireDefault(require("../../../../../../core/hooks/useSocialSettings"));
var _useAuth = _interopRequireDefault(require("../../../../../../core/hooks/useAuth"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function usePostShareAction({
  postId,
  postData,
  pageId = _enums.PageID.WildCardPage
}) {
  var _postData$creator, _postData$targetCommu;
  const {
    openBottomSheet,
    bottomSheetHeight
  } = (0, _bottomSheetSlice.useBottomSheet)();
  const {
    client
  } = (0, _useAuth.default)();
  const {
    socialSettings
  } = (0, _useSocialSettings.default)();
  const {
    getShareLink
  } = (0, _useShareableLink.useShareableLink)();
  const myId = client === null || client === void 0 ? void 0 : client.userId;
  const {
    followInfo
  } = (0, _useFollowInfo.useFollowInfo)({
    userId: (postData === null || postData === void 0 ? void 0 : postData.targetType) === 'user' ? postData === null || postData === void 0 ? void 0 : postData.targetId : undefined,
    enabled: (postData === null || postData === void 0 ? void 0 : postData.targetType) === 'user' && !!(postData !== null && postData !== void 0 && postData.targetId) && (postData === null || postData === void 0 ? void 0 : postData.targetId) !== myId
  });
  const isMyPost = myId === (postData === null || postData === void 0 || (_postData$creator = postData.creator) === null || _postData$creator === void 0 ? void 0 : _postData$creator.userId);
  const isBlocked = (followInfo === null || followInfo === void 0 ? void 0 : followInfo.status) === 'blocked';
  const isFollowing = (followInfo === null || followInfo === void 0 ? void 0 : followInfo.status) === 'accepted';
  const isPrivateNetwork = (socialSettings === null || socialSettings === void 0 ? void 0 : socialSettings.userPrivacySetting) === 'private';
  const canShare = (postData === null || postData === void 0 ? void 0 : postData.targetType) === 'community' ? !!(postData !== null && postData !== void 0 && (_postData$targetCommu = postData.targetCommunity) !== null && _postData$targetCommu !== void 0 && _postData$targetCommu.isPublic) : isMyPost || !isBlocked && (!isPrivateNetwork || isFollowing);
  const shareLink = canShare && postData ? getShareLink(_types.ShareableLinkModel.posts, postId) : null;
  const handleSharePress = () => {
    _reactNativeHapticFeedback.default.trigger('impactHeavy', {
      enableVibrateFallback: true,
      ignoreAndroidSystemSettings: false
    });
    openBottomSheet({
      height: bottomSheetHeight[2],
      content: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_CopyLinkAction.CopyLinkAction, {
        link: shareLink,
        pageId: pageId,
        componentId: _enums.ComponentID.post_content
      }), /*#__PURE__*/React.createElement(_ShareAction.ShareAction, {
        link: shareLink,
        pageId: pageId,
        componentId: _enums.ComponentID.post_content
      }))
    });
  };
  return {
    shareLink,
    handleSharePress
  };
}
//# sourceMappingURL=usePostShareAction.js.map