@extends('layouts.app', ['title' => 'QR Maintenance', 'heading' => 'QR Maintenance'])

@section('content')
<div class="row">
    <div class="col-12 mb-4">
        <div class="card">
            <div class="card-header border-bottom mb-3 d-flex flex-column flex-md-row justify-content-between align-items-md-center">
                <h5 class="mb-3 mb-md-0">QR Barang Inventaris</h5>
                <form method="GET" action="{{ route('qr.index') }}" class="d-flex align-items-center gap-2">
                    <select name="location_id" class="form-select form-select-sm" style="min-width: 200px;" onchange="this.form.submit()">
                        <option value="">Semua Ruangan</option>
                        @foreach ($locations as $loc)
                            <option value="{{ $loc->id }}" @selected(request('location_id') == $loc->id)>{{ $loc->name }}</option>
                        @endforeach
                    </select>
                    <a href="{{ route('qr.print', ['location_id' => request('location_id')]) }}" target="_blank" class="btn btn-sm btn-primary text-nowrap">
                        <i class="ti tabler-printer me-1"></i> Cetak QR
                    </a>
                </form>
            </div>
            <div class="card-body">
                <div class="row g-4">
                    @foreach ($items as $item)
                        <div class="col-md-3 col-sm-6">
                            <div class="card h-100 shadow-none border">
                                <div class="card-body text-center d-flex flex-column align-items-center justify-content-center">
                                    <div class="mb-3 p-3 bg-light rounded">
                                        {!! \SimpleSoftwareIO\QrCode\Facades\QrCode::size(120)->generate(route('maintenance.public.show', $item->qr_token)) !!}
                                    </div>
                                    <h6 class="mb-1">{{ $item->name }}</h6>
                                    <span class="text-muted small d-block mb-3">{{ $item->location?->name }}</span>
                                    <a href="{{ route('maintenance.public.show', $item->qr_token) }}" target="_blank" class="btn btn-sm btn-outline-primary mt-auto">Buka form publik</a>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>

    <div class="col-12">
        <div class="card">
            <h5 class="card-header border-bottom mb-3">QR Objek Fasilitas</h5>
            <div class="card-body">
                <div class="row g-4">
                    @foreach ($facilities as $facility)
                        <div class="col-md-3 col-sm-6">
                            <div class="card h-100 shadow-none border">
                                <div class="card-body text-center d-flex flex-column align-items-center justify-content-center">
                                    <div class="mb-3 p-3 bg-light rounded">
                                        {!! \SimpleSoftwareIO\QrCode\Facades\QrCode::size(120)->generate(route('maintenance.public.show', $facility->qr_token)) !!}
                                    </div>
                                    <h6 class="mb-1">{{ $facility->name }}</h6>
                                    <span class="text-muted small d-block mb-3">{{ $facility->location?->name }}</span>
                                    <a href="{{ route('maintenance.public.show', $facility->qr_token) }}" target="_blank" class="btn btn-sm btn-outline-primary mt-auto">Buka form publik</a>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
