@section('page-title', 'Profile')
<x-app-layout>
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h2 mb-0">Profil Saya</h1>
    </div>

    <div class="row">
        {{-- Section Left --}}
        <div class="col-lg-8">
            <div class="card border-0 mb-4">
                <div class="card-body p-4">
                    <div class="d-flex align-items-center">
                        <img src="https://ui-avatars.com/api/?name={{ urlencode($user->name) }}&background=435ebe&color=fff&size=80&rounded=true"
                            alt="Foto Profil" class="rounded-circle flex-shrink-0">
                        <div class="ms-4">
                            <h4 class="fw-bold mb-1">{{ $user->name }}</h4>
                            <span class="badge rounded-pill bg-primary-soft">{{ $user->role }}</span>
                        </div>
                        <a href="{{ route('profile.edit') }}" class="btn btn-outline-primary rounded-pill ms-auto">
                            <i class="bi bi-pencil-square me-2"></i>Edit Profil
                        </a>
                    </div>

                    <hr class="my-4">

                    {{-- Informasi Personal --}}
                    <h5 class="fw-bold mb-3">Informasi Personal</h5>
                    <div class="row g-4">
                        <div class="col-md-6 d-flex">
                            <i class="bi bi-person-badge text-primary fs-4 me-3"></i>
                            <div>
                                <small class="text-muted">NISN</small>
                                <p class="fw-semibold mb-0">{{ $user->nisn }}</p>
                            </div>
                        </div>
                        <div class="col-md-6 d-flex">
                            <i class="bi bi-envelope text-primary fs-4 me-3"></i>
                            <div>
                                <small class="text-muted">Email</small>
                                <p class="fw-semibold mb-0">{{ $user->email }}</p>
                            </div>
                        </div>
                        <div class="col-md-6 d-flex">
                            <i class="bi bi-telephone text-primary fs-4 me-3"></i>
                            <div>
                                <small class="text-muted">Nomor HP</small>
                                <p class="fw-semibold mb-0">{{ $user->nomor_hp }}</p>
                            </div>
                        </div>
                        <div class="col-md-6 d-flex">
                            <i class="bi bi-building text-primary fs-4 me-3"></i>
                            <div>
                                <small class="text-muted">Kelas</small>
                                <p class="fw-semibold mb-0">{{ $user->kelas }} / {{ $user->golongan }}</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {{-- Statistic Card --}}
            <div class="card border-0">
                <div class="card-body p-4">
                    <div class="section-header mb-3">
                        <h5 class="mb-0">Statistik Saya</h5>
                    </div>
                    <div class="d-flex justify-content-around text-center">
                        @foreach ($statistik as $stat)
                            <div class="flex-fill">
                                <i class="bi {{ $stat['icon'] }} fs-4 text-{{ $stat['color'] }}"></i>
                                <h5 class="fw-bolder mb-0 mt-2">{{ $stat['value'] }}</h5>
                                <small class="text-muted">{{ $stat['label'] }}</small>
                            </div>
                        @endforeach
                    </div>
                </div>
            </div>
        </div>

        {{-- Right Section --}}
        <div class="col-lg-4">
            {{-- Card Buku yang Dipinjam --}}
            <div class="card border-0 mb-4">
                <div class="card-body p-4">
                    <div class="section-header">
                        <h5 class="mb-0">Buku yang Dipinjam</h5>
                    </div>
                    <ul class="list-group list-group-flush mt-3">
                        @forelse ($bukuOffline as $buku)
                            <li class="list-group-item px-0">
                                <h6 class="fw-semibold mb-1">{{ $buku['judul'] }}</h6>
                                <small class="text-muted">{{ $buku['penulis'] }}</small>
                                <span class="badge bg-danger-light text-danger float-end">Sisa
                                    {{ $buku['sisa_hari'] }} hari</span>
                            </li>
                        @empty
                            <li class="list-group-item px-0 text-center text-muted small py-3">Tidak ada buku yang
                                sedang dipinjam.</li>
                        @endforelse
                    </ul>
                </div>
            </div>

            {{-- Card Riwayat Online --}}
            <div class="card border-0 mb-4">
                <div class="card-body p-4">
                    <div class="section-header">
                        <h5 class="mb-0">Riwayat Baca Online</h5>
                    </div>
                    <ul class="list-group list-group-flush mt-3">
                        @forelse ($bukuOnline as $buku)
                            <li class="list-group-item px-0">
                                <h6 class="fw-semibold mb-1">{{ $buku['judul'] }}</h6>
                                <small class="text-muted">{{ $buku['penulis'] }}</small>
                                <span class="badge bg-primary-light text-primary float-end">Progress
                                    {{ $buku['progress'] }}%</span>
                            </li>
                        @empty
                            <li class="list-group-item px-0 text-center text-muted small py-3">Tidak ada riwayat buku
                                yang dibaca.</li>
                        @endforelse
                    </ul>
                </div>
            </div>

            {{-- Card Keamanan Akun --}}
            <div class="card border-0">
                <div class="card-body p-4">
                    <div class="section-header mb-3">
                        <h5 class="mb-0">Keamanan Akun</h5>
                    </div>
                    <p class="small text-muted">Ubah password Anda secara berkala untuk menjaga keamanan akun.</p>
                    <a href="{{ route('profile.edit') }}#security" class="btn btn-outline-secondary rounded-pill">Ubah
                        Password</a>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
