import { ComponentID, PageID } from '../../../../../enums';
import { useBottomSheet } from '../../../../../../core/stores/slices/bottomSheetSlice';
import { useShareableLink } from '../../../../../../core/hooks/useShareableLink';
import { ShareableLinkModel } from '../../../../../../social/types';
import { CopyLinkAction } from '../../../../../elements/CopyLinkAction';
import { ShareAction } from '../../../../../elements/ShareAction';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import { useFollowInfo } from '../../../../../hooks/objects/user/useFollowInfo';
import useSocialSettings from '../../../../../../core/hooks/useSocialSettings';
import useAuth from '../../../../../../core/hooks/useAuth';
export function usePostShareAction({
  postId,
  postData,
  pageId = PageID.WildCardPage
}) {
  var _postData$creator, _postData$targetCommu;
  const {
    openBottomSheet,
    bottomSheetHeight
  } = useBottomSheet();
  const {
    client
  } = useAuth();
  const {
    socialSettings
  } = useSocialSettings();
  const {
    getShareLink
  } = useShareableLink();
  const myId = client === null || client === void 0 ? void 0 : client.userId;
  const {
    followInfo
  } = 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(ShareableLinkModel.posts, postId) : null;
  const handleSharePress = () => {
    ReactNativeHapticFeedback.trigger('impactHeavy', {
      enableVibrateFallback: true,
      ignoreAndroidSystemSettings: false
    });
    openBottomSheet({
      height: bottomSheetHeight[2],
      content: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CopyLinkAction, {
        link: shareLink,
        pageId: pageId,
        componentId: ComponentID.post_content
      }), /*#__PURE__*/React.createElement(ShareAction, {
        link: shareLink,
        pageId: pageId,
        componentId: ComponentID.post_content
      }))
    });
  };
  return {
    shareLink,
    handleSharePress
  };
}
//# sourceMappingURL=usePostShareAction.js.map