<?php

class PeepSoReactionsModel
{
	const TABLE = 'peepso_reactions';

	public $reactions;
	public $reactions_published;
	public $my_reaction;

	public $activity;			// PeepSoActivity instance
	public $act_id;
	public $act_module_id;
	public $act_external_id;

	public $has_default_title;

	private $_user_id;

	public function __construct($all = TRUE)
	{
		$post_status = (TRUE == $all) ? "any" : "publish";

		$this->_user_id = get_current_user_id();
		$this->reactions = array();
		$args = array(
			'post_type' 		=> array('peepso_reaction', 'peepso_reaction_user'),
			'orderby'			=> 'menu_order',
			'order'				=> 'ASC',
			'posts_per_page' 	=> -1,
			'post_status'		=> $post_status,
		);

		$posts = new WP_Query($args);

		if (!count($posts->posts)) {
			require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../install' . DIRECTORY_SEPARATOR . 'activate.php');
			$install = new PeepSoActivate();
			$install->plugin_activation();
			$posts = new WP_Query($args);
		}

		foreach ($posts->posts as $post) {

			$reaction = array(
				'id'				=> $post->post_parent,
				'post_id'			=> $post->ID,
				'published'			=> intval(('publish' == $post->post_status)),
				'title' 			=> __($post->post_title, 'peepso-core'),
				'content' 			=> $post->post_content,
				'icon'				=> $post->post_excerpt,
				'icon_url'			=> str_ireplace(['https://', 'http://'], '//', plugin_dir_url(dirname(__FILE__)) . 'assets/images/svg/' . $post->post_excerpt),
				'custom'			=> intval(('peepso_reaction_user' == $post->post_type)),
				'order'				=> intval($post->menu_order),
				'has_default_title' => FALSE,
				'emotion'           => 0, // #8037 default neutral (was +1 positive); emotions reserved for the future Controversial sort
			);

			$emotion = $emotion = get_post_meta($post->ID, 'reaction_emotion', TRUE);
			if (strlen($emotion)) {
				$reaction['emotion'] = $emotion;
			}

			if (1 == $reaction['custom']) {
				$reaction['id'] = $post->ID;
				$reaction['has_default_title'] = intval((1 == get_post_meta($post->ID, 'default_title', TRUE)));
			}

			if (strstr($post->post_excerpt, 'peepsocustom-')) {
				$reaction['icon_url'] = str_replace('peepsocustom-', '', $post->post_excerpt);
			}

			$reaction['class']	= 'ps-reaction-emoticon-' . $reaction['id'];

			$reaction = (object) $reaction;
			$this->reactions[$reaction->id] = $reaction;

			if ($reaction->published) {
				$this->reactions_published[$reaction->id] = $reaction;
			}
		}
	}

	public function init($act_id = NULL)
	{
		// Do not init for NULL act_id or the same act_ic
		if (NULL == $act_id || $this->act_id == $act_id) {
			return;
		}

		$this->act_id = $act_id;
		$my_reaction_id = FALSE;
		$this->my_reaction = FALSE;

		// has my like?
		$this->activity  		= new PeepSoActivity();
		$act					= $this->activity->get_activity($this->act_id);
		$this->act_module_id 	= $act->act_module_id;
		$this->act_external_id  = $act->act_external_id;

		$like = new PeepSoLike();
		$like = $like->user_liked($this->act_external_id, $this->act_module_id, $this->_user_id);

		if (TRUE === $like) {
			$my_reaction_id =  0;
		} else {
			global $wpdb;

			$sql = "SELECT `reaction_type` FROM `{$wpdb->prefix}" . self::TABLE . "` "
				. " WHERE `reaction_act_id`=%d AND `reaction_user_id`=%d ";

			$sql = $wpdb->prepare($sql, $this->act_id, $this->_user_id);

			$res = $wpdb->get_var($sql);

			if (is_numeric($res)) {
				$my_reaction_id = intval($res);
			}
		}

		if (is_numeric($my_reaction_id)) {
			$this->my_reaction = $this->reaction($my_reaction_id);
			$this->my_reaction->class = 'liked ' . $this->my_reaction->class;
		}
	}

