@layout('theme::layouts/admin')

@section('title')@lang('moderation.approval')@endsection
@section('page_title')@lang('moderation.approval')@endsection
@section('page_sub')@lang('moderation.approval_intro')@endsection

@section('content')
@notempty($notice)<div class="admin-alert admin-alert-success">{{ $notice }}</div>@endnotempty

<div class="panel">
    <div class="panel-header"><span>@lang('moderation.approval')</span></div>

    @if(count($queue) === 0)
    <div class="admin-card-body">
        {#
            🚨 Two different empty states. "Nothing is waiting" on a site where
            this is switched off reads as "nobody has posted anything bad",
            which is not what it means — it means nothing is being held at all.
        #}
        @if($enabled)
        <p class="admin-hint">@lang('moderation.approval_empty')</p>
        @endif
        @if(!$enabled)
        <p class="admin-hint">@lang('moderation.approval_empty_off')</p>
        @endif
    </div>
    @endif

    @if(count($queue) > 0)
    <table class="admin-table">
        <tbody>
            @each ($queue as $row)
            <tr>
                <td>
                    <div class="admin-cell-title">
                        {# The author may have been deleted since; the post is
                           still here and still has to be clearable. #}
                        @lang('moderation.approval_by', ['name' => $row['username'] ?? __('moderation.approval_gone')])
                    </div>
                    {#
                        The plain text, not the rendered HTML. A moderator
                        reading a queue must never be the one who runs whatever
                        somebody put in it.
                    #}
                    <div class="admin-hint">{{ $row['content_plain'] }}</div>
                    <div class="admin-cell-meta">
                        @if((int) $row['topic_pending'] === 1 && (int) $row['position'] === 1)
                        @lang('moderation.approval_new_topic')
                        @endif
                        @if(!((int) $row['topic_pending'] === 1 && (int) $row['position'] === 1))
                        @lang('moderation.approval_in', ['topic' => $row['topic_title'] ?? ''])
                        @endif
                        &middot; {{ $row['created_at'] }}
                    </div>
                </td>
                <td class="admin-table-actions">
                    <form method="POST" action="/admin/moderation/approval/{{ (int) $row['id'] }}/approve">
                        @csrf
                        <button type="submit" class="btn btn-primary btn-sm">@lang('moderation.approve')</button>
                    </form>
                    <form method="POST" action="/admin/moderation/approval/{{ (int) $row['id'] }}/reject"
                          onsubmit="return confirm('{{ __('moderation.reject_confirm') }}')">
                        @csrf
                        <button type="submit" class="btn btn-outline btn-sm">@lang('moderation.reject')</button>
                    </form>
                </td>
            </tr>
            @endeach
        </tbody>
    </table>
    @endif
</div>

<form method="POST" action="/admin/moderation/approval/settings">
    @csrf
    <div class="panel">
        <div class="panel-header"><span>@lang('moderation.approval_settings')</span></div>
        <div class="admin-card-body">
            <div class="admin-form-group">
                <label class="admin-checkbox-label">
                    <input type="checkbox" name="approval_enabled" value="1" @if($enabled)checked @endif>
                    @lang('moderation.approval_enabled')
                </label>
                <p class="admin-hint">@lang('moderation.approval_enabled_desc')</p>
            </div>

            <div class="admin-form-group">
                <label for="approval_posts">@lang('moderation.approval_posts')</label>
                <input type="number" id="approval_posts" name="approval_posts" min="1"
                       class="admin-input input-xs" value="{{ (int) $threshold }}">
                <p class="admin-hint">@lang('moderation.approval_posts_desc')</p>
            </div>

            <button type="submit" class="btn btn-primary">@lang('moderation.save')</button>
        </div>
    </div>
</form>
@endsection
