@extends('layouts.admin')

@section('title', 'Data Pengembalian')

@section('content')
    <x-page-header title="Data Pengembalian Buku">
        <x-slot name="actions">
            <a href="{{ route('admin.peminjaman.scan') }}" class="w-full sm:w-auto bg-gray-800 hover:bg-gray-900 text-white font-bold py-2 px-4 rounded-lg transition duration-300 flex items-center gap-2 justify-center shadow-md">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm14 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"></path></svg>
                Scan Pengembalian
            </a>
        </x-slot>
    </x-page-header>

    <x-card>
        <x-table>
            <x-slot name="head">
                <x-th>Anggota</x-th>
                <x-th>Buku</x-th>
                <x-th>Tanggal Pinjam</x-th>
                <x-th>Tanggal Kembali</x-th>
                <x-th>Status</x-th>
            </x-slot>
            
            @forelse($pengembalian as $item)
                <tr class="hover:bg-gray-50 transition-colors">
                    <x-td>{{ $item->anggota->nama ?? $item->user->name ?? 'User Terhapus' }}</x-td>
                    <x-td>{{ $item->buku->judul }}</x-td>
                    <x-td>{{ \Carbon\Carbon::parse($item->tanggal_pinjam)->format('d M Y') }}</x-td>
                    <x-td>{{ \Carbon\Carbon::parse($item->tanggal_kembali)->format('d M Y') }}</x-td>
                    <x-td>
                        <x-badge color="green">Dikembalikan</x-badge>
                        @if($item->denda > 0)
                            <div class="text-xs text-red-600 font-bold mt-1">Denda: Rp {{ number_format($item->denda, 0, ',', '.') }}</div>
                        @endif
                    </x-td>
                </tr>
            @empty
                <tr>
                    <x-td colspan="5" class="text-center text-gray-500 py-8">Belum ada data pengembalian</x-td>
                </tr>
            @endforelse
        </x-table>
        
        <div class="mt-4">
            {{ $pengembalian->links() }}
        </div>
    </x-card>
@endsection
