<div>
    {{-- Flagged warning --}}
    @if($dsar->is_flagged)
        <div class="alert alert-danger d-flex align-items-center mb-3 py-2">
            <i class="bi bi-flag-fill me-2"></i>
            <span class="small fw-semibold">This DSAR has been flagged and requires attention.</span>
        </div>
    @endif

    {{-- Logged responses --}}
    @if($responses->isNotEmpty())
        <div class="mb-3">
            @foreach($responses as $response)
                <div class="border rounded p-2 mb-2 small">
                    <div class="d-flex justify-content-between align-items-center mb-1">
                        <span class="badge {{ $response->typeBadgeClass }}">{{ $response->typeLabel }}</span>
                        @if($response->is_flagged)
                            <i class="bi bi-flag-fill text-danger" title="Flagged"></i>
                        @endif
                    </div>
                    @if($response->notes)
                        <p class="mb-1 text-muted">{{ $response->notes }}</p>
                    @endif
                    <div class="text-muted" style="font-size:.75rem;">
                        Received {{ $response->received_at?->format('d/m/Y') }}
                        &middot; logged by {{ $response->user?->name ?? 'System' }}
                        &middot; {{ $response->created_at->diffForHumans() }}
                    </div>
                </div>
            @endforeach
        </div>
    @else
        <p class="text-muted small mb-3">No responses logged yet.</p>
    @endif

    {{-- Log new response form --}}
    @if(!in_array($dsar->status, ['completed', 'draft']))
        <form wire:submit.prevent="logResponse">
            <div class="mb-2">
                <label class="form-label label-upper">Response Type</label>
                <select wire:model="type" class="form-select form-select-sm @error('type') is-invalid @enderror">
                    <option value="">— Select —</option>
                    <option value="full">Full Response</option>
                    <option value="partial">Partial Response</option>
                    <option value="pushback">Pushback</option>
                    <option value="wrong_recipient">Wrong Recipient</option>
                    <option value="unknown_client">Unknown Client</option>
                </select>
                @error('type') <div class="invalid-feedback">{{ $message }}</div> @enderror
            </div>

            <div class="mb-2">
                <label class="form-label label-upper">Date Received</label>
                <input type="date" wire:model="receivedAt"
                       class="form-control form-control-sm @error('receivedAt') is-invalid @enderror">
                @error('receivedAt') <div class="invalid-feedback">{{ $message }}</div> @enderror
            </div>

            <div class="mb-2">
                <label class="form-label label-upper">Notes</label>
                <textarea wire:model="notes" rows="3"
                          class="form-control form-control-sm @error('notes') is-invalid @enderror"
                          placeholder="Optional notes..."></textarea>
                @error('notes') <div class="invalid-feedback">{{ $message }}</div> @enderror
            </div>

            <button type="submit" class="btn btn-primary btn-sm w-100">
                <span wire:loading.remove wire:target="logResponse">
                    <i class="bi bi-check2 me-1"></i>Log Response
                </span>
                <span wire:loading wire:target="logResponse">Saving...</span>
            </button>
        </form>
    @elseif($dsar->status === 'completed')
        <div class="text-center py-2">
            <i class="bi bi-check-circle-fill text-success fs-4"></i>
            <p class="small text-muted mt-1 mb-0">This DSAR has been completed.</p>
        </div>
    @endif
</div>
