@extends('layouts.admin')

@section('title', 'Data Buku Tamu')

@section('content')
    <x-page-header title="Data Buku Tamu" />

    <x-card>
        <x-table>
            <x-slot name="head">
                <x-th>No</x-th>
                <x-th>Nama Pengunjung</x-th>
                <x-th>Tipe</x-th>
                <x-th>Tujuan</x-th>
                <x-th>Tanggal</x-th>
            </x-slot>
            
            @forelse($bukuTamu as $item)
                <tr class="hover:bg-gray-50 transition-colors">
                    <x-td>{{ $bukuTamu->firstItem() + $loop->index }}</x-td>
                    <x-td>
                        @if($item->user)
                            {{-- Member path: data dari users --}}
                            <div class="font-medium text-gray-900">{{ $item->user->name }}</div>
                            <div class="text-xs text-gray-500">{{ $item->user->email }}</div>
                        @elseif($item->nama_tamu)
                            {{-- Tamu path: data manual --}}
                            <div class="font-medium text-gray-900">{{ $item->nama_tamu }}</div>
                            <div class="text-xs text-gray-500">{{ $item->asal_instansi ?? '-' }}</div>
                        @else
                            <div class="text-gray-400">-</div>
                        @endif
                    </x-td>
                    <x-td>
                        @if($item->id_user)
                            <x-badge color="blue">Anggota</x-badge>
                        @else
                            <x-badge color="gray">Pengunjung</x-badge>
                        @endif
                    </x-td>
                    <x-td>{{ $item->tujuan_kunjungan }}</x-td>
                    <x-td>{{ \Carbon\Carbon::parse($item->tanggal_kunjungan)->format('d M Y') }}</x-td>
                </tr>
            @empty
                <tr>
                    <x-td colspan="5" class="text-center text-gray-500 py-8">Belum ada data buku tamu</x-td>
                </tr>
            @endforelse
        </x-table>
        
        <div class="mt-4">
            {{ $bukuTamu->links() }}
        </div>
    </x-card>
@endsection
