@extends('layouts.app')

@section('title', 'Detail Pengguna - ' . $user->name)

@push('head')
<style>
    .profile-shell {
        position: relative;
        max-width: 980px;
        margin: 0 auto;
        padding: 32px 36px;
        border-radius: 28px;
        background: linear-gradient(150deg, rgba(12, 24, 52, 0.96), rgba(7, 15, 36, 0.9));
        border: 1px solid rgba(148, 163, 184, 0.22);
        box-shadow: 0 40px 80px rgba(3, 7, 18, 0.55);
        overflow: hidden;
    }

    .profile-shell::before,
    .profile-shell::after {
        content: "";
        position: absolute;
        inset: 0;
        pointer-events: none;
    }

    .profile-shell::before {
        background:
            radial-gradient(circle at 12% 16%, rgba(99, 102, 241, 0.32), transparent 55%),
            radial-gradient(circle at 86% -6%, rgba(56, 189, 248, 0.28), transparent 60%);
        opacity: 0.9;
    }

    .profile-shell::after {
        background: linear-gradient(135deg, transparent 40%, rgba(59, 130, 246, 0.14));
        opacity: 0.8;
    }

    .profile-shell > * { position: relative; z-index: 1; }

    .profile-hero {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 24px;
        flex-wrap: wrap;
    }

    .profile-hero__info {
        display: flex;
        flex-direction: column;
        gap: 12px;
        max-width: 560px;
    }

    .profile-hero__tagline {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 6px 14px;
        border-radius: 999px;
        background: rgba(129, 140, 248, 0.18);
        border: 1px solid rgba(129, 140, 248, 0.38);
        color: #e0e7ff;
        font-size: 12px;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        font-weight: 600;
    }

    .profile-hero__info h2 {
        margin: 0;
        font-size: 32px;
        font-weight: 700;
        letter-spacing: -0.02em;
        color: #f8fafc;
    }

    .profile-hero__info p {
        margin: 0;
        color: rgba(226, 232, 240, 0.78);
        font-size: 15px;
        line-height: 1.6;
    }

    .profile-hero__actions {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
        align-items: center;
    }

    .profile-hero__actions .btn {
        border-radius: 14px;
        padding: 10px 18px;
        border: none;
        cursor: pointer;
        font-weight: 700;
        letter-spacing: 0.04em;
        transition: transform 0.18s ease, box-shadow 0.18s ease;
    }

    .btn-primary {
        background: linear-gradient(135deg, #2563eb, #1d4ed8);
        color: #f8fafc;
    }

    .btn-success {
        background: linear-gradient(135deg, #16a34a, #22c55e);
        color: #f8fafc;
    }

    .btn-warning {
        background: linear-gradient(135deg, #f59e0b, #d97706);
        color: #f8fafc;
    }

    .btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 18px 32px rgba(14, 165, 233, 0.22);
    }

    .profile-summary {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
        gap: 18px;
        margin-top: 32px;
    }

    .profile-card {
        padding: 24px;
        border-radius: 24px;
        background: rgba(8, 16, 34, 0.82);
        border: 1px solid rgba(148, 163, 184, 0.18);
        box-shadow: inset 0 1px 0 rgba(148, 163, 184, 0.12);
    }

    .profile-card h3 {
        margin: 0 0 18px;
        color: #f8fafc;
        font-size: 1.05rem;
        font-weight: 700;
    }

    .profile-field {
        display: grid;
        gap: 10px;
        margin-bottom: 18px;
    }

    .profile-label {
        font-size: 12px;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: rgba(203, 213, 225, 0.72);
        font-weight: 700;
    }

    .profile-value {
        color: #e2e8f0;
        font-size: 0.95rem;
        font-weight: 600;
        background: rgba(7, 15, 34, 0.9);
        border: 1px solid rgba(148, 163, 184, 0.16);
        border-radius: 14px;
        padding: 14px 16px;
    }

    .status-pill {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 10px 16px;
        border-radius: 999px;
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }

    .status-success {
        background: rgba(34, 197, 94, 0.18);
        color: #bbf7d0;
        border: 1px solid rgba(34, 197, 94, 0.3);
    }

    .status-warning {
        background: rgba(245, 158, 11, 0.18);
        color: #fde68a;
        border: 1px solid rgba(245, 158, 11, 0.3);
    }

    .status-danger {
        background: rgba(248, 113, 113, 0.18);
        color: #fecaca;
        border: 1px solid rgba(248, 113, 113, 0.3);
    }

    .profile-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 24px;
        margin-top: 32px;
    }

    .profile-grid-2 {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 18px;
        margin-top: 18px;
    }

    .summary-card {
        padding: 18px 20px;
        border-radius: 20px;
        background: linear-gradient(145deg, rgba(12, 21, 44, 0.9), rgba(19, 35, 70, 0.84));
        border: 1px solid rgba(148, 163, 184, 0.18);
    }

    .summary-card__label {
        display: block;
        font-size: 12px;
        color: rgba(203, 213, 225, 0.72);
        margin-bottom: 10px;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        font-weight: 700;
    }

    .summary-card__value {
        font-size: 1.75rem;
        font-weight: 700;
        color: #f8fafc;
    }

    .summary-card__meta {
        color: rgba(203, 213, 225, 0.72);
        margin-top: 10px;
        font-size: 12px;
    }

    @media (max-width: 768px) {
        .profile-hero,
        .profile-grid,
        .profile-grid-2 {
            grid-template-columns: 1fr;
        }

        .profile-hero {
            align-items: stretch;
        }
    }
</style>
@endpush

@section('content')
@php
    $createdAt = $user->created_at?->timezone(config('app.timezone'));
    $updatedAt = $user->updated_at?->timezone(config('app.timezone'));
@endphp

<div class="profile-shell">
    <div class="profile-hero">
        <div class="profile-hero__info">
            <span class="profile-hero__tagline">Detail Pengguna</span>
            <h2>{{ $user->name }}</h2>
            <p>Informasi akun pegawai ditampilkan dengan tampilan konsisten seperti profil user. Gunakan halaman ini untuk melihat detail serta menyetujui akun.</p>
        </div>
        <div class="profile-hero__actions">
            <a href="{{ route('admin.users.index') }}" class="btn btn-primary">Kembali</a>
            <form method="POST" action="{{ route('admin.users.approval-toggle', $user->id) }}" style="margin:0;">
                @csrf
                @method('PATCH')
                <input type="hidden" name="is_approved" value="{{ $user->is_approved ? 0 : 1 }}">
                <button type="submit" class="btn {{ $user->is_approved ? 'btn-warning' : 'btn-success' }}">
                    {{ $user->is_approved ? 'Batalkan Persetujuan' : 'Setujui Akun' }}
                </button>
            </form>
        </div>
    </div>

    <div class="profile-grid">
        <div class="profile-card">
            <h3>Informasi Utama</h3>
            <div class="profile-field">
                <label>Nama</label>
                <div class="profile-value">{{ $user->name }}</div>
            </div>
            <div class="profile-field">
                <label>Username</label>
                <div class="profile-value">{{ $user->username ?? '-' }}</div>
            </div>
            <div class="profile-field">
                <label>Email</label>
                <div class="profile-value">{{ $user->email }}</div>
            </div>
            <div class="profile-field">
                <label>NIK</label>
                <div class="profile-value">{{ $user->nik ?? '-' }}</div>
            </div>
            <div class="profile-field">
                <label>Role</label>
                <div class="profile-value">{{ $user->role ? ucfirst($user->role) : '-' }}</div>
            </div>
        </div>

        <div class="profile-card">
            <h3>Status & Persetujuan</h3>
            <div class="profile-field">
                <label>Status Verifikasi Email</label>
                <div class="profile-value">
                    <span class="status-pill {{ $user->email_verified_at ? 'status-success' : 'status-warning' }}">
                        {{ $user->email_verified_at ? 'Terverifikasi' : 'Belum Verifikasi' }}
                    </span>
                </div>
            </div>
            <div class="profile-field">
                <label>Status Persetujuan</label>
                <div class="profile-value">
                    <span class="status-pill {{ $user->is_approved ? 'status-success' : 'status-danger' }}">
                        {{ $user->is_approved ? 'Disetujui Admin' : 'Menunggu Persetujuan' }}
                    </span>
                </div>
            </div>
            <div class="profile-field">
                <label>Status Absensi</label>
                <div class="profile-value">{{ $user->attendance_enabled ? 'Aktif' : 'Nonaktif' }}</div>
            </div>
            <div class="profile-field">
                <label>Terakhir Login</label>
                <div class="profile-value">{{ $user->last_login_at?->timezone(config('app.timezone'))->format('d M Y H:i') ?? '-' }}</div>
            </div>
        </div>
    </div>

    <div class="profile-grid-2">
        <div class="profile-card">
            <h3>Kontak</h3>
            <div class="profile-field">
                <label>No. HP</label>
                <div class="profile-value">{{ $user->phone ?? '-' }}</div>
            </div>
            <div class="profile-field">
                <label>Alamat</label>
                <div class="profile-value">{{ $user->address ?? '-' }}</div>
            </div>
        </div>

        <div class="profile-card">
            <h3>Ringkasan Akun</h3>
            <div class="profile-field">
                <label>Terdaftar</label>
                <div class="profile-value">{{ $createdAt?->format('d/m/Y H:i') ?? '-' }}</div>
            </div>
            <div class="profile-field">
                <label>Update Terakhir</label>
                <div class="profile-value">{{ $updatedAt?->format('d/m/Y H:i') ?? '-' }}</div>
            </div>
        </div>
    </div>

    <div class="profile-summary">
        <div class="summary-card">
            <span class="summary-card__label">Hadir</span>
            <span class="summary-card__value">{{ $attendanceRecords->where('status', 'hadir')->count() }}</span>
            <span class="summary-card__meta">Jumlah kehadiran</span>
        </div>
        <div class="summary-card">
            <span class="summary-card__label">Tidak Hadir</span>
            <span class="summary-card__value">{{ $attendanceRecords->where('status', '!=', 'hadir')->count() }}</span>
            <span class="summary-card__meta">Absen, izin, sakit, tidak valid</span>
        </div>
        <div class="summary-card">
            <span class="summary-card__label">Izin / Sakit</span>
            <span class="summary-card__value">{{ $attendanceRecords->whereIn('status', ['izin', 'sakit'])->count() }}</span>
            <span class="summary-card__meta">Permintaan izin</span>
        </div>
        <div class="summary-card">
            <span class="summary-card__label">Total Data</span>
            <span class="summary-card__value">{{ $attendanceRecords->count() }}</span>
            <span class="summary-card__meta">Riwayat kehadiran</span>
        </div>
    </div>
</div>
@endsection
