<div @if($hasProcessing) wire:poll.5s @endif>
    @php
        $reviewed   = $totalItems - $toReview;                                  // confirmed + dismissed
        $pct        = $totalItems > 0 ? round($reviewed / $totalItems * 100) : 0;
        $canExport  = $confirmed > 0;                                           // export lists confirmed findings only
    @endphp

    <div class="d-flex align-items-start justify-content-between flex-wrap gap-2 mb-3">
        <div>
            <h6 class="mb-0 fw-semibold">Evidence Review</h6>
            <small class="text-muted">Grouped by DSAR recipient and DSAR, plus any direct uploads.</small>
        </div>
        <div class="d-flex gap-2 align-items-center">
            @if($toReview > 0 && $reviewUrl)
                {{-- Work remaining: Review is primary, Export secondary. --}}
                @if($canExport)
                    <a href="{{ $exportUrl }}" class="btn btn-sm btn-outline-secondary">
                        <i class="mdi mdi-file-download-outline me-1"></i>Export summary
                    </a>
                @else
                    <button type="button" class="btn btn-sm btn-outline-secondary" disabled
                            title="Confirm at least one finding to export a review summary">
                        <i class="mdi mdi-file-download-outline me-1"></i>Export summary
                    </button>
                @endif
                <a href="{{ $reviewUrl }}" class="btn btn-sm btn-primary">
                    <i class="mdi mdi-clipboard-check-outline me-1"></i>Review {{ $toReview }} finding{{ $toReview === 1 ? '' : 's' }}
                    <i class="mdi mdi-arrow-right ms-1"></i>
                </a>
            @else
                {{-- Nothing left to review: show completion status + make Export primary. --}}
                @if($totalItems > 0)
                    <span class="badge rounded-pill d-inline-flex align-items-center" style="background:#dcfce7;color:#15803d;padding:.45rem .7rem;font-size:.78rem;">
                        <i class="mdi mdi-check-circle me-1"></i>Review complete
                    </span>
                @endif
                @if($canExport)
                    <a href="{{ $exportUrl }}" class="btn btn-sm btn-primary">
                        <i class="mdi mdi-file-download-outline me-1"></i>Export summary
                    </a>
                @elseif($totalItems > 0)
                    <button type="button" class="btn btn-sm btn-outline-secondary" disabled
                            title="Confirm at least one finding to export a review summary">
                        <i class="mdi mdi-file-download-outline me-1"></i>Export summary
                    </button>
                @endif
            @endif
        </div>
    </div>

    @if($totalItems === 0 && $productiveFiles === 0 && $excludedFiles === 0)
        <div class="text-center py-5 text-muted">
            <i class="mdi mdi-file-search-outline fs-1 d-block mb-2 opacity-25"></i>
            <p class="mb-0 small">No evidence yet.</p>
            <small>Evidence is extracted from DSAR response attachments and uploaded documents.</small>
        </div>
    @else
        @include('components.client.partials.evidence-summary-strip', [
            'totalItems' => $totalItems,
            'confirmed'  => $confirmed,
            'toReview'   => $toReview,
            'dismissed'  => $dismissed,
            'reviewed'   => $reviewed,
            'pct'        => $pct,
        ])

        @include('components.client.partials.evidence-review-body')
    @endif
</div>
