@extends(Theme::viewName('layout'))
@section('title', trans('admin.list_comments_title'))

@section('breadcrumb')
    <li class="breadcrumb-item"><a href="{{ route('home') }}"><i class="fa fa-fw fa-home"></i></a></li>
    <li class="breadcrumb-item"><a href="{{ route('admin') }}">@lang('navigation.breadcrumb.admin')</a></li>
    <li class="breadcrumb-item active">@lang('navigation.breadcrumb.comments')</li>
@endsection

@section('content')
    <div class="container">
        <div class="row">
            <div class="col">
                <h1>@yield('title')</h1>
                <div class="alert alert-info" style="margin-bottom: 30px;">
                    <i class="fa fa-fw fa-info"></i> @lang('admin.list_comments_intro')
                </div>

                <form action="{{ url()->current() }}" method="get" class="form-inline">
                    <label for="comment-filter-status" class="mr-2 mb-3">@lang('forms.filter_comments_status_label')</label>
                    <select class="form-control mb-3 mr-2 custom-select" name="status" id="comment-filter-status">
                        <option value="all"{{ $filter_status == 'all' ? ' selected="selected"' : '' }}>@lang('admin.list_comments_status.all')</option>
                        <option value="pending"{{ $filter_status == 'pending' ? ' selected="selected"' : '' }}>@lang('admin.list_comments_status.pending')</option>
                        <option value="approved"{{ $filter_status == 'approved' ? ' selected="selected"' : '' }}>@lang('admin.list_comments_status.approved')</option>
                        <option value="rejected"{{ $filter_status == 'rejected' ? ' selected="selected"' : '' }}>@lang('admin.list_comments_status.rejected')</option>
                    </select>
                    <button type="submit" class="btn btn-primary mb-3">@lang('forms.apply_action')</button>
                </form>

                @if (count($comments) == 0)
                    <div class="text-center mt-4">
                        <h4 class="text-danger mb-3"><b>@lang('admin.no_comments_title')</b></h4>
                        <p class="mb-1">@lang('admin.no_comments_text')</p>
                        <p>@lang('admin.no_comments_text_2')</p>
                    </div>
                @else
                    <form action="{{ route('comments.bulkAction') }}" method="post">
                        {{ csrf_field() }}
                        <table class="table table-hover table-striped">
                            <tbody>
                            @foreach ($comments as $comment)
                                <tr>
                                    <td class="text-center" style="width: 40px;">
                                        <input type="checkbox" name="comment_ids[]" value="{{ $comment->id }}" />
                                    </td>
                                    <td>
                                        <p>
                                            {{-- TODO: edit comments <a href="{{ route('comments.edit', ['id' => $comment->id]) }}"><span style="font-size: 1.3em;">{{ $comment->name }}</span></a> --}}
                                            <span style="font-size: 1.3em;">{{ $comment->name }}</span>

                                            <br/>
                                            <span class="text-muted" style="font-size: smaller;">{{ trans('admin.comment_summary', ['album_name' => $comment->photo->album->name, 'photo_name' => $comment->photo->name, 'comment_date' => date(UserConfig::get('date_format'), strtotime($comment->created_at))])  }}</span>
                                        </p>
                                        <blockquote>{!! $comment->textAsHtml() !!}</blockquote>
                                    </td>
                                    <td>
                                        <p class="text-right">
                                            @if (!$comment->isModerated())
                                                <span class="badge badge-primary" style="font-size: 85%;">@lang('admin.comment_badge.new')</span>
                                            @elseif ($comment->isApproved())
                                                <span class="badge badge-success" style="font-size: 85%;">@lang('admin.comment_badge.approved')</span>
                                            @elseif ($comment->isRejected())
                                                <span class="badge badge-warning" style="font-size: 85%;">@lang('admin.comment_badge.rejected')</span>
                                            @endif
                                        </p>

                                        <div class="btn-toolbar pull-right">
                                            <div class="btn-group mr-2">
                                                @if (!$comment->isModerated())
                                                    <a href="{{ route('comments.approve', ['id' => $comment->id]) }}" class="btn btn-outline-info">@lang('forms.approve_action')</a>
                                                    <a href="{{ route('comments.reject', ['id' => $comment->id]) }}" class="btn btn-outline-info">@lang('forms.reject_action')</a>
                                                @elseif ($comment->isApproved())
                                                    <a href="{{ route('comments.reject', ['id' => $comment->id]) }}" class="btn btn-outline-info">@lang('forms.reject_action')</a>
                                                @elseif ($comment->isRejected())
                                                    <a href="{{ route('comments.approve', ['id' => $comment->id]) }}" class="btn btn-outline-info">@lang('forms.approve_action')</a>
                                                @endif
                                            </div>

                                            <a href="{{ route('comments.delete', ['id' => $comment->id]) }}" class="btn btn-danger">@lang('forms.delete_action')</a>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>

                        <div class="btn-toolbar mb-4" role="group">
                            <div class="btn-group mr-2">
                                <button type="submit" name="bulk_approve" class="btn btn-outline-info">@lang('forms.approve_selected_action')</button>
                                <button type="submit" name="bulk_reject" class="btn btn-outline-info">@lang('forms.reject_selected_action')</button>
                            </div>
                            <button type="submit" name="bulk_delete" class="btn btn-danger">@lang('forms.delete_selected_action')</button>
                        </div>
                    </form>

                    <div class="text-center">
                        {{ $comments->links() }}
                    </div>
                @endif
            </div>
        </div>
    </div>
@endsection