@extends('layouts.admin')

@section('title', 'Detail Proyeksi Pensiun')

@section('content')
<div class="content-header mb-4">
    <div class="d-flex justify-content-between align-items-center">
        <div>
            <h4 class="mb-1">Detail Proyeksi Pensiun</h4>
        </div>
        <div>
            <a href="{{ route('admin.dashboard.pensiun.sudah') }}" class="btn btn-outline-primary me-2">
                <i class="fas fa-history me-1"></i> Data Sudah Pensiun
            </a>
            <a href="{{ route('admin.dashboard') }}" class="btn btn-outline-secondary">
                <i class="fas fa-arrow-left me-1"></i> Kembali
            </a>
        </div>
    </div>
</div>

<div class="card border-0 shadow-sm rounded-4">
    <div class="card-body p-0">
        @if ($pegawai->isNotEmpty())
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="border-0 px-4 py-3" style="width: 5%">No</th>
                            <th class="border-0 px-4 py-3" style="width: 25%">Informasi Pegawai</th>
                            <th class="border-0 px-4 py-3" style="width: 25%">Jabatan & Unit Kerja</th>
                            <th class="border-0 px-4 py-3" style="width: 15%">Usia Pensiun</th>
                            <th class="border-0 px-4 py-3" style="width: 15%">Tanggal Pensiun</th>
                            <th class="border-0 px-4 py-3" style="width: 15%">Sisa Waktu</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($pegawai as $index => $item)
                            <tr>
                                <td class="px-4 py-3">{{ $pegawai->firstItem() + $index }}</td>
                                <td class="px-4 py-3">
                                    <div class="fw-bold text-dark">{{ $item->nama_lengkap }}</div>
                                    <div class="text-muted small">NIP. {{ $item->nip }}</div>
                                </td>
                                <td class="px-4 py-3">
                                    <div class="fw-medium">{{ $item->jabatan?->nama_jabatan ?? '-' }}</div>
                                    <div class="text-muted small">{{ $item->unit_kerja }}</div>
                                </td>
                                <td class="px-4 py-3">
                                    <span class="badge bg-secondary">
                                        {{ $item->retirement_info['usia_pensiun'] ?? '-' }} Tahun
                                    </span>
                                </td>
                                <td class="px-4 py-3">
                                    <div class="fw-bold text-danger">
                                        {{ isset($item->retirement_info['tanggal_pensiun']) ? $item->retirement_info['tanggal_pensiun']->translatedFormat('d F Y') : '-' }}
                                    </div>
                                </td>
                                <td class="px-4 py-3">
                                    @if(isset($item->retirement_info['tanggal_pensiun']))
                                        @php
                                            $diff = now()->diff($item->retirement_info['tanggal_pensiun']);
                                            $years = $diff->y;
                                            $months = $diff->m;
                                        @endphp
                                        @if(now()->greaterThanOrEqualTo($item->retirement_info['tanggal_pensiun']))
                                            <span class="text-danger fw-bold"><i class="fas fa-exclamation-triangle me-1"></i>Sudah Pensiun</span>
                                        @elseif($years == 0 && $months == 0)
                                            <span class="text-danger fw-bold"><i class="fas fa-exclamation-triangle me-1"></i>Bulan ini!</span>
                                        @elseif($years == 0)
                                            <span class="text-warning fw-bold">{{ $months }} Bulan lagi</span>
                                        @else
                                            <span class="text-muted">{{ $years }} Tahun, {{ $months }} Bulan</span>
                                        @endif
                                    @else
                                        -
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            
            @if ($pegawai->hasPages())
                {{ $pegawai->links() }}
            @endif
        @else
            <div class="p-5 text-center text-muted">
                <i class="fas fa-box-open mb-3 fs-2"></i>
                <p class="mb-0">Tidak ada data pegawai yang diproyeksikan pensiun.</p>
            </div>
        @endif
    </div>
</div>
@endsection
