

<?php $__env->startSection('title', 'Detail Pegawai'); ?>
<?php $__env->startSection('subtitle', 'Informasi lengkap dan timeline akses'); ?>

<?php $__env->startSection('breadcrumb'); ?>
    <li class="flex items-center">
        <i class="fas fa-chevron-right text-xs text-secondary-400 mx-2"></i>
        <a href="<?php echo e(route('employees.index')); ?>" class="text-sm font-medium text-secondary-500 hover:text-primary-600">Pegawai</a>
    </li>
    <li class="flex items-center">
        <i class="fas fa-chevron-right text-xs text-secondary-400 mx-2"></i>
        <span class="text-sm font-medium text-secondary-700">Detail</span>
    </li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('actions'); ?>
    <a href="<?php echo e(route('employees.edit', $employee)); ?>" class="px-5 py-2.5 bg-amber-500 hover:bg-amber-600 text-white font-medium rounded-xl shadow-lg shadow-amber-500/25 transition-all flex items-center">
        <i class="fas fa-edit mr-2"></i>Edit
    </a>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<!-- Profile Header -->
<div class="glass-card rounded-2xl p-6 mb-6">
    <div class="flex flex-col md:flex-row items-start md:items-center">
        <div class="w-20 h-20 rounded-2xl bg-gradient-to-br from-primary-400 to-primary-600 text-white flex items-center justify-center text-3xl font-bold shadow-lg">
            <?php echo e(substr($employee->name, 0, 2)); ?>

        </div>
        <div class="mt-4 md:mt-0 md:ml-6 flex-1">
            <div class="flex flex-col md:flex-row md:items-center justify-between">
                <div>
                    <h1 class="text-2xl font-bold text-secondary-800"><?php echo e($employee->name); ?></h1>
                    <p class="text-secondary-500"><?php echo e($employee->nip); ?> • <?php echo e($employee->position); ?></p>
                </div>
                <div class="mt-3 md:mt-0">
                    <?php
                        $statusColors = [
                            'active' => 'bg-emerald-100 text-emerald-800',
                            'retiring' => 'bg-amber-100 text-amber-800',
                            'retired' => 'bg-gray-100 text-gray-800',
                            'extended' => 'bg-purple-100 text-purple-800',
                        ];
                    ?>
                    <span class="inline-flex items-center px-4 py-2 rounded-full text-sm font-medium <?php echo e($statusColors[$employee->status] ?? 'bg-secondary-100'); ?>">
                        <span class="w-2 h-2 rounded-full mr-2 <?php echo e($employee->status === 'active' ? 'bg-emerald-500' : ($employee->status === 'retiring' ? 'bg-amber-500' : 'bg-gray-500')); ?>"></span>
                        <?php echo e(ucfirst($employee->status)); ?>

                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
    <!-- Left: Info & Timeline -->
    <div class="lg:col-span-2 space-y-6">
        
        <!-- Personal Info -->
        <div class="glass-card rounded-2xl p-6">
            <h3 class="text-lg font-bold text-secondary-800 mb-4 flex items-center">
                <i class="fas fa-id-card text-primary-500 mr-2"></i>Informasi Pribadi
            </h3>
            <div class="grid grid-cols-2 gap-4">
                <div>
                    <p class="text-xs text-secondary-500 uppercase">Email</p>
                    <p class="text-sm font-medium text-secondary-800"><?php echo e($employee->email); ?></p>
                </div>
                <div>
                    <p class="text-xs text-secondary-500 uppercase">Telepon</p>
                    <p class="text-sm font-medium text-secondary-800"><?php echo e($employee->phone ?? '-'); ?></p>
                </div>
                <div>
                    <p class="text-xs text-secondary-500 uppercase">Departemen</p>
                    <p class="text-sm font-medium text-secondary-800"><?php echo e($employee->department->name); ?></p>
                </div>
                <div>
                    <p class="text-xs text-secondary-500 uppercase">Status Kepegawaian</p>
                    <p class="text-sm font-medium text-secondary-800 capitalize"><?php echo e(str_replace('_', ' ', $employee->employment_status)); ?></p>
                </div>
                <div>
                    <p class="text-xs text-secondary-500 uppercase">Tanggal Masuk</p>
                    <p class="text-sm font-medium text-secondary-800"><?php echo e($employee->join_date->format('d M Y')); ?></p>
                </div>
                <div>
                    <p class="text-xs text-secondary-500 uppercase">Masa Kerja</p>
                    <p class="text-sm font-medium text-secondary-800"><?php echo e($employee->join_date->diffForHumans(null, true)); ?></p>
                </div>
            </div>
        </div>

        <!-- Retirement Info -->
        <?php if($employee->retirement_date): ?>
        <div class="glass-card rounded-2xl p-6 border-l-4 <?php echo e($employee->retirement_date->isPast() ? 'border-gray-400' : ($employee->retirement_date->diffInDays(now()) <= 7 ? 'border-rose-500' : 'border-amber-500')); ?>">
            <h3 class="text-lg font-bold text-secondary-800 mb-4 flex items-center">
                <i class="fas fa-calendar-times text-amber-500 mr-2"></i>Informasi Pensiun/Resign
            </h3>
            <div class="grid grid-cols-2 gap-4 mb-4">
                <div>
                    <p class="text-xs text-secondary-500 uppercase">Tanggal</p>
                    <p class="text-lg font-bold <?php echo e($employee->retirement_date->isPast() ? 'text-gray-600' : ($employee->retirement_date->diffInDays(now()) <= 7 ? 'text-rose-600' : 'text-amber-600')); ?>">
                        <?php echo e($employee->retirement_date->format('d M Y')); ?>

                    </p>
                </div>
                <div>
                    <p class="text-xs text-secondary-500 uppercase">Tipe</p>
                    <p class="text-sm font-medium text-secondary-800 capitalize"><?php echo e(str_replace('_', ' ', $employee->retirement_type)); ?></p>
                </div>
            </div>
            <?php if($employee->retirement_document): ?>
            <a href="<?php echo e(asset('storage/' . $employee->retirement_document)); ?>" target="_blank" class="inline-flex items-center px-4 py-2 bg-rose-50 text-rose-600 rounded-lg text-sm font-medium hover:bg-rose-100 transition-colors">
                <i class="fas fa-file-pdf mr-2"></i>Lihat Dokumen
            </a>
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <!-- Access Timeline -->
        <div class="glass-card rounded-2xl p-6">
            <div class="flex items-center justify-between mb-6">
                <h3 class="text-lg font-bold text-secondary-800 flex items-center">
                    <i class="fas fa-history text-primary-500 mr-2"></i>Timeline Akses
                </h3>
                <button onclick="document.getElementById('addAccessModal').classList.remove('hidden')" class="px-4 py-2 bg-primary-500 hover:bg-primary-600 text-white text-sm font-medium rounded-lg transition-all">
                    <i class="fas fa-plus mr-1"></i>Tambah Akses
                </button>
            </div>

            <div class="space-y-4">
                <?php $__empty_1 = true; $__currentLoopData = $employee->accessDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $access): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="relative pl-8 pb-4 border-l-2 <?php echo e($access->status === 'revoked' ? 'border-gray-300' : 'border-primary-300'); ?> last:border-0">
                        <div class="absolute -left-2.5 top-0 w-5 h-5 rounded-full <?php echo e($access->status === 'active' ? 'bg-emerald-400' : ($access->status === 'extended' ? 'bg-amber-400' : 'bg-gray-400')); ?> border-2 border-white shadow-sm"></div>
                        <div class="bg-white/50 rounded-xl p-4">
                            <div class="flex items-center justify-between">
                                <div>
                                    <p class="font-semibold text-secondary-800"><?php echo e($access->accessCatalog->name); ?></p>
                                    <p class="text-xs text-secondary-500"><?php echo e($access->accessCatalog->code); ?> • <?php echo e($access->accessCatalog->getCategoryLabelAttribute()); ?></p>
                                </div>
                                <div class="flex items-center space-x-2">
                                    <?php if($access->status !== 'revoked'): ?>
                                        <span class="px-2 py-1 rounded-full text-xs font-medium <?php echo e($access->daysUntilExpiry() <= 7 ? 'bg-rose-100 text-rose-700' : 'bg-emerald-100 text-emerald-700'); ?>">
                                            <?php echo e($access->daysUntilExpiry()); ?> hari
                                        </span>
                                        <a href="<?php echo e(route('extensions.create', $access)); ?>" class="p-1.5 text-amber-600 hover:bg-amber-50 rounded-lg" title="Perpanjang">
                                            <i class="fas fa-clock"></i>
                                        </a>
                                        <form action="<?php echo e(route('revocations.revoke', $access)); ?>" method="POST" class="inline" onsubmit="return confirm('Cabut akses ini?')">
                                            <?php echo csrf_field(); ?>
                                            <input type="hidden" name="confirm" value="REVOKE">
                                            <button type="submit" class="p-1.5 text-rose-600 hover:bg-rose-50 rounded-lg" title="Cabut">
                                                <i class="fas fa-ban"></i>
                                            </button>
                                        </form>
                                    <?php else: ?>
                                        <span class="px-2 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-700">Revoked</span>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="mt-2 flex items-center text-xs text-secondary-500 space-x-4">
                                <span><i class="far fa-calendar-plus mr-1"></i> <?php echo e($access->granted_date->format('d M Y')); ?></span>
                                <span><i class="far fa-calendar-times mr-1"></i> <?php echo e($access->current_expiry_date->format('d M Y')); ?></span>
                                <?php if($access->is_extended): ?>
                                    <span class="text-amber-600"><i class="fas fa-history mr-1"></i> Extended <?php echo e($access->extension_count); ?>x</span>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <div class="text-center py-8 text-secondary-400">
                        <i class="fas fa-inbox text-3xl mb-2"></i>
                        <p>Belum ada akses yang diberikan</p>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <!-- Right: Summary -->
    <div class="space-y-6">
        <div class="glass-card rounded-2xl p-6">
            <h3 class="text-lg font-bold text-secondary-800 mb-4">Ringkasan Akses</h3>
            <div class="space-y-3">
                <div class="flex items-center justify-between p-3 bg-emerald-50 rounded-lg">
                    <span class="text-sm text-emerald-700">Aktif</span>
                    <span class="font-bold text-emerald-700"><?php echo e($employee->accessDetails->where('status', 'active')->count()); ?></span>
                </div>
                <div class="flex items-center justify-between p-3 bg-amber-50 rounded-lg">
                    <span class="text-sm text-amber-700">Extended</span>
                    <span class="font-bold text-amber-700"><?php echo e($employee->accessDetails->where('status', 'extended')->count()); ?></span>
                </div>
                <div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
                    <span class="text-sm text-gray-700">Revoked</span>
                    <span class="font-bold text-gray-700"><?php echo e($employee->accessDetails->where('status', 'revoked')->count()); ?></span>
                </div>
            </div>
        </div>

        <div class="glass-card rounded-2xl p-6">
            <h3 class="text-lg font-bold text-secondary-800 mb-4">Aktivitas Terbaru</h3>
            <div class="space-y-3 text-sm">
                <?php $__empty_1 = true; $__currentLoopData = $employee->accessDetails->flatMap->revocationLogs->sortByDesc('created_at')->take(5); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="flex items-start space-x-3">
                        <div class="w-2 h-2 rounded-full bg-primary-400 mt-1.5"></div>
                        <div>
                            <p class="text-secondary-700"><?php echo e($log->employeeAccessDetail->accessCatalog->name); ?> <?php echo e($log->method === 'automatic' ? 'auto-revoked' : 'revoked'); ?></p>
                            <p class="text-xs text-secondary-400"><?php echo e($log->created_at->diffForHumans()); ?></p>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <p class="text-secondary-400 text-center py-4">Belum ada aktivitas</p>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<!-- Add Access Modal -->