	public function reaction($id)
	{
		if (!isset($this->reactions[$id])) {
			// Default to a like to avoid fatals in unlikely case of missing reaction
			return clone $this->reactions[0];
		}

		return clone $this->reactions[$id];
	}

	/**
	 * Remove my Reaction
	 * @return bool
	 */
	public function user_reaction_reset($is_delete = true)
	{
		global $wpdb;

		$rank = new PeepSoActivityRanking();
		if ($is_delete) {
			$like = new PeepSoLike();
			$user_liked = $like->user_liked($this->act_external_id, $this->act_module_id, $this->_user_id);
			if ($user_liked) {
				$like->remove_like($this->act_external_id, $this->act_module_id, $this->_user_id);

				// flag the thread root for ranking recompute
				$rank->mark_dirty($this->act_id);
			}
		}

		$sql = "SELECT `reaction_type` FROM `{$wpdb->prefix}" . self::TABLE . "` "
			. " WHERE `reaction_act_id`=%d AND `reaction_user_id`=%d ";

		$sql = $wpdb->prepare($sql, $this->act_id, $this->_user_id);
		$user_react = $wpdb->get_var($sql);

		if (is_numeric($user_react)) {
			// remove reaction
			$sql = "DELETE FROM `{$wpdb->prefix}" . self::TABLE . "` "
				. " WHERE `reaction_act_id`=%d "
				. " AND `reaction_user_id`=%d ";

			$sql = $wpdb->prepare($sql, $this->act_id, $this->_user_id);
			$wpdb->query($sql);

			// fire the action
			do_action('peepso_action_react_remove', (object) array(
				'react_external_id' => $this->act_external_id,
				'react_user_id' => $this->_user_id,
				'react_module_id' => $this->act_module_id
			));

			// flag the thread root for ranking recompute
			$rank->mark_dirty($this->act_id);
		}

		$this->my_reaction = FALSE;
	}

	private function is_comment_activity($act_post)
	{
		return (is_object($act_post) && isset($act_post->post_type) && $act_post->post_type === PeepSoActivityStream::CPT_COMMENT);
	}

	private function get_comment_notification_context($act_post)
	{
		$post_id = $act_post->ID;
		$orig_post = get_post($post_id);
		$post_title = $orig_post->post_title;
		$object_id = $post_id;
		$object_module_id = PeepSoActivity::MODULE_ID;
		$parent_post_id = $post_id;

		if (0 !== intval($act_post->act_comment_object_id)) {
			$parent_post = get_post($act_post->act_comment_object_id);
			$parent_post_act = $this->activity->get_activity_data($parent_post->ID, $act_post->act_comment_module_id);
			$object_id = $act_post->act_comment_object_id;
			$object_module_id = $act_post->act_comment_module_id;
			$parent_post_id = $parent_post->ID;

			if ($parent_post->post_type === PeepSoActivityStream::CPT_COMMENT) {
				$parent_post_comment = get_post($parent_post_act->act_comment_object_id);
				$parent_post_comment_act = $this->activity->get_activity_data($parent_post_comment->ID, $parent_post_act->act_comment_module_id);
				$object_id = $parent_post_act->act_comment_object_id;
				$object_module_id = $parent_post_act->act_comment_module_id;
				$parent_post_id = $parent_post_comment->ID;

				$post_title = $parent_post_comment->post_title . '#comment.' . $parent_post_comment_act->act_id . '.' . $parent_post->ID . '.' . $parent_post_act->act_id . '.' . $this->act_external_id;
			} else {
				$post_title = $parent_post->post_title . '#comment.' . $parent_post_act->act_id . '.' . $orig_post->ID . '.' . $this->act_id;
			}
		}

		$object_id = apply_filters('peepso_activity_user_comment_object_id', $object_id, $object_module_id);

		return array(
			'orig_post' => $orig_post,
			'parent_post_id' => $parent_post_id,
			'object_id' => $object_id,
			'object_module_id' => $object_module_id,
			'mailq_data' => array(
				'permalink' => PeepSo::get_page('activity_status', FALSE) . $post_title,
				'post_content' => $orig_post->post_content,
			),
		);
	}

