<div class="print-queue">
    <x-title>
        Print Queue
        @if(count($queueItems) > 0)
            <x-slot:buttons>
                <button class="btn btn-primary btn-sm"
                        wire:click="printSelected"
                        wire:loading.attr="disabled"
                        @if(count($selectedItems) === 0) disabled @endif>
                    <span wire:loading.remove wire:target="printSelected">
                        <i class="mdi mdi-printer"></i>
                        Print Selected
                        @if(count($selectedItems) > 0)
                            ({{ count($selectedItems) }})
                        @endif
                    </span>
                    <span wire:loading wire:target="printSelected">
                        <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 style="width: 40px;">
                                        <input type="checkbox"
                                               class="form-check-input"
                                               wire:model.live="selectAll"
                                               title="Select all">
                                    </th>
                                    <th>Document</th>
                                    <th>Type</th>
                                    <th>Client</th>
                                    <th>Sent By</th>
                                    <th>Added At</th>
                                    <th></th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($queueItems as $item)
                                    <tr>
                                        <td>
                                            <input type="checkbox"
                                                   class="form-check-input"
                                                   wire:model.live="selectedItems"
                                                   value="{{ $item['id'] }}">
                                        </td>
                                        <td>
                                            <span class="fw-semibold text-primary">
                                                {{ $item['doc_name'] }}
                                            </span>
                                        </td>
                                        <td>
                                            <span class="badge bg-light text-dark border">
                                                {{ $item['type_label'] }}
                                            </span>
                                        </td>
                                        <td>{{ $item['client'] }}</td>
                                        <td>{{ $item['user'] }}</td>
                                        <td>
                                            <span class="text-muted">{{ $item['created_at'] }}</span>
                                        </td>
                                        <td class="text-end">
                                            <a wire:navigate href="{{ $item['preview_url'] }}" target="_blank" title="Preview document">
                                                <i class="mdi mdi-eye-outline action-icon text-secondary me-2"></i>
                                            </a>
                                            <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>
