<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Daftar Layanan Pengujian Air</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;
        }
        .status {
            display: inline-block;
            padding: 3px 6px;
            border-radius: 3px;
            font-size: 11px;
            color: white;
            background-color: #777;
        }
        .status-menunggu { background-color: #f0ad4e; }
        .status-diterima { background-color: #5bc0de; }
        .status-diproses { background-color: #0275d8; }
        .status-selesai { background-color: #5cb85c; }
        .status-ditolak { background-color: #d9534f; }
        .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 LAYANAN PENGUJIAN AIR</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 Layanan</h2>
        <table>
            <thead>
                <tr>
                    <th>No</th>
                    <th>Nama</th>
                    <th>Jenis Permintaan</th>
                    <th>Pengujian Air</th>
                    <th>Parameter</th>
                    <th>Total Sampel</th>
                    <th>Tanggal Uji</th>
                    <th>Status</th>
                    <th>Total Biaya</th>
                </tr>
            </thead>
            <tbody>
                @forelse($services as $key => $service)
                <tr>
                    <td>{{ $key + 1 }}</td>
                    <td>{{ $service->user->name }}</td>
                    <td>{{ Str::limit($service->jenis_permintaan, 25) }}</td>
                    <td>{{ $service->pengujian_kualitas_air }}</td>
                    <td>{{ Str::limit($service->parameter, 15) }}</td>
                    <td>{{ $service->total_sampel }}</td>
                    <td>{{ \Carbon\Carbon::parse($service->tanggal_uji)->format('d M Y') }}</td>
                    <td>
                        <span class="status status-{{ strtolower($service->status) }}">{{ $service->status }}</span>
                    </td>
                    <td>
                        @if($service->biaya_retribusi)
                            Rp {{ number_format($service->biaya_retribusi, 0, ',', '.') }}
                        @elseif($service->status == 'Ditolak')
                            <span style="color: #d9534f; font-weight: bold;">Ditolak</span>
                        @else
                            Menunggu
                        @endif
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="9" style="text-align: center;">Tidak ada data layanan</td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="info-section">
        <h2>Ringkasan</h2>
        <table>
            <tr>
                <td style="width: 60%;"><strong>Total Layanan</strong></td>
                <td>{{ $services->count() }}</td>
            </tr>
            <tr>
                <td><strong>Total Biaya Retribusi</strong></td>
                <td>Rp {{ number_format($services->whereNotIn('status', ['Ditolak'])->sum('biaya_retribusi'), 0, ',', '.') }}</td>
            </tr>
            <tr>
                <td><strong>Layanan Status Menunggu</strong></td>
                <td>{{ $services->where('status', 'Menunggu')->count() }}</td>
            </tr>
            <tr>
                <td><strong>Layanan Status Diterima</strong></td>
                <td>{{ $services->where('status', 'Diterima')->count() }}</td>
            </tr>
            <tr>
                <td><strong>Layanan Status Diproses</strong></td>
                <td>{{ $services->where('status', 'Diproses')->count() }}</td>
            </tr>
            <tr>
                <td><strong>Layanan Status Selesai</strong></td>
                <td>{{ $services->where('status', 'Selesai')->count() }}</td>
            </tr>
            <tr>
                <td><strong>Layanan Status Ditolak</strong></td>
                <td>{{ $services->where('status', 'Ditolak')->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 Layanan Pengujian Air</p>
    </div>
</body>
</html> 