<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Statistik PPID</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        .header-section {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            color: white;
            padding: 2rem 0;
        }
        .card {
            border: none;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            border-radius: 15px;
        }
        .chart-container {
            position: relative;
            height: 400px;
        }
    </style>
</head>
<body>
    <!-- Header -->
    <div class="header-section">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <h1 class="mb-2">
                        <i class="fas fa-chart-bar me-3"></i>
                        Statistik PPID
                    </h1>
                    <p class="mb-0 fs-5">Transparansi Layanan Informasi Publik</p>
                </div>
                <div class="col-md-4 text-end">
                    <a href="{{ route('ppid.dashboard') }}" class="btn btn-light">
                        <i class="fas fa-home me-2"></i>Kembali ke Beranda
                    </a>
                </div>
            </div>
        </div>
    </div>

    <div class="container my-5">
        <!-- Grafik Permohonan per Tahun -->
        <div class="card mb-5">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">
                    <i class="fas fa-chart-line me-2"></i>
                    Permohonan Informasi per Tahun
                </h5>
            </div>
            <div class="card-body">
                <div class="chart-container">
                    <canvas id="permohonanChart"></canvas>
                </div>
            </div>
        </div>

        <div class="row">
            <!-- Grafik Status Permohonan -->
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header bg-success text-white">
                        <h5 class="mb-0">
                            <i class="fas fa-pie-chart me-2"></i>
                            Status Permohonan
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="chart-container">
                            <canvas id="statusChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Tabel Status -->
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header bg-info text-white">
                        <h5 class="mb-0">
                            <i class="fas fa-table me-2"></i>
                            Detail Status Permohonan
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Status</th>
                                        <th class="text-center">Jumlah</th>
                                        <th class="text-center">Persentase</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($statusPermohonan as $status)
                                    <tr>
                                        <td>
                                            @if($status['status'] == 'Disetujui')
                                                <i class="fas fa-check-circle text-success me-2"></i>
                                            @elseif($status['status'] == 'Diproses')
                                                <i class="fas fa-clock text-warning me-2"></i>
                                            @elseif($status['status'] == 'Ditolak')
                                                <i class="fas fa-times-circle text-danger me-2"></i>
                                            @else
                                                <i class="fas fa-exclamation-triangle text-warning me-2"></i>
                                            @endif
                                            {{ $status['status'] }}
                                        </td>
                                        <td class="text-center fw-bold">{{ $status['jumlah'] }}</td>
                                        <td class="text-center">{{ $status['persentase'] }}%</td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Link ke SKM -->
        <div class="card">
            <div class="card-header bg-warning text-dark">
                <h5 class="mb-0">
                    <i class="fas fa-star me-2"></i>
                    Survei Kepuasan Masyarakat
                </h5>
            </div>
            <div class="card-body">
                <div class="row align-items-center">
                    <div class="col-md-8">
                        <h6>Berikan Penilaian Terhadap Layanan PPID</h6>
                        <p class="mb-0 text-muted">Bantu kami meningkatkan kualitas layanan informasi publik dengan mengisi survei kepuasan masyarakat.</p>
                    </div>
                    <div class="col-md-4 text-end">
                        <a href="{{ route('ppid.survei') }}" class="btn btn-warning btn-lg">
                            <i class="fas fa-external-link-alt me-2"></i>
                            Isi Survei SKM
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Chart Permohonan per Tahun
        const permohonanCtx = document.getElementById('permohonanChart').getContext('2d');
        new Chart(permohonanCtx, {
            type: 'bar',
            data: {
                labels: [2022, 2023, 2024],
                datasets: [{
                    label: 'Jumlah Permohonan',
                    data: [85, 102, 128],
                    backgroundColor: 'rgba(42, 82, 152, 0.8)',
                    borderColor: 'rgba(42, 82, 152, 1)',
                    borderWidth: 1
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });

        // Chart Status Permohonan
        const statusCtx = document.getElementById('statusChart').getContext('2d');
        new Chart(statusCtx, {
            type: 'doughnut',
            data: {
                labels: ['Disetujui', 'Diproses', 'Ditolak', 'Keberatan'],
                datasets: [{
                    data: [95, 20, 10, 3],
                    backgroundColor: [
                        '#28a745',
                        '#ffc107', 
                        '#dc3545',
                        '#fd7e14'
                    ],
                    borderWidth: 2,
                    borderColor: '#fff'
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        position: 'bottom',
                        labels: {
                            padding: 20
                        }
                    },
                    tooltip: {
                        callbacks: {
                            label: function(context) {
                                const total = context.dataset.data.reduce((a, b) => a + b, 0);
                                const percentage = ((context.parsed / total) * 100).toFixed(1);
                                return context.label + ': ' + context.parsed + ' (' + percentage + '%)';
                            }
                        }
                    }
                }
            }
        });
    </script>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>