	/**
	 * Set my Reaction, fire notifications
	 * @param int $react_id
	 * @return void
	 */
	public function user_reaction_set($react_id)
	{
		$this->user_reaction_reset($react_id);

		$react_id = intval($react_id);

		$act_post = $this->activity->get_activity_post($this->act_id);
		$post_id = $act_post->ID;
		$owner_id = $this->activity->get_author_id($post_id);
		$is_comment = $this->is_comment_activity($act_post);

		// Build the full recipient list. Plugins (e.g. peepso-pages) can add managers/moderators
		// via this filter. The reacting user is always excluded to avoid self-notifications.
		$notify_ids = apply_filters('peepso_activity_notification_recipients', array($owner_id), $post_id, $this->_user_id);
		$notify_ids = array_values(array_filter(array_unique(array_map('intval', $notify_ids)), function($id) {
			return $id !== intval($this->_user_id);
		}));

		$user = PeepSoUser::get_instance($this->_user_id);
		$note = new PeepSoNotifications();

		// fire the action
		do_action('peepso_action_react_add', (object) array(
			'react_external_id' => $this->act_external_id,
			'react_act_id' => $this->act_id,
			'react_user_id' => $this->_user_id,
			'react_module_id' => $this->act_module_id
		));

		$do_notify = !empty($notify_ids);
		// Base mail data without per-recipient 'user' fields (merged inside the notify loop)
		$mailq_data = array();
		$owner_follow_notification = NULL;

		if ($is_comment) {
			$comment_context = $this->get_comment_notification_context($act_post);
			$mailq_data = $comment_context['mailq_data'];

			if (PeepSo::get_option_new('postbox_anon_enabled')) {
				$anon_op = get_post_meta($comment_context['parent_post_id'], PeepSo3_anon::META_POST_ANON_OP, TRUE);
				if (strlen($anon_op) && intval($anon_op) == $this->_user_id) {
					$user = PeepSoUser::get_instance(PeepSo3_anon::get_instance()->anon_id);
				}
			}

			$mailq_data = array_merge($mailq_data, $user->get_template_fields('from'));
			$owner_follow_notification = new PeepSo3_Activity_Notifications($comment_context['object_id'], $owner_id);
		} else {
			// activity_followers fallback for post owner
			$owner_follow_notification = new PeepSo3_Activity_Notifications($post_id, $owner_id);
			if (!$owner_follow_notification->is_exists()) {
				$owner_follow_notification->set(1);
			}

			$mailq_data = array(
				'permalink' => PeepSo::get_page('activity', FALSE) . '?status/' . $act_post->post_title,
				'post_content' => $act_post->post_content,
			);
			$mailq_data = array_merge($mailq_data, $user->get_template_fields('from'));

			if ($do_notify && PeepSo::get_option_new('post_auto_follow_react')) {
				// activity_followers fallback for reactions author
				$act_notif = new PeepSo3_Activity_Notifications($post_id, $this->_user_id);
				if (!$act_notif->is_exists()) {
					$act_notif->set(1);
				}
			}
		}

		// perform like
		if (0 == $react_id) {
			$like = new PeepSoLike();
			$like->add_like($this->act_external_id, $this->act_module_id, $this->_user_id);

			// add_like above is called without an act_id, so flag the root here
			$rank = new PeepSoActivityRanking();
			$rank->mark_dirty($this->act_id);

			if (TRUE === $do_notify) {
				foreach ($notify_ids as $notif_id) {
					$notif_user_owner = PeepSoUser::get_instance($notif_id);
					$mailq_data_notif = array_merge($mailq_data, $notif_user_owner->get_template_fields('user'));
					// The primary owner is gated by is_following(); extra recipients (managers etc.) always notified
					$is_primary = ($notif_id === $owner_id);

					if ($is_comment) {
						$i18n = __('Someone liked your comment', 'peepso-core');
						PeepSoMailQueue::add_notification_new($notif_id, $mailq_data_notif, 'Someone liked your comment', array('peepso-core'), 'like_comment', 'like_comment', PeepSoActivity::MODULE_ID);
						if (!$is_primary || $owner_follow_notification->is_following()) {
							$i18n = __('liked your comment', 'peepso-core');
							$note->add_notification_new($this->_user_id, $notif_id, 'liked your comment', array('peepso-core'), 'like_comment', $this->act_module_id, $post_id, $this->act_id);
						}
					} else {
						$i18n = __('Someone liked your post', 'peepso-core');
						PeepSoMailQueue::add_notification_new($notif_id, $mailq_data_notif, 'Someone liked your post', array('peepso-core'), 'like_post', 'like_post', PeepSoActivity::MODULE_ID);
						if (!$is_primary || $owner_follow_notification->is_following()) {
							$i18n = __('liked your post', 'peepso-core');
							$note->add_notification_new($this->_user_id, $notif_id, 'liked your post', array('peepso-core'), 'like_post', $this->act_module_id, $post_id, $this->act_id);
						}
					}
				}
			}

			if (!$is_comment) {
				$followers = $owner_follow_notification->get_followers();
				$skip = array_merge(array($this->_user_id), $notify_ids);
				foreach ($followers as $follower) {
					if (!in_array($follower, $skip)) {
						$act_notif = new PeepSo3_Activity_Notifications($post_id, $follower);
						if ($act_notif->is_following() && PeepSo::get_option_new('post_follow_notify_react')) {
							$i18n = __('liked a post you are following', 'peepso-core');
							$note->add_notification_new($this->_user_id, $follower, 'liked a post you are following', array('peepso-core'), 'like_post', $this->act_module_id, $post_id, $this->act_id);
						}
					}
				}
			}

			$this->my_reaction = $this->reaction($react_id);
			return TRUE;
		}

		// perform reaction
		global $wpdb;

		$data = array(
			'reaction_user_id' => $this->_user_id,
			'reaction_act_id' => $this->act_id,
			'reaction_type' => $react_id,
		);

		$wpdb->insert($wpdb->prefix . self::TABLE, $data);

		// flag the thread root for ranking recompute
		$rank = new PeepSoActivityRanking();
		$rank->mark_dirty($this->act_id);

		$reaction_text = $this->reaction($react_id)->content;

		if (TRUE == $do_notify) {
			if ($is_comment) {
				$email_message = 'Someone %s your comment';
				$email_message_i18n = __('Someone %s your comment', 'peepso-core');
				$email_args = array('peepso-core', $reaction_text);
				$notification_message = '%s your comment';
				$notification_message_i18n = __('%s your comment', 'peepso-core');
				$notification_args = array('peepso-core', $reaction_text);

				if (!strlen($reaction_text)) {
					$email_message = 'Someone reacted to your comment';
					$email_message_i18n = __('Someone reacted to your comment', 'peepso-core');
					$email_args = array('peepso-core');
					$notification_message = 'reacted to your comment';
					$notification_message_i18n = __('reacted to your comment', 'peepso-core');
					$notification_args = array('peepso-core');
				}
			} else {
				$email_message = 'Someone %s your post';
				$email_message_i18n = __('Someone %s your post', 'peepso-core');
				$email_args = array('peepso-core', $reaction_text);
				$notification_message = '%s your post';
				$notification_message_i18n = __('%s your post', 'peepso-core');
				$notification_args = array('peepso-core', $reaction_text);

				if (!strlen($reaction_text)) {
					$email_message = 'Someone reacted to your post';
					$email_message_i18n = __('Someone reacted to your post', 'peepso-core');
					$email_args = array('peepso-core');
					$notification_message = 'reacted to your post';
					$notification_message_i18n = __('reacted to your post', 'peepso-core');
					$notification_args = array('peepso-core');
				}
			}

			$not_type = $is_comment ? 'like_comment' : 'like_post';

			foreach ($notify_ids as $notif_id) {
				$notif_user_owner = PeepSoUser::get_instance($notif_id);
				$mailq_data_notif = array_merge($mailq_data, $notif_user_owner->get_template_fields('user'));
				$is_primary = ($notif_id === $owner_id);
				PeepSoMailQueue::add_notification_new($notif_id, $mailq_data_notif, $email_message, $email_args, $not_type, $not_type, PeepSoActivity::MODULE_ID);
				if (!$is_primary || $owner_follow_notification->is_following()) {
					$ret = $note->add_notification_new($this->_user_id, $notif_id, $notification_message, $notification_args, $not_type, $this->act_module_id, $post_id, $this->act_id);
				}
			}
		}

		if (!$is_comment) {
			$followers = $owner_follow_notification->get_followers();
			$skip = array_merge(array($this->_user_id), $notify_ids);
			foreach ($followers as $follower) {
				if (!in_array($follower, $skip)) {
					$act_notif = new PeepSo3_Activity_Notifications($post_id, $follower);
					if ($act_notif->is_following() && PeepSo::get_option_new('post_follow_notify_react')) {
						$i18n = __('reacted to a post you are following', 'peepso-core');
						$note->add_notification_new($this->_user_id, $follower, 'reacted to a post you are following', array('peepso-core'), 'like_post', $this->act_module_id, $post_id, $this->act_id);
					}
				}
			}
		}

		$this->my_reaction = $this->reaction($react_id);

		return TRUE;
	}

