<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Daftar Penilaian Kepuasan Pelanggan</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            color: #333;
        }
        .header {
            text-align: center;
            margin-bottom: 20px;
            border-bottom: 1px solid #ddd;
            padding-bottom: 10px;
        }
        .logo {
            max-width: 150px;
            margin-bottom: 10px;
        }
        h1 {
            font-size: 20px;
            margin-bottom: 5px;
        }
        .info-section {
            margin-bottom: 20px;
        }
        .info-section h2 {
            font-size: 16px;
            margin-bottom: 10px;
            border-bottom: 1px solid #eee;
            padding-bottom: 5px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
            font-size: 12px;
        }
        table th, table td {
            padding: 8px;
            border: 1px solid #ddd;
            text-align: left;
        }
        table th {
            background-color: #f5f5f5;
            font-weight: bold;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .score {
            text-align: center;
        }
        .score-1 { background-color: #FFD9D9; }
        .score-2 { background-color: #FFEBD9; }
        .score-3 { background-color: #F0F0F0; }
        .score-4 { background-color: #D9EBD9; }
        .score-5 { background-color: #C6E6C6; }
        .footer {
            margin-top: 30px;
            text-align: center;
            font-size: 12px;
            color: #777;
            border-top: 1px solid #ddd;
            padding-top: 10px;
        }
        .filter-info {
            margin-bottom: 15px;
            font-size: 14px;
            font-style: italic;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>DAFTAR PENILAIAN KEPUASAN PELANGGAN</h1>
        <p>Dicetak pada: {{ date('d-m-Y H:i:s') }}</p>
    </div>

    @if(isset($filters) && count($filters) > 0)
    <div class="filter-info">
        <p><strong>Filter yang digunakan:</strong></p>
        <ul>
            @foreach($filters as $key => $value)
                @if($value)
                    <li>{{ ucfirst(str_replace('_', ' ', $key)) }}: {{ $value }}</li>
                @endif
            @endforeach
        </ul>
    </div>
    @endif

    <div class="info-section">
        <h2>Daftar Penilaian</h2>
        <table>
            <thead>
                <tr>
                    <th>No</th>
                    <th>Nama</th>
                    <th>Tanggal Pengisian</th>
                    <th>Nilai Rata-rata</th>
                    <th>Q1</th>
                    <th>Q2</th>
                    <th>Q3</th>
                    <th>Q4</th>
                    <th>Q5</th>
                    <th>Q6</th>
                    <th>Q7</th>
                    <th>Q8</th>
                    <th>Q9</th>
                    <th>Q10</th>
                    <th>Q11</th>
                    <th>Q12</th>
                    <th>Q13</th>
                    <th>Q14</th>
                    <th>Q15</th>
                </tr>
            </thead>
            <tbody>
                @forelse($satisfactions as $key => $satisfaction)
                <tr>
                    <td>{{ $key + 1 }}</td>
                    <td>{{ $satisfaction->user->name }}</td>
                    <td>{{ $satisfaction->created_at->format('d M Y') }}</td>
                    <td class="score
                        @if($satisfaction->average_score >= 4) score-5
                        @elseif($satisfaction->average_score >= 3) score-4
                        @elseif($satisfaction->average_score >= 2) score-3
                        @elseif($satisfaction->average_score >= 1) score-2
                        @else score-1 @endif">
                        {{ number_format($satisfaction->average_score, 1) }}
                    </td>
                    <td class="score score-{{ $satisfaction->q1 }}">{{ $satisfaction->q1 }}</td>
                    <td class="score score-{{ $satisfaction->q2 }}">{{ $satisfaction->q2 }}</td>
                    <td class="score score-{{ $satisfaction->q3 }}">{{ $satisfaction->q3 }}</td>
                    <td class="score score-{{ $satisfaction->q4 }}">{{ $satisfaction->q4 }}</td>
                    <td class="score score-{{ $satisfaction->q5 }}">{{ $satisfaction->q5 }}</td>
                    <td class="score score-{{ $satisfaction->q6 }}">{{ $satisfaction->q6 }}</td>
                    <td class="score score-{{ $satisfaction->q7 }}">{{ $satisfaction->q7 }}</td>
                    <td class="score score-{{ $satisfaction->q8 }}">{{ $satisfaction->q8 }}</td>
                    <td class="score score-{{ $satisfaction->q9 }}">{{ $satisfaction->q9 }}</td>
                    <td class="score score-{{ $satisfaction->q10 }}">{{ $satisfaction->q10 }}</td>
                    <td class="score score-{{ $satisfaction->q11 }}">{{ $satisfaction->q11 }}</td>
                    <td class="score score-{{ $satisfaction->q12 }}">{{ $satisfaction->q12 }}</td>
                    <td class="score score-{{ $satisfaction->q13 }}">{{ $satisfaction->q13 }}</td>
                    <td class="score score-{{ $satisfaction->q14 }}">{{ $satisfaction->q14 }}</td>
                    <td class="score score-{{ $satisfaction->q15 }}">{{ $satisfaction->q15 }}</td>
                </tr>
                @empty
                <tr>
                    <td colspan="20" style="text-align: center;">Tidak ada data penilaian kepuasan</td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="info-section">
        <h2>Ringkasan</h2>
        <table>
            <tr>
                <td style="width: 60%;"><strong>Total Penilaian</strong></td>
                <td>{{ $satisfactions->count() }}</td>
            </tr>
            <tr>
                <td><strong>Rata-rata Keseluruhan</strong></td>
                <td>{{ number_format($satisfactions->avg('average_score'), 2) }}</td>
            </tr>
            <tr>
                <td><strong>Nilai Tertinggi</strong></td>
                <td>{{ number_format($satisfactions->max('average_score'), 2) }}</td>
            </tr>
            <tr>
                <td><strong>Nilai Terendah</strong></td>
                <td>{{ number_format($satisfactions->min('average_score'), 2) }}</td>
            </tr>
            <tr>
                <td><strong>Jumlah Penilaian Sangat Baik (>=4)</strong></td>
                <td>{{ $satisfactions->filter(function($item) { return $item->average_score >= 4; })->count() }}</td>
            </tr>
            <tr>
                <td><strong>Jumlah Penilaian Baik (>=3)</strong></td>
                <td>{{ $satisfactions->filter(function($item) { return $item->average_score >= 3 && $item->average_score < 4; })->count() }}</td>
            </tr>
            <tr>
                <td><strong>Jumlah Penilaian Cukup (>=2)</strong></td>
                <td>{{ $satisfactions->filter(function($item) { return $item->average_score >= 2 && $item->average_score < 3; })->count() }}</td>
            </tr>
            <tr>
                <td><strong>Jumlah Penilaian Kurang (<2)</strong></td>
                <td>{{ $satisfactions->filter(function($item) { return $item->average_score < 2; })->count() }}</td>
            </tr>
        </table>
    </div>

    <div class="footer">
        <p>Dokumen ini diterbitkan secara elektronik dan tidak memerlukan tanda tangan.</p>
        <p>© {{ date('Y') }} UPTD Laboratorium Lingkungan Pada Dinas Lingkungan Hidup Kota Probolinggo - Laporan Penilaian Kepuasan Pelanggan</p>
    </div>
</body>
</html> 