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

    <div class="row g-3 g-md-4 min-vh-100 pb-4">

        @if (Auth::user()->role == 'penjaga perpus')
        <div class="row g-3 g-md-4 h-100">
            <div class="col-lg-8 d-flex flex-column">
                <div class="card border-0 mb-3 mb-md-4">
                    <div
                        class="card-body p-3 p-md-4 d-flex flex-column flex-sm-row align-items-center text-center text-sm-start">
                        <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 profile-avatar-lg mb-3 mb-sm-0">
                        <div class="ms-sm-4 mb-3 mb-sm-0">
                            <h4 class="fw-bold mb-1">{{ $user->name }}</h4>
                            <span class="badge rounded-pill bg-success-subtle text-success-emphasis">{{
                                Str::title($user->role) }}</span>
                        </div>
                        <div class="ms-sm-auto">
                            <a href="{{ route('profile.edit') }}"
                                class="btn btn-outline-primary rounded-pill w-100 w-sm-auto">
                                <i class="bi bi-pencil-square me-2"></i>Edit Profil
                            </a>
                        </div>
                    </div>
                </div>

                <div class="mb-3 mb-md-4 flex-grow-1">
                    <h5 class="fw-bold mb-3">Statistik Perpustakaan</h5>
                    <div class="row g-3">
                        @foreach ($statistik as $stat)
                        <div class="col-sm-6 col-lg-3">
                            <div class="card border-0 h-100">
                                <div class="card-body p-3 p-md-4 text-center">
                                    <div class="icon-circle bg-{{ $stat['color'] }}-light mx-auto mb-3"
                                        style="width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: 15px;">
                                        <i class="bi {{ $stat['icon'] }} fs-2 text-{{ $stat['color'] }}"></i>
                                    </div>
                                    <h3 class="fw-bold mb-2">{{ $stat['value'] }}</h3>
                                    <p class="text-muted mb-0 small">{{ $stat['label'] }}</p>
                                </div>
                            </div>
                        </div>
                        @endforeach
                    </div>
                </div>
            </div>

            <div class="col-lg-4 d-flex flex-column">
                <div class="card border-0 mb-3 mb-md-4 flex-grow-1">
                    <div class="card-body p-3 p-md-4 d-flex flex-column h-100">
                        <h5 class="fw-bold mb-4">Pintasan Manajemen</h5>
                        <div class="d-grid gap-3 flex-grow-1">
                            <a href="{{ route('admin.buku.index') }}"
                                class="btn btn-light text-start py-3 d-flex align-items-center">
                                <i class="bi bi-book-fill me-3 fs-4"></i>
                                <span>Kelola Buku</span>
                            </a>
                            <a href="{{ route('admin.pengguna.index') }}"
                                class="btn btn-light text-start py-3 d-flex align-items-center">
                                <i class="bi bi-people-fill me-3 fs-4"></i>
                                <span>Kelola Pengguna</span>
                            </a>
                            <a href="{{ route('admin.pengumuman.index') }}"
                                class="btn btn-light text-start py-3 d-flex align-items-center">
                                <i class="bi bi-megaphone-fill me-3 fs-4"></i>
                                <span>Kelola Pengumuman</span>
                            </a>
                        </div>
                    </div>
                </div>

                {{-- <div class="card border-0">
                    <div class="card-body p-3 p-md-4">
                        <h5 class="fw-bold mb-3">Keamanan Akun</h5>
                        <p class="small text-muted mb-3">Ubah password Anda secara berkala untuk menjaga keamanan akun.
                        </p>
                        <a href="{{ route('profile.edit') }}" class="btn btn-outline-secondary rounded-pill w-100 py-2">
                <i class="bi bi-shield-lock me-2"></i>Ubah Password
                </a>
            </div>
        </div> --}}
    </div>
    </div>

    @elseif (Auth::user()->role == 'guru')
    <div class="row g-3 g-md-4 h-100">
        <div class="col-lg-8 d-flex flex-column">
            <div class="card border-0 mb-3 mb-md-4">
                <div class="card-body p-3 p-md-4">
                    <div class="d-flex flex-column flex-sm-row align-items-center text-center text-sm-start">
                        <img src="https://ui-avatars.com/api/?name={{ urlencode($user->name) }}&background=198754&color=fff&size=80&rounded=true"
                            alt="Foto Profil" class="rounded-circle profile-avatar-lg mb-3 mb-sm-0">
                        <div class="ms-sm-4 mb-3 mb-sm-0">
                            <h4 class="fw-bold mb-1">{{ $user->name }}</h4>
                            <span class="badge rounded-pill bg-success-subtle text-success-emphasis">{{
                                    Str::title($user->role) }}</span>
                        </div>
                        <div class="ms-sm-auto">
                            <a href="{{ route('profile.edit') }}"
                                class="btn btn-outline-primary rounded-pill ms-sm-auto w-100 w-sm-auto">
                                <i class="bi bi-pencil-square me-2"></i>Edit Profil
                            </a>
                        </div>
                        <hr class="my-3 my-md-4">
                        <h5 class="fw-bold mb-3 px-4">Informasi Personal</h5>
                        <div class="row g-3 px-4 pb-4">
                            <div class="col-sm-6">
                                <small class="text-muted d-block mb-1">NIP / NUPTK</small>
                                <p class="fw-semibold mb-0">{{ $user->nuptk ?? ($user->nomor_induk ?? 'N/A') }}</p>
                            </div>
                            <div class="col-sm-6">
                                <small class="text-muted d-block mb-1">Email</small>
                                <p class="fw-semibold mb-0 text-break">{{ $user->email }}</p>
                            </div>
                            <div class="col-sm-6">
                                <small class="text-muted d-block mb-1">Nomor HP</small>
                                <p class="fw-semibold mb-0">{{ $user->phone ?? 'N/A' }}</p>
                            </div>
                        </div>
                    </div>

                    <hr class="my-3 my-md-4">
                    <h5 class="fw-bold mb-3">Informasi Personal</h5>
                    <div class="row g-3">
                        <div class="col-sm-6">
                            <small class="text-muted d-block mb-1">NIP/NIK</small>
                            <p class="fw-semibold mb-0">{{ $user->nip ?? $user->nisn ?? '-' }}</p>
                        </div>
                        <div class="col-sm-6">
                            <small class="text-muted d-block mb-1">Email</small>
                            <p class="fw-semibold mb-0 text-break">{{ $user->email }}</p>
                        </div>
                        <div class="col-sm-6">
                            <small class="text-muted d-block mb-1">Nomor HP</small>
                            <p class="fw-semibold mb-0">{{ $user->no_hp ?? '-' }}</p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card border-0 flex-grow-1">
                <div class="card-body p-3 p-md-4 d-flex flex-column h-100">
                    <div
                        class="d-flex flex-column flex-sm-row justify-content-between align-items-center mb-4 gap-3">
                        <h5 class="fw-bold mb-0">Ringkasan Laporan Minat Baca</h5>
                        <div class="ms-sm-auto">
                            <a href="{{ route('guru.laporan.index') }}"
                                class="btn btn-sm btn-outline-primary rounded-pill w-100 w-sm-auto">
                                Lihat Laporan Lengkap
                            </a>
                        </div>
                    </div>
                    <div class="row flex-grow-1">
                        <div class="col-md-6 mb-3 mb-md-0">
                            <h6 class="small text-muted mb-3 text-uppercase fw-semibold">Buku Terpopuler</h6>
                            <ul class="list-group list-group-flush laporan-list">
                                @foreach ($laporan['buku_terpopuler'] as $buku)
                                <li
                                    class="list-group-item px-0 py-3 d-flex justify-content-between align-items-center">
                                    <span class="text-truncate me-2">{{ $buku['judul'] }}</span>
                                    <span class="badge bg-primary rounded-pill">{{ $buku['total_pembaca'] }}</span>
                                </li>
                                @endforeach
                            </ul>
                        </div>
                        <div class="col-md-6">
                            <h6 class="small text-muted mb-3 text-uppercase fw-semibold">Kategori Terpopuler</h6>
                            <ul class="list-group list-group-flush laporan-list">
                                @foreach ($laporan['kategori_populer'] as $kategori)
                                <li
                                    class="list-group-item px-0 py-3 d-flex justify-content-between align-items-center">
                                    <span class="text-truncate me-2">{{ $kategori['nama'] }}</span>
                                    <span class="badge bg-success rounded-pill">{{ $kategori['total_pembaca']
                                            }}</span>
                                </li>
                                @endforeach
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            @include('profile.partials.personal-activities', [
            'bukuOffline' => $bukuOffline,
            'bukuOnline' => $bukuOnline,
            ])
        </div>
    </div>

    @else
    <div class="row g-3 g-md-4 h-100">
        <div class="col-lg-8 d-flex flex-column">
            <div class="card border-0 mb-3 mb-md-4">
                <div class="card-body p-3 p-md-4">
                    <div class="d-flex flex-column flex-sm-row align-items-center text-center text-sm-start">
                        <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 profile-avatar-lg mb-3 mb-sm-0">
                        <div class="ms-sm-4 mb-3 mb-sm-0">
                            <h4 class="fw-bold mb-1">{{ $user->name }}</h4>
                            <span class="badge rounded-pill bg-primary-subtle text-primary-emphasis">{{
                                    Str::title($user->role) }}</span>
                        </div>
                        <div class="ms-sm-auto">
                            <a href="{{ route('profile.edit') }}"
                                class="btn btn-outline-primary rounded-pill ms-md-auto">
                                <i class="bi bi-pencil-square me-2"></i>Edit Profil
                            </a>
                        </div>
                        <hr class="my-3 my-md-4">
                        <h5 class="fw-bold mb-3">Informasi Personal</h5>
                        <div class="row g-3">
                            <div class="col-sm-6">
                                <small class="text-muted d-block mb-1">NISN</small>
                                <p class="fw-semibold mb-0">{{ $user->nomor_induk ?? 'N/A' }}</p>
                            </div>
                            <div class="col-sm-6">
                                <small class="text-muted d-block mb-1">Email</small>
                                <p class="fw-semibold mb-0 text-break">{{ $user->email }}</p>
                            </div>
                            <div class="col-sm-6">
                                <small class="text-muted d-block mb-1">Nomor HP</small>
                                <p class="fw-semibold mb-0">{{ $user->phone ?? 'N/A' }}</p>
                            </div>
                            <div class="col-sm-6">
                                <small class="text-muted d-block mb-1">Kelas</small>
                                <p class="fw-semibold mb-0">{{ $user->kelas ?? 'N/A' }}</p>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="mb-3 mb-md-4 flex-grow-1">
                    <h5 class="fw-bold mb-3">Statistik Saya</h5>
                    <div class="row g-3">
                        @foreach ($statistik as $stat)
                        <div class="col-sm-6 col-lg-3">
                            <div class="card border-0 h-100">
                                <div class="card-body p-3 p-md-4 text-center">
                                    <div class="icon-circle bg-{{ $stat['color'] }}-light mx-auto mb-3"
                                        style="width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: 15px;">
                                        <i class="bi {{ $stat['icon'] }} fs-2 text-{{ $stat['color'] }}"></i>
                                    </div>
                                    <h3 class="fw-bold mb-2">{{ $stat['value'] }}</h3>
                                    <p class="text-muted mb-0 small">{{ $stat['label'] }}</p>
                                </div>
                            </div>
                        </div>
                        @endforeach
                    </div>
                </div>
            </div>

            <div class="col-lg-4">
                @include('profile.partials.personal-activities', [
                'bukuOffline' => $bukuOffline,
                'bukuOnline' => $bukuOnline,
                ])
            </div>
        </div>
        @endif

    </div>
</x-app-layout>