	/**
	 * Count the number of Reactions of given type on current activity
	 * @param int $react_id
	 * @return int
	 */
	public function get_reactions_count($react_id)
	{
		if (!isset($this->activity) || !$this->activity instanceof PeepSoActivity) {
			return;
		}

		if (empty($this->act_module_id)) {
			#	return; // 2207
		}



		if (0 == $react_id) {
			$like = $this->activity->get_like_status($this->act_external_id, $this->act_module_id);
			return $like['count'];
		}

		global $wpdb;
		$sql = "SELECT COUNT(*) FROM `{$wpdb->prefix}" . self::TABLE . "` " .
			" WHERE `reaction_act_id`=%d ";

		$sql .= " AND `reaction_type`=%d ";
		$sql = $wpdb->prepare($sql, $this->act_id, $react_id);

		$res = $wpdb->get_var($sql);
		return (intval($res));
	}

	/*****************************************//* @TODO THIS IS AWFUL */
	/******************************************/

	public function html_reactions()
	{
		$total_reactions = 0;

		foreach ($this->reactions as $react_id => $reaction) {

			$count = $this->get_reactions_count($react_id);

			if ($count > 0) {
				$reactions[$react_id] = $count;
				$total_reactions += $count;
			}
		}

		if (0 === $total_reactions) {
			return FALSE;
		}

		ob_start();
		$i = 0;
		arsort($reactions);

		foreach ($reactions as $react_id => $reaction_count) {

			$class = array();
			$class[] = 'ps-reaction__like';
			$class[] = 'ps-reaction-emoticon-' . $react_id;

			if (0 == $i) {
				$class[] = 'ps-reaction__like--first';
				$i++;
			}
			$class = implode(' ', $class);

			$title = array();
			$title[] = $this->reaction($react_id)->title;
			$title[] = '(' . $reaction_count . ')';

			$title = implode(' ', $title);
?>
			<span class="<?php echo esc_attr($class); ?>" title="<?php echo esc_attr($title); ?>"></span>
		<?php
		}
		?>
		<a title="<?php echo esc_attr($title); ?>" href="#"
			onclick="reactions.action_html_reactions_details(this, <?php echo esc_attr($this->act_id); ?>); return false;">
			<nobr>

				<?php

				if (FALSE !== $this->my_reaction) {

					echo esc_attr(__('You', 'peepso-core'));
					$total_reactions--;

					if ($total_reactions > 0) {
						echo esc_attr(" + " . $total_reactions . ' ');
						echo esc_attr(_n('other', 'others', $total_reactions, 'peepso-core'));
					}
				} else {
					echo esc_attr($total_reactions . ' ');
					echo esc_attr(_n('person', 'people', $total_reactions, 'peepso-core'));
				}

				echo '</nobr></a>';
				$res = ob_get_clean();
				return $res;
			}

