<div class="print-queue">
    <x-title>
        Print Queue
        @if(count($queueItems) > 0)
            <x-slot:buttons>
                <button class="btn btn-primary btn-sm" wire:click="printAll" wire:loading.attr="disabled">
                    <span wire:loading.remove wire:target="printAll">
                        <i class="mdi mdi-printer"></i> Print All
                    </span>
                    <span wire:loading wire:target="printAll">
                        <span class="spinner-border spinner-border-sm me-1"></span> Merging...
                    </span>
                </button>
            </x-slot:buttons>
        @endif
    </x-title>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    @if(count($queueItems) > 0)
                        <div class="table-responsive">
                            <table class="table table-hover align-middle mb-0">
                                <thead>
                                <tr>
                                    <th>Document</th>
                                    <th>Type</th>
                                    <th>Owner</th>
                                    <th>Added By</th>
                                    <th>Added At</th>
                                    <th></th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($queueItems as $item)
                                    <tr>
                                        <td>
                                                <span class="fw-semibold text-primary">
                                                    @if($item['file_path'])
                                                        {{ basename($item['file_path']) }}
                                                    @else
                                                        {{ $item['document']['display_name'] ?? $item['document']['file_name'] }}
                                                    @endif
                                                </span>
                                        </td>
                                        <td>
                                                <span class="text-muted">
                                                    @if($item['file_path'])
                                                        <span class="badge bg-light text-dark border">File</span>
                                                    @else
                                                        {{ $item['document']['type']['display_name'] ?? '—' }}
                                                    @endif
                                                </span>
                                        </td>
                                        <td>
                                            @if($item['file_path'])
                                                {{ $item['owner']['display_name'] ?? '—' }}
                                            @else
                                                {{ $item['document']['owner']['display_name'] ?? '—' }}
                                            @endif
                                        </td>
                                        <td>
                                            {{ $item['user']['name'] ?? '—' }}
                                        </td>
                                        <td>
                                                <span class="text-muted">
                                                    {{ $item['created_at'] }}
                                                </span>
                                        </td>
                                        <td class="text-end">
                                            <i class="mdi mdi-delete-outline action-icon text-danger"
                                               style="cursor: pointer"
                                               wire:confirm="Remove this document from the print queue?"
                                               wire:click="removeItem({{ $item['id'] }})"></i>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    @else
                        <div class="text-center p-5 text-muted">
                            <i class="mdi mdi-printer-off fs-1 d-block mb-2"></i>
                            No documents in the print queue.
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
