<?php $__env->startSection('title', 'Dashboard Pegawai'); ?>

<?php $__env->startSection('style'); ?>
<style>
    body {
        background: #f4f6f9;
    }

    .container-main {
        display: block;
        padding: 1.5rem 0 2.5rem;
    }

    .employee-dashboard {
        max-width: 1180px;
        margin: 0 auto;
    }

    .welcome-panel {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1.5rem;
        padding: 1.5rem;
        margin-bottom: 1rem;
        color: #4a3728;
        background: linear-gradient(135deg, #e6ddc5 0%, #f6e5b3 100%);
        border: 1px solid rgba(212,160,23,0.3);
        border-radius: 8px;
    }

    .welcome-panel h1 {
        margin: 0 0 0.35rem;
        font-size: 1.5rem;
        font-weight: 750;
    }

    .welcome-panel p {
        margin: 0;
        color: #7a5c1e;
    }

    .verified-badge {
        display: inline-flex;
        align-items: center;
        gap: 0.45rem;
        padding: 0.5rem 0.75rem;
        color: #4a6348;
        background: #dce5da;
        border-radius: 6px;
        font-size: 0.85rem;
        font-weight: 700;
        white-space: nowrap;
    }

    .dashboard-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.65rem;
        padding: 1rem;
        margin-bottom: 1rem;
        background: #f4f1e9;
        border: 1px solid rgba(0,0,0,0.05);
        border-radius: 8px;
    }

    .dashboard-actions .btn {
        display: inline-flex;
        align-items: center;
        gap: 0.45rem;
    }

    .dashboard-panel {
        height: 100%;
        margin: 0;
        background: #f4f1e9;
        border: 1px solid rgba(0,0,0,0.05);
        border-radius: 8px;
        box-shadow: none;
        overflow: hidden;
    }

    .dashboard-panel .panel-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: 1rem 1.15rem;
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }

    .dashboard-panel .panel-header h2 {
        margin: 0;
        color: #4a3728;
        font-size: 1rem;
        font-weight: 750;
    }

    .dashboard-panel .panel-header i {
        margin-right: 0.45rem;
        color: #d4a017;
    }

    .dashboard-panel .panel-body {
        padding: 1.15rem;
    }

    .profile-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem 1.5rem;
    }

    .profile-item {
        min-width: 0;
    }

    .profile-label {
        display: block;
        margin-bottom: 0.2rem;
        color: #6c757d;
        font-size: 0.78rem;
        font-weight: 650;
        text-transform: uppercase;
    }

    .profile-value {
        color: #4a3728;
        font-weight: 650;
        overflow-wrap: anywhere;
    }

    .retirement-grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .retirement-item {
        padding: 0.9rem;
        background: #e8e4d9;
        border: 1px solid rgba(0,0,0,0.05);
        border-radius: 6px;
    }

    .retirement-item strong {
        display: block;
        margin-top: 0.2rem;
        color: #4a3728;
        font-size: 1.05rem;
    }

    .warning-note {
        margin-top: 0.85rem;
        padding: 0.75rem;
        color: #8c6a28;
        background: #f2e7c9;
        border-left: 3px solid #d6a658;
        border-radius: 4px;
        font-size: 0.85rem;
    }

    .dashboard-table {
        margin: 0;
    }

    .dashboard-table thead th {
        padding: 0.75rem;
        color: #6c757d;
        background: #e8e4d9;
        border-bottom: 1px solid rgba(0,0,0,0.05);
        font-size: 0.75rem;
        text-transform: uppercase;
        white-space: nowrap;
    }

    .dashboard-table tbody td {
        padding: 0.85rem 0.75rem;
        color: #4a3728;
        border-color: rgba(0,0,0,0.05);
        vertical-align: top;
    }

    .score-value {
        color: #d4a017;
        font-size: 1.05rem;
        font-weight: 750;
    }

    .detail-list {
        display: grid;
        gap: 0.25rem;
        min-width: 220px;
        font-size: 0.82rem;
    }

    .detail-list span {
        color: #6c757d;
    }

    .career-note {
        margin-top: 0.4rem;
        padding: 0.5rem;
        background: #e8e4d9;
        border-radius: 4px;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .status-badge {
        display: inline-flex;
        padding: 0.35rem 0.55rem;
        border-radius: 5px;
        font-size: 0.75rem;
        font-weight: 700;
        white-space: nowrap;
    }

    .status-badge.success { color: #4a6348; background: #dce5da; }
    .status-badge.primary { color: #8c6a28; background: #f2e7c9; }
    .status-badge.neutral { color: #8b8378; background: #e8e4d9; }

    .document-link {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.8rem 0;
        color: #d4a017;
        text-decoration: none;
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }

    .document-link:last-child {
        border-bottom: 0;
    }

    .document-icon {
        width: 36px;
        height: 36px;
        flex: 0 0 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: #b42318;
        background: #f2d5d3;
        border-radius: 6px;
    }

    .empty-state {
        padding: 2rem 1rem;
        color: #6c757d;
        text-align: center;
    }

    @media (max-width: 767.98px) {
        .welcome-panel {
            align-items: flex-start;
            flex-direction: column;
        }

        .profile-grid,
        .retirement-grid {
            grid-template-columns: 1fr;
        }

        .dashboard-actions .btn {
            width: 100%;
            justify-content: center;
        }
    }
</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<?php
    $riwayatSelesai = $pegawai->jabatanHistories
        ->where('status', 'selesai')
        ->sortBy('tanggal_mulai_jabatan')
        ->values();
    $riwayatAktif = $pegawai->jabatanHistories
        ->where('status', 'aktif')
        ->sortByDesc('created_at')
        ->first();
?>

<main class="employee-dashboard">
    <section class="welcome-panel">
        <div>
            <h1>Selamat datang, <?php echo e($pegawai->nama_lengkap); ?></h1>
            <p><?php echo e($pegawai->unit_kerja); ?> | NIP <?php echo e($pegawai->nip); ?></p>
        </div>
        <span class="verified-badge">
            <i class="fas fa-circle-check"></i> Data Tervalidasi
        </span>
    </section>

    <nav class="dashboard-actions" aria-label="Menu pegawai">
        <a href="<?php echo e(route('pegawai.assessment.form')); ?>" class="btn btn-primary">
            <i class="fas fa-clipboard-list"></i> Penilaian Mandiri
        </a>
        <a href="<?php echo e(route('pegawai.assessment.hasil')); ?>" class="btn btn-outline-primary">
            <i class="fas fa-chart-pie"></i> Hasil Assessment
        </a>
        <a href="<?php echo e(route('pegawai.assessment.rekomendasi')); ?>" class="btn btn-outline-success">
            <i class="fas fa-graduation-cap"></i> Rekomendasi Pelatihan
        </a>
        <form action="<?php echo e(route('logout')); ?>" method="POST" class="ms-auto">
            <?php echo csrf_field(); ?>
            <button type="submit" class="btn btn-outline-danger">
                <i class="fas fa-sign-out-alt"></i> Logout
            </button>
        </form>
    </nav>

    <section class="row g-3 mb-3">
        <div class="col-lg-7">
            <article class="dashboard-panel">
                <header class="panel-header">
                    <h2><i class="fas fa-id-card"></i>Profil Pegawai</h2>
                </header>
                <div class="panel-body">
                    <div class="profile-grid">
                        <div class="profile-item">
                            <span class="profile-label">Nama Lengkap</span>
                            <div class="profile-value"><?php echo e($pegawai->nama_lengkap); ?></div>
                        </div>
                        <div class="profile-item">
                            <span class="profile-label">NIP</span>
                            <div class="profile-value"><?php echo e($pegawai->nip); ?></div>
                        </div>
                        <div class="profile-item">
                            <span class="profile-label">Email</span>
                            <div class="profile-value"><?php echo e($pegawai->email); ?></div>
                        </div>
                        <div class="profile-item">
                            <span class="profile-label">Unit Kerja</span>
                            <div class="profile-value"><?php echo e($pegawai->unit_kerja); ?></div>
                        </div>
                        <div class="profile-item">
                            <span class="profile-label">Jabatan Fungsional</span>
                            <div class="profile-value"><?php echo e($pegawai->jabatan?->nama_jabatan ?? '-'); ?></div>
                        </div>
                        <div class="profile-item">
                            <span class="profile-label">Jenjang</span>
                            <div class="profile-value"><?php echo e($pegawai->jabatan?->jenjang_label ?? '-'); ?></div>
                        </div>
                        <div class="profile-item">
                            <span class="profile-label">Golongan</span>
                            <div class="profile-value"><?php echo e($pegawai->golongan ?? '-'); ?></div>
                        </div>
                        <div class="profile-item">
                            <span class="profile-label">TMT Jabatan</span>
                            <div class="profile-value"><?php echo e($pegawai->tanggal_mulai_jabatan?->format('d-m-Y') ?? '-'); ?></div>
                        </div>
                    </div>
                </div>
            </article>
        </div>

        <div class="col-lg-5">
            <article class="dashboard-panel">
                <header class="panel-header">
                    <h2><i class="fas fa-user-clock"></i>Informasi Pensiun</h2>
                </header>
                <div class="panel-body">
                    <?php if($pegawai->retirement_info): ?>
                        <div class="retirement-grid">
                            <div class="retirement-item">
                                <span class="profile-label">Batas Usia</span>
                                <strong><?php echo e($pegawai->retirement_info['usia_pensiun']); ?> tahun</strong>
                            </div>
                            <div class="retirement-item">
                                <span class="profile-label">Tahun Pensiun</span>
                                <strong><?php echo e($pegawai->retirement_info['tahun_pensiun']); ?></strong>
                            </div>
                            <div class="retirement-item">
                                <span class="profile-label">Perkiraan Tanggal</span>
                                <strong><?php echo e($pegawai->retirement_info['tanggal_pensiun']->format('d-m-Y')); ?></strong>
                            </div>
                        </div>
                        <?php if($pegawai->retirement_info['peringatan_golongan']): ?>
                            <div class="warning-note">
                                <i class="fas fa-triangle-exclamation me-1"></i>
                                <?php echo e($pegawai->retirement_info['peringatan_golongan']); ?>

                            </div>
                        <?php endif; ?>
                    <?php else: ?>
                        <div class="empty-state">Informasi pensiun belum tersedia.</div>
                    <?php endif; ?>
                </div>
            </article>
        </div>
    </section>

    <section class="dashboard-panel mb-3">
        <header class="panel-header">
            <h2><i class="fas fa-chart-pie"></i>Hasil Penilaian Mandiri Kompetensi</h2>
            <a href="<?php echo e(route('pegawai.assessment.hasil')); ?>" class="btn btn-sm btn-outline-primary"></a>
        </header>
        <div class="panel-body p-0">
            <?php if($assessmentResults->isNotEmpty()): ?>
                <div class="table-responsive">
                    <table class="table dashboard-table align-middle">
                        <thead>
                            <tr>
                                <th>Tahun</th>
                                <th>Pemenuhan</th>
                                <th>Kategori</th>
                                <th>Status</th>
                                <th>Karier</th>
                                <th>Kompetensi</th>
                                <th>Rencana Pengembangan Karier</th>
                                <th>Dasar Pengembangan Kompetensi</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__currentLoopData = $assessmentResults; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $hasilAssessment = $item['hasil'];
                                    $pengembangan = $item['pengembangan'];
                                    $statusAssessment = match ($hasilAssessment['status']) {
                                        'draft' => 'Draft',
                                        'submitted' => 'Dikirim',
                                        'verified' => 'Diverifikasi',
                                        default => 'Belum Diisi',
                                    };
                                    $statusClass = match ($hasilAssessment['status']) {
                                        'verified' => 'success',
                                        'submitted' => 'primary',
                                        default => 'neutral',
                                    };
                                ?>
                                <tr>
                                    <td><strong><?php echo e($item['tahun']); ?></strong></td>
                                    <td>
                                        <div class="score-value"><?php echo e($hasilAssessment['persentase']); ?>%</div>
                                        <small class="text-muted"><?php echo e($hasilAssessment['ya']); ?>/<?php echo e($hasilAssessment['total']); ?> indikator</small>
                                    </td>
                                    <td><?php echo e($hasilAssessment['kategori']); ?></td>
                                    <td><span class="status-badge <?php echo e($statusClass); ?>"><?php echo e($statusAssessment); ?></span></td>
                                    <td>
                                        <span class="status-badge <?php echo e($pengembangan?->dikembangkan_karier ? 'success' : 'neutral'); ?>">
                                            <?php echo e($pengembangan?->dikembangkan_karier ? 'Ya' : 'Tidak'); ?>

                                        </span>
                                    </td>
                                    <td>
                                        <span class="status-badge <?php echo e($pengembangan?->dikembangkan_kompetensi ? 'success' : 'neutral'); ?>">
                                            <?php echo e($pengembangan?->dikembangkan_kompetensi ? 'Ya' : 'Tidak'); ?>

                                        </span>
                                    </td>
                                    <td>
                                        <?php if($pengembangan?->dikembangkan_karier): ?>
                                            <div class="detail-list">
                                                <div><span>Bentuk:</span> <?php echo e($pengembangan->bentuk_pengembangan_karier_label); ?></div>
                                                <div><span>Waktu:</span> <?php echo e($pengembangan->waktu_pelaksanaan_tahun ?? '-'); ?> tahun</div>
                                                <div><span>Prosedur:</span> <?php echo e($pengembangan->prosedur_pengisian_jabatan_label); ?></div>
                                                <div><span>Mekanisme:</span> <?php echo e($pengembangan->mekanisme_pengisian_jabatan_label); ?></div>
                                                <?php if($pengembangan->catatan_pengembangan_karier): ?>
                                                    <div class="career-note">
                                                        <span>Catatan:</span><br>
                                                        <?php echo e($pengembangan->catatan_pengembangan_karier); ?>

                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        <?php else: ?>
                                            <span class="text-muted">Belum ada rencana</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if($pengembangan?->dikembangkan_kompetensi): ?>
                                            <div class="detail-list">
                                                <div><span>Penilaian Kompetensi:</span><br><?php echo e($pengembangan->hasil_penilaian_kompetensi ?: '-'); ?></div>
                                                <div><span>Sejarah Karier:</span><br><?php echo e($pengembangan->sejarah_karier ?: '-'); ?></div>
                                                <div><span>Penilaian Kinerja:</span><br><?php echo e($pengembangan->hasil_penilaian_kinerja ?: '-'); ?></div>
                                                <?php if($pengembangan->perencanaan_suksesi_detail): ?>
                                                    <div>
                                                        <span>Perencanaan Suksesi:</span><br>
                                                        <strong>
                                                            <?php echo e($pengembangan->perencanaan_suksesi); ?> -
                                                            <?php echo e($pengembangan->perencanaan_suksesi_detail['kategori']); ?>

                                                        </strong>
                                                    </div>
                                                    <div>
                                                        <span>Kondisi:</span><br>
                                                        <?php echo e($pengembangan->perencanaan_suksesi_detail['kondisi']); ?>

                                                    </div>
                                                    <div>
                                                        <span>Kegiatan Pembinaan:</span><br>
                                                        <?php echo e($pengembangan->perencanaan_suksesi_detail['kegiatan']); ?>

                                                    </div>
                                                <?php else: ?>
                                                    <div><span>Perencanaan Suksesi:</span><br>-</div>
                                                <?php endif; ?>
                                            </div>
                                        <?php else: ?>
                                            <span class="text-muted">Belum ada rencana</span>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            <?php else: ?>
                <div class="empty-state">Belum ada hasil Penilaian Mandiri Kompetensi.</div>
            <?php endif; ?>
        </div>
    </section>

    <section class="dashboard-panel mb-3">
        <header class="panel-header">
            <h2><i class="fas fa-history"></i>Riwayat Jabatan</h2>
        </header>
        <div class="panel-body p-0">
            <?php if($pegawai->jabatanHistories->isNotEmpty() || $pegawai->jabatan): ?>
                <div class="table-responsive">
                    <table class="table dashboard-table align-middle">
                        <thead>
                            <tr>
                                <th>Jabatan</th>
                                <th>Jenjang</th>
                                <th>TMT</th>
                                <th>Selesai</th>
                                <th>Nomor SK</th>
                                <th>Status</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__currentLoopData = $riwayatSelesai; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $history): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $jabatanRiwayat = $history->jabatan_sebelumnya ?? $history->jabatan?->nama_jabatan ?? $history->nama_jabatan ?? '-';
                                    $jenjangRiwayat = $history->jenjang_sebelumnya ?? $history->jabatan?->jenjang_label ?? $history->jenjang ?? '-';
                                    $jenjangSuffix = ' - ' . $jenjangRiwayat;
                                    $riwayatBerikutnya = $riwayatSelesai->get($loop->index + 1);
                                    $tahunSelesai = $riwayatBerikutnya?->tanggal_mulai_jabatan?->format('Y')
                                        ?? $pegawai->tanggal_mulai_jabatan?->format('Y')
                                        ?? '-';

                                    if ($jenjangRiwayat !== '-' && str_ends_with($jabatanRiwayat, $jenjangSuffix)) {
                                        $jabatanRiwayat = substr($jabatanRiwayat, 0, -strlen($jenjangSuffix));
                                    }
                                ?>
                                <tr>
                                    <td><strong><?php echo e($jabatanRiwayat); ?></strong></td>
                                    <td><?php echo e($jenjangRiwayat); ?></td>
                                    <td><?php echo e($history->tanggal_mulai_jabatan?->format('Y') ?? '-'); ?></td>
                                    <td><?php echo e($tahunSelesai); ?></td>
                                    <td><?php echo e($history->nomor_sk ?? '-'); ?></td>
                                    <td><span class="status-badge neutral">Selesai</span></td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php if($pegawai->jabatan): ?>
                                <tr>
                                    <td><strong><?php echo e($pegawai->jabatan->nama_jabatan); ?></strong></td>
                                    <td><?php echo e($pegawai->jabatan->jenjang_label); ?></td>
                                    <td><?php echo e($pegawai->tanggal_mulai_jabatan?->format('Y') ?? '-'); ?></td>
                                    <td>-</td>
                                    <td><?php echo e($riwayatAktif?->nomor_sk ?? '-'); ?></td>
                                    <td><span class="status-badge success">Aktif</span></td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            <?php else: ?>
                <div class="empty-state">Riwayat jabatan belum tersedia.</div>
            <?php endif; ?>
        </div>
    </section>

    <section class="dashboard-panel">
        <header class="panel-header">
            <h2><i class="fas fa-folder-open"></i>Dokumen Pendukung</h2>
            <span class="text-muted small"><?php echo e($pegawai->files->count()); ?> dokumen</span>
        </header>
        <div class="panel-body">
            <?php $__empty_1 = true; $__currentLoopData = $pegawai->files; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $file): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <a href="<?php echo e(URL::temporarySignedRoute('pegawai.files.show', now()->addHours(2), ['file' => $file->id])); ?>"
                    class="document-link" target="_blank">
                    <span class="document-icon"><i class="fas fa-file"></i></span>
                    <span>
                        <strong><?php echo e($file->nama_file); ?></strong><br>
                        <small class="text-muted">Buka dokumen</small>
                    </span>
                    <i class="fas fa-arrow-up-right-from-square ms-auto"></i>
                </a>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div class="empty-state">Belum ada dokumen pendukung.</div>
            <?php endif; ?>
        </div>
    </section>
</main>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\Skripsi-M\resources\views/pegawai/dashboard.blade.php ENDPATH**/ ?>