			public function html_reactions_details()
			{
				ob_start();
				$reactions = array();
				?>
				<div class="ps-reactions__likes-list">
					<a id="ps-reaction-details-close" class="ps-reactions__likes-close ps-tip ps-tip--arrow ps-tip--inline" href="#"
						onclick="reactions.action_html_reactions(this, <?php echo esc_attr($this->act_id); ?>); return false;" aria-label="<?php echo esc_attr(__('Close reactions', 'peepso-core')); ?>">
						<i class="gcis gci-times"></i>
					</a>
					<?php
					// User ids for  likes
					$reactions_count = array(0 => 0);
					$like = new PeepSoLike();
					$names = $like->get_like_names($this->act_external_id, $this->act_module_id);

					if (count($names) > 0) {
						foreach ($names as $name) {
							$reactions[0][] = $name->ID;
							$reactions_count[0]++;
						}
					}

					// User ids for each reactions
					global $wpdb;
					foreach ($this->reactions as $react_id => $reaction) {

						if (0 == $react_id) {
							continue;
						}

						$reactions_count[$react_id] = 0; // = array_merge($reactions_count, array("$react_id"=>0));

						$sql = "SELECT reaction_user_id  FROM `{$wpdb->prefix}" . self::TABLE . "` "
							. " WHERE `reaction_act_id`=%d "
							. " AND `reaction_type`=%d ";

						$sql = $wpdb->prepare($sql, $this->act_id, $react_id);

						$result = $wpdb->get_results($sql);

						if (count($result)) {
							foreach ($result as $user) {
								$reactions[$react_id][] = $user->reaction_user_id;
								$reactions_count[$react_id]++;
							}
						}
					}

					// Most pop[ular reactions on top
					arsort($reactions_count);

					foreach ($reactions_count as $react_id => $count) {
						// array is sorted descending - abort the loop when encountering the first zero
						if (0 == $count) {
							break;
						}

						$class = array();
						$class[] = 'ps-reaction__like';
						$class[] = 'ps-reaction-emoticon-' . $react_id;
						$class[] = 'ps-reaction__like--first';
						$class = implode(' ', $class);
					?>

						<div class="ps-reactions__likes-list-item">
							<span class="<?php echo esc_attr($class); ?>"><?php echo esc_attr($this->reaction($react_id)->title); ?> (<?php echo esc_attr($count); ?>):</span>
							<span class="ps-reactions__likes-list-users">
							<?php


							$html_names = array();

							if (in_array($this->_user_id, $reactions[$react_id])) {
								$user = PeepSoUser::get_instance($this->_user_id);
								$html_names[] = '<a class="ps-comment-user" href="' . $user->get_profileurl() . '" data-hover-card="' . $user->get_id() . '">' . __('You', 'peepso-core') . '</a>';
							}

							foreach ($reactions[$react_id] as $user_id) {
								if ($user_id == $this->_user_id) {
									continue;
								}
								$user = PeepSoUser::get_instance($user_id);
								$html_names[] = '<a class="ps-comment-user" href="' . $user->get_profileurl() . '" data-hover-card="' . $user->get_id() . '">' . $user->get_fullname() . '</a>';
							}

							echo wp_kses_post(implode(', ', $html_names));
							echo '</span>';
							echo '</div>';
						}


						$res = ob_get_clean();
						$res .= "</div>";
						return $res;
					}

