// Extracted logic related to activities components
import i18n from '~/locale/i18n';
import _ from 'lodash';

export const isOutgoingActivity = (activity) => {
	if (activity.comment) {
		return activity.comment.sender === activity.username;
	} else if (activity.deletedPhotos) {
		return true;
	} else if (activity.sender) {
		if (activity.connectionEvent) {
			switch (activity.connectionEvent.type) {
				case 'accept':
				case 'auto-add':
				case 'reject':
					return true;
				default:
					return false;
			}
		}
	} else if (activity.receiver) {
		if (activity.connectionEvent) {
			switch (activity.connectionEvent.type) {
				case 'delete':
				case 'send':
					return true;
				default:
					return false;
			}
		} else if (activity.mediaExchange) {
			return true;
		}
	}

	return false;
};

export const activityMessage = (activity) => {
	if (!activity) {
		return '';
	} else if (activity.connectionEvent) {
		if (activity.sender && activity.sender.trim().length > 0 && activity.connectionEvent.type === 'send') {
			return i18n.t('friends.sentFriendRequestIngoing', { friend: activity.senderFullName });
		} else if (activity.sender && activity.sender.trim().length > 0 && activity.connectionEvent.type === 'accept') {
			return i18n.t('friends.acceptFriendRequestIngoing');
		} else if (activity.sender && activity.sender.trim().length > 0 && activity.connectionEvent.type === 'auto-add') {
			return i18n.t('friends.acceptFriendRequestIngoing', { friend: activity.senderFullName });
		} else if (activity.sender && activity.sender.trim().length > 0 && activity.connectionEvent.type === 'delete') {
			return i18n.t('friends.deletedFriendIngoing', { friend: activity.senderFullName });
		} else if (activity.sender && activity.sender.trim().length > 0 && activity.connectionEvent.type === 'reject') {
			return i18n.t('friends.rejectedFriendOutgoing', { friend: activity.senderFullName });
		} else if (activity.receiver && activity.receiver.trim().length > 0 && activity.connectionEvent.type === 'send') {
			return i18n.t('friends.sentFriendRequestOutgoing', { friend: activity.receiverFullName });
		} else if (activity.receiver && activity.receiver.trim().length > 0 && activity.connectionEvent.type === 'accept') {
			return i18n.t('friends.acceptedFriendRequest');
		} else if (activity.receiver && activity.receiver.trim().length > 0 && activity.connectionEvent.type === 'auto-add') {
			return i18n.t('friends.acceptedFriendRequest');
		} else if (activity.receiver && activity.receiver.trim().length > 0 && activity.connectionEvent.type === 'delete') {
			return i18n.t('friends.deletedFriendOutgoing', { friend: activity.receiverFullName });
		} else if (activity.receiver && activity.receiver.trim().length > 0 && activity.connectionEvent.type === 'reject') {
			return i18n.t('friends.rejectedFriendIngoing', { friend: activity.receiverFullName });
		}
	} else if (activity.mediaExchange) {
		if (activity.mediaExchange.type === 'person' || activity.mediaExchange.type === 'email') {
			if (activity.sender && activity.sender.trim().length > 0) {
				return i18n.t('friends.receivedNPhotos', {
					friend: activity.senderFullName,
					count: activity.mediaExchange.count,
				});
			} else if (activity.receiver && activity.receiver.trim().length > 0) {
				return i18n.t('friends.sentNPhotos', {
					friend: activity.receiverFullName,
					count: activity.mediaExchange.count,
				});
			}
		} else if (activity.receiver && activity.receiver.trim().length > 0) {
			return i18n.t('friends.addedNPhotosTo', {
				friend: activity.receiverFullName,
				count: activity.mediaExchange.count,
			});
		}
	} else if (activity.comment) {
		return activity.comment.comment;
	} else if (activity.deletedPhotos) {
		const totalDeletedPhotos = _.size(activity.deletedPhotos);
		return i18n.t('contents.deletedNPhotosFromAlbum', {
			album: activity.fullName,
			count: totalDeletedPhotos,
		});
	}
	return '';
};
