<?php
    $isLoggedIn = isset($isLoggedIn) ? (bool) $isLoggedIn : \Auth::check();
    $authUserId = array_key_exists('authUserId', get_defined_vars()) ? $authUserId : ($isLoggedIn ? \Auth::id() : null);
    $themeAsset = isset($themeAsset) ? $themeAsset : Theme::asset();
    $reactionsBase = isset($reactionsBase) ? $reactionsBase : $themeAsset->img('theme/images/reactions');
?>
<div id="last-activity-{{$type}}{{$type_id}}">
	<div class="like-reactions @if(!$isLoggedIn and $type=="post") like-reaction-outsider @endif" id="like-reactions-{{$type}}{{$type_id}}">
    
		@if(!$isLoggedIn and $type=="post")
        	<span>STEP 1: Email required</span>
			<input type="email" name="post_like_email_address" id="post_like_email_address_{{$type_id}}" class="form-control post_like_email_address_{{$type_id}} post_like_email_address" placeholder="Provide your email and select an emoji icon to react." />
            @if(!$isLoggedIn)
                <p style="text-align:right;margin-bottom: 4px;margin-top: -12px;">I agree to the <a href="https://idhubs.com/terms" target="_blank" style="color:#F00;text-decoration:underline">terms</a> of posting</p> 
            @endif
            
            <span style="margin-right: 10px;">STEP 2 : Select an emoji to post</span>
		@endif
    
        <img data-original="{{$reactionsBase}}/like.png" class="like-reaction lazy" data-value='like' alt="like" data-is-login="{{$isLoggedIn}}">
        
        <img data-original="{{$reactionsBase}}/love.png" class="like-reaction lazy" data-value='love' alt="love" data-is-login="{{$isLoggedIn}}">
        
        <img data-original="{{$reactionsBase}}/haha.png" class="like-reaction lazy" data-value='haha' alt="haha" data-is-login="{{$isLoggedIn}}">
        
        <img data-original="{{$reactionsBase}}/wow.png" class="like-reaction lazy" data-value='wow' alt="wow" data-is-login="{{$isLoggedIn}}">
        
        <img data-original="{{$reactionsBase}}/sad.png" class="like-reaction lazy" data-value='sad' alt="sad" data-is-login="{{$isLoggedIn}}">
        
        <img data-original="{{$reactionsBase}}/angry.png" class="like-reaction lazy" data-value='angry' alt="angry" data-is-login="{{$isLoggedIn}}">
        
    </div>

    @if($likes > 0)
          <?php 
            $likeRepo = app('App\\Repositories\\LikeRepository');
            $latest = $likeRepo->getLatestLikes($type, $type_id, 1);
            $reactions = $likeRepo->getLikesAction($type, $type_id);
          ?>
          
          <div class="like-last-activity">
              @foreach($latest as $like)
              
                    @if($like->user)
                    
                        <?php 
                        $likeCount=0;
                        $likeUserPresenter = \App\Helpers\PresenterCache::user($like->user);
                    ?> 
                        
                        @if($reactions)
								@foreach($reactions as $reaction)
                                
                                	<?php $react=($reaction->reaction)? $reaction->reaction: 'like'; ?>
                                    
                                    @if($react)
                                    	
                                        @if($react == 'like' && $likeCount==1)
                                        @else
											<?php if($react == 'like'){ $likeCount=1;  } ?>
                                            
                                            <img data-original="{{$reactionsBase}}/{{$react}}.png" class="like-reaction lazy" alt="reaction"/>
                                        @endif    
                                    @endif
                                @endforeach
                        @endif 
                    
                        @if($likes == 1)
                            <a class="title" data-url="{{$likeUserPresenter->popoverUrl()}}" href="{{$likeUserPresenter->url()}}">
                            
                            @if($isLoggedIn and $authUserId==$likeUserPresenter->id) You @else {{$likeUserPresenter->fullname}} @endif  </a> recently liked
                            
                        @else

                                <a class="title" data-url="{{$likeUserPresenter->popoverUrl()}}" href="{{$likeUserPresenter->url()}}">
                                @if($isLoggedIn and $authUserId==$likeUserPresenter->id) You @else {{$likeUserPresenter->fullname}} @endif </a> and 
                                
                          
                                @if($type =='post') 
                                   <a data-id="{{$type_id}}" data-loading="{{trans('post.loading')}}" class="post-activity-loader title" href="{{URL::route('show-likes', ['type' => 'post', 'id' => $type_id])}}">{{$likes-1}} others</a>
                                @else
                                    <a data-id="{{$type_id}}" data-loading="{{trans('post.loading')}}" class="photo-activity-loader title" href="{{URL::route('show-likes', ['type' => 'photo', 'id' => $type_id])}}">{{$likes-1}} others</a>
                                @endif
                                
                        @endif
                    @endif
              @endforeach
          </div>    
    @endif
</div> 