					public function html_before_comments($context = 'post')
					{
						global $post;

						$is_comment = ('comment' === $context);
						$dropdown_classes = array(
							'ps-reactions__dropdown',
							$is_comment ? 'ps-comment__action' : 'ps-post__action',
							'cstream-reactions-options',
							'ps-js-reaction-options',
							'ps-js-act-reactions-options--' . $this->act_id,
						);

						$status_classes = array(
							$is_comment ? 'ps-comment__action' : 'ps-post__action ps-stream-status ps-post__status',
							$is_comment ? 'ps-comment__action--reactions' : '',
							'cstream-reactions',
							'ps-js-act-reactions--' . $this->act_id,
						);
							?>
							<div id="act-reactions-<?php echo esc_attr($this->act_id); ?>"
								class="<?php echo esc_attr(implode(' ', array_filter($dropdown_classes))); ?>"
								data-count="">
								<div class="ps-reactions__list">
									<?php
									foreach ($this->reactions as $react_id => $reaction) :

										// skip unpublished
										if (1 != $reaction->published) {
											continue;
										}

										// skip unconfigured (default titles)
										if (1 == $reaction->has_default_title) {
											continue;
										}

										$title = trim($this->reaction($react_id)->title);

										// build CSS
										$class = array(
											$reaction->class,
											'ps-reaction-option',
											'ps-reaction-option--' . $this->act_id,
											'ps-reaction-option-' . $react_id . '--' . $this->act_id,
										);

										if (!empty($title)) {
											$class[] = 'ps-tooltip';
											$class[] = 'ps-tooltip--reaction';
										}

										if ($this->my_reaction && $this->my_reaction->id === $react_id) {
											$class[] = 'ps-reaction-option-selected';
										}

										$class = implode(' ', $class);
									?>
										<span class="ps-reactions__list-item">
											<a href="#" class="<?php echo esc_attr($class); ?>" aria-label="<?php echo esc_attr($title); ?>" data-tooltip="<?php echo esc_attr($title); ?>"
												onclick="reactions.action_react(this, <?php echo esc_attr($this->act_id); ?>, <?php echo esc_attr($post->ID); ?>, <?php echo esc_attr($react_id); ?>); return false;">
											</a>
										</span>
									<?php endforeach; ?>

									<?php
									$class = array(
										'ps-reaction-option',
										'ps-reaction-option-delete',
										'ps-reaction-option--' . $this->act_id,
										'ps-reaction-option-delete--' . $this->act_id,
									);

									$class = implode(' ', $class);
									?>

									<span class="ps-reactions__list-item ps-reactions__list-item--delete ps-reaction-option-delete--<?php echo esc_attr($this->act_id); ?>">
										<a class="<?php echo esc_attr($class); ?>" href="#"
											data-tooltip="<?php echo esc_attr(__('Remove', 'peepso-core')); ?>"
											onclick="reactions.action_react_delete(this, <?php echo esc_attr($this->act_id); ?>, <?php echo esc_attr($post->ID); ?>); return false;">
											<i class="gcir gci-times-circle"></i>
										</a>
									</span>

								</div>
							</div>
							<?php
							$html_reactions = $this->html_reactions();

							if (FALSE === $html_reactions) {
								$status_classes[] = 'ps-reactions__likes--hide';
							}
							?>
							<div id="act-react-<?php echo esc_attr($this->act_id); ?>"
								class="ps-reactions__likes <?php echo esc_attr(implode(' ', array_filter($status_classes))); ?>" data-count="">
								<?php echo $html_reactions; ?>
							</div>
					<?php
					}
				}
