<x-app-layout>
    @section('page-title', $pageTitle)

    <div class="d-flex align-items-center mb-4">
        <a href="{{ route('admin.buku.index') }}" class="btn btn-outline-secondary me-3 shadow-sm rounded-circle">
            <i class="bi bi-arrow-left"></i>
        </a>
        <h3 class="my-0 fw-bold">Detail Buku</h3>
    </div>

    <div class="row justify-content-center">
        <div class="col-lg-10">
            <div class="card border-0 shadow-sm overflow-hidden">
                <div class="card-body p-0">
                    <div class="row g-0">
                        {{-- Cover Section --}}
                        <div class="col-md-4 bg-light d-flex align-items-center justify-content-center p-4 border-end">
                            <div class="position-relative">
                                <img src="{{ asset($buku->cover) }}" alt="{{ $buku->judul }}" 
                                    class="img-fluid rounded shadow-lg" style="max-height: 400px; object-fit: cover;">
                                @if($buku->is_arsip)
                                    <div class="position-absolute top-0 start-0 w-100 h-100 d-flex align-items-center justify-content-center rounded" 
                                        style="background: rgba(0,0,0,0.5);">
                                        <span class="badge bg-warning text-dark fs-5 shadow">DIARSIPKAN</span>
                                    </div>
                                @endif
                            </div>
                        </div>

                        {{-- Info Section --}}
                        <div class="col-md-8">
                            <div class="p-4 p-md-5">
                                <div class="d-flex justify-content-between align-items-start mb-4">
                                    <div>
                                        <h2 class="fw-bold text-dark mb-1">{{ $buku->judul }}</h2>
                                        <p class="fs-5 text-muted mb-0">oleh <span class="text-primary fw-semibold">{{ $buku->penulis }}</span></p>
                                    </div>
                                    <div class="d-flex gap-2">
                                        <a href="{{ route('admin.buku.edit', $buku->id) }}" class="btn btn-warning rounded-pill">
                                            <i class="bi bi-pencil-square me-2"></i>Edit
                                        </a>
                                    </div>
                                </div>

                                <div class="row g-4 mb-4">
                                    <div class="col-sm-6">
                                        <div class="p-3 border rounded-3 bg-light-subtle">
                                            <small class="text-muted d-block text-uppercase fw-bold mb-1" style="font-size: 0.7rem;">Kategori</small>
                                            <span class="fw-bold fs-5 text-dark">{{ $buku->category->name ?? '-' }}</span>
                                        </div>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="p-3 border rounded-3 bg-light-subtle">
                                            <small class="text-muted d-block text-uppercase fw-bold mb-1" style="font-size: 0.7rem;">Tahun Terbit</small>
                                            <span class="fw-bold fs-5 text-dark">{{ $buku->tahun }}</span>
                                        </div>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="p-3 border rounded-3 bg-light-subtle">
                                            <small class="text-muted d-block text-uppercase fw-bold mb-1" style="font-size: 0.7rem;">Kode Buku</small>
                                            <code class="fw-bold fs-5 text-primary">{{ $buku->kode_buku ?? 'N/A' }}</code>
                                        </div>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="p-3 border rounded-3 bg-light-subtle">
                                            <small class="text-muted d-block text-uppercase fw-bold mb-1" style="font-size: 0.7rem;">Stok Tersedia</small>
                                            <span class="fw-bold fs-5 text-dark">{{ $buku->stok }} Buku</span>
                                        </div>
                                    </div>
                                </div>

                                <div class="mb-4">
                                    <h6 class="fw-bold text-dark mb-3">Tipe Akses:</h6>
                                    <div class="d-flex gap-2">
                                        @if(in_array('offline', $buku->tipe_akses ?? []))
                                            <span class="badge bg-secondary-subtle text-secondary-emphasis px-3 py-2 rounded-pill">
                                                <i class="bi bi-book-half me-2"></i>Peminjaman Offline
                                            </span>
                                        @endif
                                        @if(in_array('online', $buku->tipe_akses ?? []))
                                            <span class="badge bg-info-subtle text-info-emphasis px-3 py-2 rounded-pill">
                                                <i class="bi bi-globe2 me-2"></i>Baca Online
                                            </span>
                                        @endif
                                    </div>
                                </div>

                                @if(in_array('online', $buku->tipe_akses ?? []) && $buku->file_pdf)
                                    <div class="border-top pt-4">
                                        <h6 class="fw-bold text-dark mb-2">File PDF Digital:</h6>
                                        <div class="d-flex align-items-center p-3 border rounded-3 bg-light">
                                            <i class="bi bi-file-earmark-pdf-fill text-danger fs-1 me-3"></i>
                                            <div>
                                                <p class="mb-0 fw-bold">{{ $buku->file_pdf }}</p>
                                                <small class="text-muted">Buku dapat diakses secara digital oleh siswa & guru.</small>
                                            </div>
                                        </div>
                                    </div>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
