<div class="panel panel-default">
    <div class="panel-heading">Log</div>
    <div class="panel-body">
        @include('parts.overview.filterLog')
        <hr>

        <table class="table">
            <thead>
                <tr>
                    <th>Level</th>
                    <th>Status code</th>
                    <th>Title</th>
                    <th>Project</th>
                    <th>Time</th>
                </tr>
            </thead>
            <tbody>
                <?php $useGroupBreaks = in_array(Session::get('list.filter.grouping', 'no'), ['day','week','month','year']); ?>
                @foreach($filteredOccurrences as $row)
                    @if($useGroupBreaks && isset($nextGroupDivider) && date('Y-m-d', strtotime($row->created_at)) <= $nextGroupDivider)
                        @if(Session::get('list.filter.grouping') == 'day')
                            <tr><td colspan="5" class="active text-center"><em>{{$nextGroupDivider}}</em></td></tr>
                            <?php $nextGroupDivider = date('Y-m-d', strtotime($nextGroupDivider .' - 1 day')); ?>
                        @else
                            <tr><td colspan="5" class="active text-center"><em>{{$nextGroupDivider}} - {{$nextGroupDivider = date('Y-m-d', strtotime($nextGroupDivider .' - 1 '.Session::get('list.filter.grouping')))}}</em></td></tr>
                        @endif
                    @elseif($useGroupBreaks && !isset($nextGroupDivider))
                        @if(Session::get('list.filter.grouping') == 'day')
                            <tr><td colspan="5" class="active text-center"><em>{{date('Y-m-d', strtotime($row->created_at))}}</em></td></tr>
                            <?php $nextGroupDivider = date('Y-m-d', strtotime($row->created_at .' - 1 day')); ?>
                        @else
                            <tr><td colspan="5" class="active text-center"><em>{{date('Y-m-d', strtotime($row->created_at))}} - {{$nextGroupDivider = date('Y-m-d', strtotime($row->created_at .' - 1 '.Session::get('list.filter.grouping')))}}</em></td></tr>
                        @endif
                    @endif
                    <tr>
                        <td><span class="error-lvl" data-error-lvl="{{$row->level}}">{{$row->level}}</span></td>
                        <td>{{$row->message->status_code}}</td>
                        <td>
                            <a href="{{route('message', [$row->message->id])}}">{{$row->message->title}}</a>
                            @if(isset($row->occurrences) && $row->occurrences > 1)
                                <span class="label label-primary">x {{$row->occurrences}}</span>
                            @endif
                            @if(!empty($row->message->spam))
                                <span class="label label-danger">SPAM</span>
                            @endif
                        </td>
                        <td>
                            @if($row->message->project_id && !empty($row->message->project->title))
                                {{$row->message->project->title}}
                            @elseif($row->message->project_id)
                                <em>{{$row->message->project->name}}</em>
                            @endif
                        </td>
                        <td>{{$row->created_at}}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
        @if($filteredOccurrences instanceof \Illuminate\Pagination\LengthAwarePaginator)
            {{ $filteredOccurrences->links() }}
        @endif
    </div>
</div>
