<x-tech-layout>
    <a href="{{ route(auth()->user()->homeRoute()) }}" class="btn btn-light border btn-sm mb-3">
        <i class="bi bi-arrow-left me-1"></i>Назад
    </a>

    <div class="mb-3">
        <h1 class="h5 fw-semibold mb-0">{{ $printer->manufacturer }} {{ $printer->model }}</h1>
        <div class="text-muted small">{{ $printer->client->name }}</div>
    </div>

    <div class="card border-0 shadow-sm mb-3">
        <div class="card-body">
            <dl class="row mb-0 small">
                <dt class="col-5 text-muted">Сериски број</dt><dd class="col-7">{{ $printer->serial_number }}</dd>
                <dt class="col-5 text-muted">Статус</dt><dd class="col-7">{{ $printer->status->label() }}</dd>
                <dt class="col-5 text-muted">Инсталација</dt><dd class="col-7">{{ optional($printer->installation_date)->format('d.m.Y') ?: '—' }}</dd>
            </dl>
        </div>
    </div>

    <div class="card border-0 shadow-sm">
        <div class="card-header bg-white fw-medium">Читања</div>
        <div class="table-responsive">
            <table class="table table-stack align-middle mb-0 small">
                <thead>
                    <tr><th>Датум</th><th class="text-end">Црно-бело</th><th class="text-end">Боја</th><th class="text-end">Скен</th><th>Тонер</th><th>Техничар</th></tr>
                </thead>
                <tbody>
                    @forelse ($log as $row)
                        @php($r = $row['reading'])
                        <tr>
                            <td data-label="Датум" class="text-nowrap">{{ $r->reading_date->format('d.m.Y') }}</td>
                            <td data-label="Црно-бело" class="text-end">
                                {{ $r->bw_counter !== null ? number_format($r->bw_counter) : '—' }}
                                @if ($row['bw_used'] !== null)<div class="text-muted">+{{ number_format($row['bw_used']) }}</div>@endif
                            </td>
                            <td data-label="Боја" class="text-end">
                                {{ $r->color_counter !== null ? number_format($r->color_counter) : '—' }}
                                @if ($row['color_used'] !== null)<div class="text-muted">+{{ number_format($row['color_used']) }}</div>@endif
                            </td>
                            <td data-label="Скен" class="text-end">
                                {{ $r->scan_counter !== null ? number_format($r->scan_counter) : '—' }}
                                @if ($row['scan_used'] !== null)<div class="text-muted">+{{ number_format($row['scan_used']) }}</div>@endif
                            </td>
                            <td data-label="Тонер" class="text-nowrap">
                                @if ($r->toner_black || $r->toner_cyan || $r->toner_magenta || $r->toner_yellow)
                                    B{{ $r->toner_black ?? '–' }} C{{ $r->toner_cyan ?? '–' }} M{{ $r->toner_magenta ?? '–' }} Y{{ $r->toner_yellow ?? '–' }}
                                @else — @endif
                            </td>
                            <td data-label="Техничар">{{ $r->technician?->name ?? '—' }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="text-center text-muted py-4">Сè уште нема читања</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</x-tech-layout>
