"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useUserItem = useUserItem;
var _bottomSheetSlice = require("../../../../../../../core/stores/slices/bottomSheetSlice");
var _hooks = require("../../../../../../hooks");
var _icons = require("../../../../../../../core/assets/icons");
var _styles = require("../styles");
var _objects = require("../../../../../../hooks/objects");
var _native = require("@react-navigation/native");
var _useAuth = _interopRequireDefault(require("../../../../../../../core/hooks/useAuth"));
var _BehaviourProvider = require("../../../../../../providers/BehaviourProvider");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function useUserItem({
  profileId,
  userId
}) {
  const {
    styles
  } = (0, _styles.useStyles)();
  const {
    user
  } = (0, _objects.useUser)({
    userId
  });
  const {
    client
  } = (0, _useAuth.default)();
  const navigation = (0, _native.useNavigation)();
  const {
    open,
    openBottomSheet,
    closeBottomSheet,
    bottomSheetHeight
  } = (0, _bottomSheetSlice.useBottomSheet)();
  const {
    isFlaggedByMe,
    reportUser,
    unreportUser
  } = (0, _hooks.useUserFlaggedByMeQuery)({
    userId,
    enabled: open
  });
  const {
    blockUser
  } = (0, _hooks.useBlockUser)();
  const {
    AmityUserRelationshipPageBehavior
  } = (0, _BehaviourProvider.useBehaviour)();
  const isMyProfile = (client === null || client === void 0 ? void 0 : client.userId) === profileId;
  const isMyItem = (client === null || client === void 0 ? void 0 : client.userId) === userId;
  const goToUserProfile = () => {
    if (AmityUserRelationshipPageBehavior !== null && AmityUserRelationshipPageBehavior !== void 0 && AmityUserRelationshipPageBehavior.goToUserProfilePage) {
      AmityUserRelationshipPageBehavior.goToUserProfilePage({
        userId
      });
    } else {
      navigation.push('UserProfile', {
        userId
      });
    }
  };
  const actions = [{
    visible: !isFlaggedByMe,
    label: 'Report user',
    iconProps: {
      xml: (0, _icons.report)()
    },
    onPress: () => {
      closeBottomSheet();
      reportUser(userId);
    }
  }, {
    visible: !!isFlaggedByMe,
    label: 'Unreport user',
    iconProps: {
      xml: (0, _icons.unreport)()
    },
    onPress: () => {
      closeBottomSheet();
      unreportUser(userId);
    }
  }, {
    visible: isMyProfile,
    label: 'Block user',
    iconProps: {
      xml: (0, _icons.block)()
    },
    onPress: () => {
      closeBottomSheet();
      blockUser(userId, (user === null || user === void 0 ? void 0 : user.displayName) || (user === null || user === void 0 ? void 0 : user.userId) || '');
    }
  }].filter(action => action.visible);
  return {
    actions,
    openBottomSheet,
    bottomSheetHeight,
    styles,
    user,
    navigation,
    isMyProfile,
    isMyItem,
    goToUserProfile
  };
}
//# sourceMappingURL=useUserItem.js.map