@extends('layouts.admin')

@section('title', 'Dashboard Admin')
@section('page_title', 'Dashboard BKPSDM')

@php
    $totalStatus = max($totalPegawai + $pegawaiPending, 1);
    $assessmentCoverage = $totalPegawai > 0 ? round(($sudahAssessment / $totalPegawai) * 100, 1) : 0;
    $pendingRate = round(($pegawaiPending / $totalStatus) * 100, 1);
    $developmentRate = $sudahAssessment > 0 ? round(($perluPengembanganAssessment / $sudahAssessment) * 100, 1) : 0;
    $distributionTotal = max(array_sum($assessmentDistribution), 1);
    $pengembanganTotal = max(array_sum($statusPengembanganKompetensi), 1);
@endphp

@section('style')
    <style>
        .exec-date {
            display: inline-flex;
            align-items: center;
            gap: 0.45rem;
            padding: 0.45rem 0.7rem;
            color: #6c757d;
            background: #e8e4d9;
            border: 1px solid rgba(0, 0, 0, 0.05);
            border-radius: 6px;
            font-size: 0.86rem;
            white-space: nowrap;
        }

        .dashboard-grid {
            display: grid;
            grid-template-columns: repeat(12, 1fr);
            gap: 20px;
            grid-auto-flow: dense;
            align-items: stretch;
            margin-bottom: 2rem;
        }

        .span-12 {
            grid-column: span 12;
        }

        .span-8 {
            grid-column: span 8;
        }

        .span-7 {
            grid-column: span 7;
        }

        .span-6 {
            grid-column: span 6;
        }

        .span-5 {
            grid-column: span 5;
        }

        .span-4 {
            grid-column: span 4;
        }

        .span-3 {
            grid-column: span 3;
        }

        .row-span-2 {
            grid-row: span 2;
        }

        .row-span-3 {
            grid-row: span 3;
        }

        @media (max-width: 1199.98px) {

            .span-12,
            .span-8,
            .span-7,
            .span-6,
            .span-5,
            .span-4,
            .span-3 {
                grid-column: span 12;
            }

            .row-span-2,
            .row-span-3 {
                grid-row: auto;
            }
        }

        .kpi-card,
        .exec-panel {
            height: 100%;
            background: #f4f1e9;
            border: 1px solid rgba(0, 0, 0, 0.05);
            border-radius: 8px;
            box-shadow: none;
            transition: border-color 0.15s ease, box-shadow 0.15s ease;
            margin: 0;
        }

        .kpi-card:hover,
        .exec-panel:hover {
            border-color: rgba(212, 160, 23, 0.2);
            box-shadow: 0 8px 22px rgba(31, 45, 61, 0.04);
        }

        .kpi-card {
            display: flex;
            gap: 1rem;
            padding: 1.25rem;
            min-height: 120px;
            max-height: 140px;
            align-items: center;
        }

        .kpi-icon {
            width: 48px;
            height: 48px;
            flex: 0 0 48px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            font-size: 1.2rem;
        }

        .tone-gold {
            color: #7a5c1e;
            background: #e6ddc5;
        }

        .tone-amber {
            color: #8c6a28;
            background: #f2e7c9;
        }

        .tone-green {
            color: #4a6348;
            background: #dce5da;
        }

        .tone-red {
            color: #8a4843;
            background: #f2d5d3;
        }

        .tone-gray {
            color: #8b8378;
            background: #e8e4d9;
        }

        .kpi-label {
            color: #6c757d;
            font-size: 0.85rem;
            font-weight: 650;
        }

        .kpi-number {
            margin-top: 0.35rem;
            color: #4a3728;
            font-size: 1.72rem;
            line-height: 1;
            font-weight: 750;
        }

        .kpi-meta {
            margin-top: 0.5rem;
            color: #6c757d;
            font-size: 0.8rem;
        }

        .kpi-link {
            display: inline-flex;
            align-items: center;
            gap: 0.35rem;
            margin-top: 0.55rem;
            color: var(--primary);
            /* Changed from #d4a017 to dark brown for readability */
            font-size: 0.82rem;
            font-weight: 650;
            text-decoration: none;
            transition: color 0.2s;
        }

        .kpi-link:hover {
            color: #d4a017;
        }

        .exec-panel {
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }

        .exec-panel .card-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            gap: 1rem;
            padding: 1.25rem 1.5rem;
            background: #ffffff;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        }

        .exec-panel h5 {
            margin: 0;
            color: #4a3728;
            font-size: 1rem;
            font-weight: 750;
        }

        .panel-subtitle {
            margin-top: 0.2rem;
            color: #64748b;
            font-size: 0.8rem;
        }

        .exec-panel .card-body {
            padding: 1.5rem;
            flex-grow: 1;
        }

        .chart-frame {
            position: relative;
            height: 320px;
        }

        .chart-frame-sm {
            height: 320px;
            /* Force consistent heights as per request */
        }

        .compact-table {
            margin: 0;
        }

        .compact-table thead th {
            padding: 0.7rem 0.8rem;
            color: #7a6c5d;
            background: #ffffff;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
            font-size: 0.72rem;
            text-transform: uppercase;
            white-space: nowrap;
        }

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

        .text-truncate-2 {
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .compact-table tbody tr:last-child td {
            border-bottom-width: 0;
        }

        .person-name {
            color: #4a3728;
            font-weight: 700;
        }

        .person-meta {
            color: #6c757d;
            font-size: 0.78rem;
        }

        .score-pill {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-width: 58px;
            padding: 0.32rem 0.55rem;
            border-radius: 6px;
            font-size: 0.75rem;
            font-weight: 750;
        }

        .empty-state {
            min-height: 185px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            color: #64748b;
            text-align: center;
        }

        .empty-state i {
            margin-bottom: 0.65rem;
            color: #adb5bd;
            font-size: 1.45rem;
        }

        .legend-list {
            display: grid;
            gap: 0.55rem;
            margin-top: 0.9rem;
        }

        .legend-row {
            display: flex;
            justify-content: space-between;
            gap: 0.8rem;
            color: #6c757d;
            font-size: 0.84rem;
        }

        .legend-dot {
            width: 10px;
            height: 10px;
            display: inline-block;
            margin-right: 0.45rem;
            border-radius: 50%;
        }

        .priority-list {
            display: grid;
            gap: 0.75rem;
        }

        .priority-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 0.8rem;
            padding: 0.72rem 0.8rem;
            background: #e8e4d9;
            border: 1px solid rgba(0, 0, 0, 0.05);
            border-radius: 8px;
        }

        .priority-rank {
            width: 28px;
            height: 28px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: 7px;
            color: #7a5c1e;
            background: #e6ddc5;
            font-size: 0.78rem;
            font-weight: 800;
        }

        .heatmap-table th,
        .heatmap-table td {
            text-align: center;
        }

        .heatmap-table th:first-child,
        .heatmap-table td:first-child {
            text-align: left;
        }

        .heat-cell {
            min-width: 90px;
            font-weight: 800;
            border-radius: 6px;
        }

        @media (max-width: 767.98px) {
            .exec-date {
                white-space: normal;
            }

            .chart-frame {
                height: 245px;
            }
        }
    </style>
