import { useBottomSheet } from '../../../../../../../core/stores/slices/bottomSheetSlice';
import { useUserFlaggedByMeQuery, useBlockUser } from '../../../../../../hooks';
import { report, unreport, block } from '../../../../../../../core/assets/icons';
import { useStyles } from '../styles';
import { useUser } from '../../../../../../hooks/objects';
import { useNavigation } from '@react-navigation/native';
import useAuth from '../../../../../../../core/hooks/useAuth';
import { useBehaviour } from '../../../../../../providers/BehaviourProvider';
export function useUserItem({
  profileId,
  userId
}) {
  const {
    styles
  } = useStyles();
  const {
    user
  } = useUser({
    userId
  });
  const {
    client
  } = useAuth();
  const navigation = useNavigation();
  const {
    open,
    openBottomSheet,
    closeBottomSheet,
    bottomSheetHeight
  } = useBottomSheet();
  const {
    isFlaggedByMe,
    reportUser,
    unreportUser
  } = useUserFlaggedByMeQuery({
    userId,
    enabled: open
  });
  const {
    blockUser
  } = useBlockUser();
  const {
    AmityUserRelationshipPageBehavior
  } = 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: report()
    },
    onPress: () => {
      closeBottomSheet();
      reportUser(userId);
    }
  }, {
    visible: !!isFlaggedByMe,
    label: 'Unreport user',
    iconProps: {
      xml: unreport()
    },
    onPress: () => {
      closeBottomSheet();
      unreportUser(userId);
    }
  }, {
    visible: isMyProfile,
    label: 'Block user',
    iconProps: {
      xml: 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