<div id="addAccessModal" class="hidden fixed inset-0 z-50 overflow-y-auto">
    <div class="flex items-center justify-center min-h-screen px-4">
        <div class="fixed inset-0 bg-secondary-900/75" onclick="document.getElementById('addAccessModal').classList.add('hidden')"></div>
        <div class="relative glass-card rounded-2xl p-6 w-full max-w-lg">
            <h3 class="text-lg font-bold text-secondary-800 mb-4">Tambah Akses Baru</h3>
            <form action="<?php echo e(route('employee-access.store', $employee)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-secondary-700 mb-2">Pilih Akses</label>
                    <select name="access_catalog_id" required class="w-full px-4 py-3 bg-white/60 border border-secondary-200 rounded-xl text-sm">
                        <?php $__currentLoopData = \App\Models\AccessCatalog::active()->whereNotIn('id', $employee->accessDetails->pluck('access_catalog_id'))->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $catalog): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($catalog->id); ?>"><?php echo e($catalog->name); ?> (<?php echo e($catalog->code); ?>)</option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-secondary-700 mb-2">Tanggal Diberikan</label>
                    <input type="date" name="granted_date" value="<?php echo e(now()->format('Y-m-d')); ?>" required class="w-full px-4 py-3 bg-white/60 border border-secondary-200 rounded-xl text-sm">
                </div>
                <div class="flex justify-end space-x-3">
                    <button type="button" onclick="document.getElementById('addAccessModal').classList.add('hidden')" class="px-4 py-2 text-secondary-600 hover:bg-secondary-50 rounded-lg">Batal</button>
                    <button type="submit" class="px-4 py-2 bg-primary-500 text-white rounded-lg hover:bg-primary-600">Tambah</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\codingan\access-control-management\resources\views/employees/show.blade.php ENDPATH**/ ?>