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

    {{-- Header --}}
    <div class="d-flex align-items-center flex-wrap gap-2 mb-3">
        <a href="{{ route('clients.show', $client) }}" class="btn btn-sm btn-outline-secondary">
            <i class="mdi mdi-arrow-left me-1"></i>Back to client
        </a>
        <div class="ms-1">
            <h5 class="mb-0">Evidence Review</h5>
            <small class="text-muted">{{ $client->fullName ?? $client->display_name ?? 'Client' }}</small>
        </div>

        <div class="ms-auto d-flex align-items-center gap-2">
            @if($toReview > 0 && $reviewUrl)
                @if($canExport)
                    <a href="{{ route('clients.evidence.export', $client) }}" 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
                @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="{{ route('clients.evidence.export', $client) }}" 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)
        @include('components.client.partials.evidence-summary-strip', [
            'totalItems' => $totalItems,
            'confirmed'  => $confirmed,
            'toReview'   => $toReview,
            'dismissed'  => $dismissed,
            'reviewed'   => $reviewed,
            'pct'        => $pct,
        ])
    @endif

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