"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useMenu = useMenu;
var _hooks = require("../../../../../../hooks");
var _enums = require("../../../../../../enums");
var _native = require("@react-navigation/native");
var _icons = require("../../../../../../../core/assets/icons");
var _useShareableLink = require("../../../../../../../core/hooks/useShareableLink");
var _types = require("../../../../../../types");
var _bottomSheetSlice = require("../../../../../../../core/stores/slices/bottomSheetSlice");
var _useAuth = _interopRequireDefault(require("../../../../../../../core/hooks/useAuth"));
var _useFlagUserQuery = require("../../../../../../hooks/queries/useFlagUserQuery");
var _useBlockUser = require("../../../../../../hooks/queries/useBlockUser");
var _objects = require("../../../../../../hooks/objects");
var _BehaviourProvider = require("../../../../../../providers/BehaviourProvider");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function useMenu({
  userId,
  displayName
}) {
  const pageId = _enums.PageID.user_profile_page;
  const {
    client
  } = (0, _useAuth.default)();
  const {
    getShareLink
  } = (0, _useShareableLink.useShareableLink)();
  const {
    AmityUserProfilePageBehavior
  } = (0, _BehaviourProvider.useBehaviour)();
  const {
    accessibilityId: menuButtonId
  } = (0, _hooks.useAmityElement)({
    pageId,
    componentId: _enums.ComponentID.WildCardComponent,
    elementId: _enums.ElementID.menu_button
  });
  const {
    openBottomSheet,
    closeBottomSheet,
    bottomSheetHeight
  } = (0, _bottomSheetSlice.useBottomSheet)();
  const navigation = (0, _native.useNavigation)();
  const shareLink = userId ? getShareLink(_types.ShareableLinkModel.users, userId) : null;
  const isMyProfile = (client === null || client === void 0 ? void 0 : client.userId) === userId;
  const {
    isFlaggedByMe,
    reportUser,
    unreportUser
  } = (0, _useFlagUserQuery.useUserFlaggedByMeQuery)({
    userId: userId ?? '',
    enabled: !isMyProfile && !!userId
  });
  const {
    blockUser,
    unBlockUser
  } = (0, _useBlockUser.useBlockUser)();
  const {
    followInfo
  } = (0, _objects.useFollowInfo)({
    userId: userId ?? '',
    enabled: !isMyProfile && !!userId
  });
  const isBlockedByMe = (followInfo === null || followInfo === void 0 ? void 0 : followInfo.status) === 'blocked';
  const actions = [{
    visible: isMyProfile,
    label: 'Edit profile',
    iconProps: {
      xml: (0, _icons.pen)()
    },
    testID: 'edit-profile-button',
    accessibilityLabel: 'Edit profile',
    onPress: () => {
      closeBottomSheet();
      if (AmityUserProfilePageBehavior !== null && AmityUserProfilePageBehavior !== void 0 && AmityUserProfilePageBehavior.goToEditUserPage) {
        AmityUserProfilePageBehavior.goToEditUserPage({
          userId
        });
      } else {
        navigation.navigate('EditUser', {
          userId
        });
      }
    }
  }, {
    visible: isMyProfile,
    label: 'Manage blocked users',
    iconProps: {
      xml: (0, _icons.block)()
    },
    testID: 'manage-blocked-users-button',
    accessibilityLabel: 'Manage blocked users',
    onPress: () => {
      closeBottomSheet();
      if (AmityUserProfilePageBehavior !== null && AmityUserProfilePageBehavior !== void 0 && AmityUserProfilePageBehavior.goToBlockedUsersPage) {
        AmityUserProfilePageBehavior.goToBlockedUsersPage();
      } else {
        navigation.navigate('BlockedUsers');
      }
    }
  }, {
    visible: !isMyProfile && !isFlaggedByMe,
    label: 'Report user',
    iconProps: {
      xml: (0, _icons.report)()
    },
    testID: 'report-user-button',
    accessibilityLabel: 'Report user',
    onPress: () => {
      if (userId) reportUser(userId);
      closeBottomSheet();
    }
  }, {
    visible: !isMyProfile && !!isFlaggedByMe,
    label: 'Unreport user',
    iconProps: {
      xml: (0, _icons.unreport)()
    },
    testID: 'unreport-user-button',
    accessibilityLabel: 'Unreport user',
    onPress: () => {
      if (userId) unreportUser(userId);
      closeBottomSheet();
    }
  }, {
    visible: !isMyProfile && !isBlockedByMe,
    label: 'Block user',
    iconProps: {
      xml: (0, _icons.block)()
    },
    testID: 'block-user-button',
    accessibilityLabel: 'Block user',
    onPress: () => {
      closeBottomSheet();
      if (userId) blockUser(userId, displayName ?? userId);
    }
  }, {
    visible: !isMyProfile && isBlockedByMe,
    label: 'Unblock user',
    iconProps: {
      xml: (0, _icons.block)()
    },
    testID: 'unblock-user-button',
    accessibilityLabel: 'Unblock user',
    onPress: () => {
      closeBottomSheet();
      if (userId) unBlockUser(userId, displayName ?? userId);
    }
  }].filter(action => action.visible);
  return {
    actions,
    shareLink,
    menuButtonId,
    openBottomSheet,
    bottomSheetHeight
  };
}
//# sourceMappingURL=useMenu.js.map