@endsection

@section('content')
    <section class="page-hero">
        <div>
            <h3>Dashboard Eksekutif BKPSDM</h3>
            <p>{{ $dashboardScope }} &middot; Tahun assessment {{ $assessmentYear }}</p>
        </div>
        <div class="exec-date">
            <i class="fas fa-calendar-day"></i> {{ now()->locale('id')->translatedFormat('l, d F Y') }}
        </div>
    </section>

    <div class="dashboard-grid">
        <div class="span-3">
            <div class="kpi-card">
                <div class="kpi-icon tone-gold"><i class="fas fa-users"></i></div>
                <div>
                    <div class="kpi-label">Total Pegawai Aktif</div>
                    <div class="kpi-number">{{ number_format($totalPegawai) }}</div>
                    <div class="kpi-meta">Basis pemetaan jabatan dan kompetensi ASN.</div>
                    <a class="kpi-link" href="{{ route('admin.pegawai.index') }}">Lihat data <i
                            class="fas fa-arrow-right"></i></a>
                </div>
            </div>
        </div>
        <div class="span-3">
            <div class="kpi-card">
                <div class="kpi-icon tone-amber"><i class="fas fa-inbox"></i></div>
                <div>
                    <div class="kpi-label">Menunggu Validasi</div>
                    <div class="kpi-number">{{ number_format($pegawaiPending) }}</div>
                    <div class="kpi-meta">{{ $pendingRate }}% dari data aktif dan antrean.</div>
                    <a class="kpi-link" href="{{ route('admin.pegawai.submissions') }}">Tinjau pendataan <i
                            class="fas fa-arrow-right"></i></a>
                </div>
            </div>
        </div>
        <div class="span-3">
            <div class="kpi-card">
                <div class="kpi-icon tone-green"><i class="fas fa-clipboard-check"></i></div>
                <div>
                    <div class="kpi-label">Sudah Assessment</div>
                    <div class="kpi-number">{{ number_format($sudahAssessment) }}</div>
                    <div class="kpi-meta">{{ $assessmentCoverage }}% dari pegawai aktif.</div>
                    <a class="kpi-link"
                        href="{{ route('admin.assessment-kompetensi.index', ['tahun' => $assessmentYear]) }}">Lihat
                        assessment <i class="fas fa-arrow-right"></i></a>
                </div>
            </div>
        </div>
        <div class="span-3">
            <div class="kpi-card">
                <div class="kpi-icon tone-red"><i class="fas fa-seedling"></i></div>
                <div>
                    <div class="kpi-label">Perlu Pelatihan</div>
                    <div class="kpi-number">{{ number_format($perluPengembanganAssessment) }}</div>
                    <div class="kpi-meta">{{ $developmentRate }}% dari pegawai yang sudah assessment.</div>
                    <a class="kpi-link"
                        href="{{ route('admin.assessment-kompetensi.recap', ['tahun' => $assessmentYear]) }}">Lihat
                        kebutuhan <i class="fas fa-arrow-right"></i></a>
                </div>
            </div>
        </div>

        <!-- Level 2: Operasional Kritis -->
        <div class="span-6 row-span-2">
            <div class="card exec-panel h-100">
                <div class="card-header">
                    <div>
                        <h5><i class="fas fa-clipboard-check me-2 text-warning"></i>Antrian Validasi Pendataan</h5>
                        <div class="panel-subtitle">Data masuk yang perlu ditindaklanjuti admin.</div>
                    </div>
                    <a href="{{ route('admin.pegawai.submissions') }}" class="btn btn-sm btn-outline-primary">Lihat
                        semua</a>
                </div>
                <div class="card-body p-0">
                    @if ($pendingForApproval->isNotEmpty())
                        <div class="table-responsive">
                            <table class="table compact-table align-middle">
                                <thead>
                                    <tr>
                                        <th>Nama</th>
                                        <th>Jabatan</th>
                                        <th>Tanggal Pengajuan</th>
                                        <th class="text-end">Aksi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($pendingForApproval as $pegawai)
                                        <tr>
                                            <td>
                                                <div class="person-name text-truncate-2" style="max-width: 150px;">{{ $pegawai->nama_lengkap }}</div>
                                                <div class="person-meta">NIP {{ $pegawai->nip }}</div>
                                            </td>
                                            <td>
                                                <div class="text-truncate-2" style="max-width: 160px;" title="{{ $pegawai->jabatan?->nama_jabatan }}">{{ $pegawai->jabatan?->nama_jabatan ?? '-' }}</div>
                                                <div class="person-meta">{{ $pegawai->jabatan?->jenjang_label ?? '-' }}</div>
                                            </td>
                                            <td>
                                                <div>{{ $pegawai->created_at->format('d M Y') }}</div>
                                                <div class="person-meta">{{ $pegawai->created_at->diffForHumans() }}</div>
                                            </td>
                                            <td class="text-end">
                                                <a href="{{ route('admin.pegawai.show', $pegawai) }}" class="btn btn-sm btn-light text-primary border shadow-sm" title="Tinjau">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @else
                        <div class="empty-state"><i class="fas fa-check-circle"></i><span>Tidak ada pendataan yang menunggu
                                validasi.</span></div>
                    @endif
                </div>
            </div>
        </div>
        <div class="span-6 row-span-2">
            <div class="card exec-panel h-100">
                <div class="card-header">
                    <div class="d-flex justify-content-between align-items-center w-100">
                        <div>
                            <h5><i class="fas fa-user-check me-2 text-primary"></i>Pegawai Belum Melakukan Assessment</h5>
                            <div class="panel-subtitle">Prioritas pengingat assessment.</div>
                        </div>
                        <a href="{{ route('admin.dashboard.belum-assessment') }}" class="btn btn-sm btn-outline-primary">Lihat Semua</a>
                    </div>
                </div>
                <div class="card-body p-0">
                    @if ($pegawaiBelumAssessment->isNotEmpty())
                        <div class="table-responsive">
                            <table class="table compact-table align-middle">
                                <thead>
                                    <tr>
                                        <th>Nama</th>
                                        <th>Jabatan</th>
                                        <th>Unit Kerja</th>
                                        <th class="text-end">Aksi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($pegawaiBelumAssessment as $pegawai)
                                        <tr>
                                            <td>
                                                <div class="person-name text-truncate-2" style="max-width: 150px;">{{ $pegawai->nama_lengkap }}</div>
                                                <div class="person-meta">NIP {{ $pegawai->nip }}</div>
                                            </td>
                                            <td>
                                                <div class="text-truncate-2" style="max-width: 160px;" title="{{ $pegawai->jabatan?->nama_jabatan }}">{{ $pegawai->jabatan?->nama_jabatan ?? '-' }}</div>
                                                <div class="person-meta">{{ $pegawai->jabatan?->jenjang_label ?? '-' }}</div>
                                            </td>
                                            <td>
                                                <div class="person-meta text-truncate-2" style="max-width: 160px;" title="{{ $pegawai->unit_kerja }}">{{ $pegawai->unit_kerja }}</div>
                                            </td>
                                            <td class="text-end">
                                                <a href="{{ route('admin.pegawai.show', $pegawai) }}" class="btn btn-sm btn-light text-primary border shadow-sm" title="Detail">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @else
                        <div class="empty-state"><i class="fas fa-check-circle"></i><span>Semua pegawai aktif sudah melakukan
                                assessment.</span></div>
                    @endif
                </div>
            </div>
        </div>

        <!-- Level 3: HR Planning -->

        <div class="span-6 row-span-2">
            <div class="card exec-panel h-100">
                <div class="card-header">
                    <div class="d-flex justify-content-between align-items-center w-100">
                        <div>
                            <h5><i class="fas fa-user-clock me-2 text-warning"></i>Proyeksi Pensiun 5 Tahun</h5>
                            <div class="panel-subtitle">Mendukung perencanaan kebutuhan pegawai.</div>
                        </div>
                        <a href="{{ route('admin.dashboard.pensiun') }}" class="btn btn-sm btn-outline-primary">Lihat Semua</a>
                    </div>
                </div>
                <div class="card-body">
                    @if ($retirementSoonTotal > 0)
                        <div class="chart-frame"><canvas id="retirementChart"></canvas></div>
                    @else
                        <div class="empty-state"><i class="fas fa-user-clock"></i><span>Belum ada pegawai yang mendekati
                                pensiun.</span></div>
                    @endif
                </div>
            </div>
        </div>

        <div class="span-6 row-span-2">
            <div class="card exec-panel h-100">
                <div class="card-header">
                    <div>
                        <h5><i class="fas fa-chart-line me-2 text-danger"></i>Jabatan dengan Tingkat Kompetensi Terendah
                        </h5>
                        <div class="panel-subtitle">Top 5, urut dari terendah.</div>
                    </div>
                </div>
                <div class="card-body p-0">
                    @if ($jabatanAssessmentTerendah->isNotEmpty())
                        <div class="table-responsive">
                            <table class="table compact-table align-middle">
                                <thead>
                                    <tr>
                                        <th>Jabatan</th>
                                        <th class="text-end">Persentase Kompetensi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($jabatanAssessmentTerendah as $jabatan)
                                        <tr>
                                            <td>
                                                <div class="person-name">{{ $jabatan->nama_jabatan }}</div>
                                                <div class="person-meta">{{ $jabatan->nama_jenjang ?? '-' }} &middot;
                                                    {{ $jabatan->jumlah_pegawai }} pegawai</div>
                                            </td>
                                            <td class="text-end">
                                                <span
                                                    class="score-pill {{ $jabatan->rata_rata >= 75 ? 'tone-green' : ($jabatan->rata_rata >= 50 ? 'tone-amber' : 'tone-red') }}">{{ $jabatan->rata_rata }}%</span>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @else
                        <div class="empty-state"><i class="fas fa-chart-line"></i><span>Belum ada data assessment per
                                jabatan.</span></div>
                    @endif
                </div>
            </div>
        </div>

        <!-- Level 4: Kompetensi -->
        <div class="span-6 row-span-2">
            <div class="card exec-panel h-100">
                <div class="card-header">
                    <div>
                        <h5><i class="fas fa-chart-pie me-2 text-success"></i>Distribusi Hasil Kompetensi</h5>
                        <div class="panel-subtitle">Kondisi kompetensi ASN berdasarkan hasil penilaian mandiri.</div>
                    </div>
                </div>
                <div class="card-body">
                    @if (array_sum($assessmentDistribution) > 0)
                        <div class="chart-frame chart-frame-sm"><canvas id="assessmentDistributionChart"></canvas></div>
                        <div class="legend-list">
                            @foreach ($assessmentDistribution as $label => $total)
                                @php
                                    $color = $label === 'Kompeten' ? '#8ba888' : ($label === 'Cukup Kompeten' ? '#d6a658' : '#c97c72');
                                    $percentage = round(($total / $distributionTotal) * 100, 1);
                                @endphp
                                <div class="legend-row">
                                    <span><span class="legend-dot" style="background: {{ $color }}"></span>{{ $label }}</span>
                                    <strong>{{ $total }} pegawai &middot; {{ $percentage }}%</strong>
                                </div>
                            @endforeach
                        </div>
                    @else
                        <div class="empty-state"><i class="fas fa-chart-pie"></i><span>Belum ada hasil assessment pada tahun
                                ini.</span></div>
                    @endif
                </div>
            </div>
        </div>

        <div class="span-6 row-span-2">
            <div class="card exec-panel h-100">
                <div class="card-header">
                    <div>
                        <h5><i class="fas fa-bullseye me-2 text-primary"></i>Prioritas Pengembangan Kompetensi</h5>
                        <div class="panel-subtitle">Fokus pelatihan berdasarkan gap terbanyak.</div>
                    </div>
                </div>
                <div class="card-body d-flex flex-column">
                    @if ($topKompetensiPengembangan->isNotEmpty())
                        <div class="priority-list flex-grow-1 d-flex flex-column justify-content-between"
                            style="display: flex !important;">
                            @foreach ($topKompetensiPengembangan as $kompetensi)
                                <div class="priority-item">
                                    <div class="d-flex align-items-center gap-3">
                                        <span class="priority-rank">{{ $loop->iteration }}</span>
                                        <div>
                                            <div class="person-name">{{ $kompetensi->nama_kompetensi }}</div>
                                            <div class="person-meta">
                                                {{ ucwords(str_replace('_', ' ', $kompetensi->jenis_kompetensi)) }}</div>
                                        </div>
                                    </div>
                                    <span class="score-pill tone-amber">{{ $kompetensi->total_gap }} gap</span>
                                </div>
                            @endforeach
                        </div>
                    @else
                        <div class="empty-state m-auto"><i class="fas fa-bullseye"></i><span>Belum ada prioritas pengembangan
                                kompetensi.</span></div>
                    @endif
                </div>
            </div>
        </div>


        <!-- Level 5: Heatmap -->
        <div class="span-12">
            <div class="card exec-panel">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <div>
                        <h5><i class="fas fa-table-cells-large me-2 text-success"></i>Heatmap Pemetaan Kompetensi</h5>
                        <div class="panel-subtitle">Matriks jabatan fungsional terhadap kategori hasil kompetensi ASN.</div>
                    </div>
                    @if ($heatmapKompetensi->count() > 5)
                        <div class="action-group">
                            <a href="{{ route('admin.dashboard.heatmap-kompetensi') }}" class="btn btn-sm btn-outline-success">
                                Lihat Semua <i class="fas fa-arrow-right ms-1"></i>
                            </a>
                        </div>
                    @endif
                </div>
                <div class="card-body p-0">
                    @if ($heatmapKompetensi->isNotEmpty())
                        <div class="table-responsive">
                            <table class="table compact-table heatmap-table align-middle">
                                <thead>
                                    <tr>
                                        <th>Jabatan Fungsional</th>
                                        <th>Kompeten</th>
                                        <th>Cukup Kompeten</th>
                                        <th>Perlu Pelatihan</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($heatmapKompetensi->take(5) as $row)
                                        <tr>
                                            <td>
                                                <div class="person-name">{{ $row['jabatan'] }}</div>
                                            </td>
                                            <td><span class="score-pill tone-green heat-cell">{{ $row['Kompeten'] }}</span></td>
                                            <td><span class="score-pill tone-amber heat-cell">{{ $row['Cukup Kompeten'] }}</span>
                                            </td>
                                            <td><span class="score-pill tone-red heat-cell">{{ $row['Perlu Pelatihan'] }}</span>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @else
                        <div class="empty-state"><i class="fas fa-table-cells-large"></i><span>Heatmap akan tampil setelah
                                assessment kompetensi tersedia.</span></div>
                    @endif
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    @if ($pegawaiPerJabatan->isNotEmpty() || $retirementSoonTotal > 0 || array_sum($assessmentDistribution) > 0 || $topKompetensiPengembangan->isNotEmpty() || array_sum($statusPengembanganKompetensi) > 0)
        <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
        <script>
            Chart.defaults.font.family = "'Segoe UI', Tahoma, Geneva, Verdana, sans-serif";
            Chart.defaults.color = '#8b8378';

            const gridColor = 'rgba(0,0,0,0.05)';



            @if ($retirementSoonTotal > 0)
                new Chart(document.getElementById('retirementChart'), {
                    type: 'bar',
                    data: {
                        labels: @json($retirementChartLabels),
                        datasets: [{
                            data: @json($retirementChartData),
                            backgroundColor: '#d6a658',
                            borderRadius: 5,
                            maxBarThickness: 34
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: { legend: { display: false } },
                        scales: {
                            y: { beginAtZero: true, ticks: { precision: 0 }, grid: { color: gridColor } },
                            x: { grid: { display: false } }
                        }
                    }
                });
            @endif

            @if (array_sum($assessmentDistribution) > 0)
                new Chart(document.getElementById('assessmentDistributionChart'), {
                    type: 'doughnut',
                    data: {
                        labels: @json(array_keys($assessmentDistribution)),
                        datasets: [{
                            data: @json(array_values($assessmentDistribution)),
                            backgroundColor: ['#8ba888', '#d6a658', '#c97c72'],
                            borderColor: '#f4f1e9',
                            borderWidth: 3
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        cutout: '62%',
                        plugins: {
                            legend: {
                                position: 'bottom',
                                labels: { usePointStyle: true, boxWidth: 8 }
                            }
                        }
                    }
                });
            @endif


        </script>
    @endif
@endsection