@extends('admin.layout.main')

@section('title', 'PeGas - Detail User')

@section('content')
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-gray-800">Detail Pengguna</h1>
    <a href="{{ route('admin.data-user') }}" class="btn btn-sm btn-secondary shadow-sm">
        <i class="fas fa-arrow-left fa-sm text-white-50 mr-1"></i> Kembali
    </a>
</div>

<div class="row">
    <div class="col-xl-4 col-lg-5">
        <div class="card shadow mb-4">
            <div class="card-body text-center">
                <div class="mb-3">
                    <img class="img-profile rounded-circle img-thumbnail" 
                         src="https://ui-avatars.com/api/?name={{ urlencode($user->name) }}&background=7EBC12&color=fff&size=128" 
                         alt="{{ $user->name }}">
                </div>
                <h5 class="font-weight-bold text-dark">{{ $user->name }}</h5>
                <p class="text-muted small">{{ $user->email }}</p>
                <hr>
                <div class="text-left">
                    <label class="small font-weight-bold text-primary">Alamat Pangkalan:</label>
                    <p class="text-gray-800">{{ $user->alamat ?? 'Alamat belum diatur' }}</p>
                    
                    <label class="small font-weight-bold text-primary">Bergabung Sejak:</label>
                    <p class="text-gray-800">{{ $user->created_at->translatedFormat('d F Y') }}</p>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-8 col-lg-7">
        <div class="row">
            <div class="col-md-6 mb-4">
                <div class="card border-left-primary shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Prediksi</div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">{{ $user->hasil_prediksis_count }} Hari</div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-chart-line fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-md-6 mb-4">
                <div class="card border-left-success shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-success text-uppercase mb-1">Total Bantuan</div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">{{ $user->helpdesks_count }}</div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-comments fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">Riwayat Aktivitas Pengguna</h6>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-sm table-hover mb-0">
                        <thead class="bg-gray-100">
                            <tr>
                                <th>Jenis Aktivitas</th>
                                <th>Waktu Aktivitas</th>
                                <th class="text-center" style="width: 15%">Status</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($riwayatAktivitas as $aktivitas)
                                <tr>
                                    <td class="align-middle py-2">
                                        <i class="{{ $aktivitas['icon'] }} fa-fw mr-2"></i>{{ $aktivitas['jenis'] }}
                                    </td>
                                    <td class="align-middle py-2">
                                        {{ $aktivitas['tanggal']->translatedFormat('d F Y, H:i') }} WIB
                                    </td>
                                    <td class="text-center align-middle py-2">
                                        <span class="badge badge-{{ $aktivitas['badge'] }} px-2 py-1 shadow-sm text-xs font-weight-bold">
                                            {{ $aktivitas['status'] }}
                                        </span>
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="3" class="text-center py-5 text-muted">
                                        <i class="fas fa-history fa-2x mb-2 d-block opacity-25"></i>
                                        Belum ada rekaman riwayat aktivitas dari pengguna ini.
                                    </td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection