@extends('layouts.app')

@section('title', 'Dashboard Admin - Survey Kepuasan Masyarakat (SKM)')

@section('content')
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h2 style="color: #1e3a8a; font-weight: 700;">
                        <i class="bi bi-speedometer2 me-2"></i> Dashboard Administrator
                    </h2>
                    <p class="text-muted">Ringkasan data Survey Kepuasan Masyarakat (SKM)</p>
                </div>
                <a href="{{ route('admin.answer-options.index') }}" class="btn btn-gov-primary">
                    <i class="bi bi-list-check me-2"></i> Kelola Opsi Jawaban
                </a>
            </div>
        </div>
    </div>

    <div class="row mb-4">
        <div class="col-md-4 mb-3">
            <div class="card border-0 shadow-sm" style="border-left: 4px solid #1e3a8a !important;">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <h6 class="text-muted mb-2" style="font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px;">
                                Total OPD
                            </h6>
                            <h3 class="mb-0" style="color: #1e3a8a; font-weight: 700;">{{ $totalOpds }}</h3>
                        </div>
                        <div class="bg-primary bg-opacity-10 rounded p-3">
                            <i class="bi bi-building text-primary" style="font-size: 2.5rem;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4 mb-3">
            <div class="card border-0 shadow-sm" style="border-left: 4px solid #28a745 !important;">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <h6 class="text-muted mb-2" style="font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px;">
                                Total Response
                            </h6>
                            <h3 class="mb-0" style="color: #28a745; font-weight: 700;">{{ $totalResponses }}</h3>
                        </div>
                        <div class="bg-success bg-opacity-10 rounded p-3">
                            <i class="bi bi-clipboard-check text-success" style="font-size: 2.5rem;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4 mb-3">
            <div class="card border-0 shadow-sm" style="border-left: 4px solid #17a2b8 !important;">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <h6 class="text-muted mb-2" style="font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px;">
                                Total Pertanyaan
                            </h6>
                            <h3 class="mb-0" style="color: #17a2b8; font-weight: 700;">{{ $totalQuestions }}</h3>
                        </div>
                        <div class="bg-info bg-opacity-10 rounded p-3">
                            <i class="bi bi-question-circle text-info" style="font-size: 2.5rem;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card card-gov shadow-sm">
        <div class="card-header">
            <h5 class="mb-0">
                <i class="bi bi-list-ul me-2"></i> Daftar Organisasi Perangkat Daerah (OPD)
            </h5>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th style="width: 50px;">No</th>
                            <th>Nama OPD</th>
                            <th style="width: 100px;">Kode</th>
                            <th style="width: 120px;" class="text-center">Total Response</th>
                            <th style="width: 150px;" class="text-center">Rata-rata Rating</th>
                            <th style="width: 280px;" class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($opds as $index => $opd)
                            <tr>
                                <td class="fw-semibold">{{ $index + 1 }}</td>
                                <td>
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-building text-primary me-2"></i>
                                        <strong>{{ $opd->name }}</strong>
                                    </div>
                                </td>
                                <td>
                                    <span class="badge-gov">{{ $opd->code }}</span>
                                </td>
                                <td class="text-center">
                                    <span class="badge bg-secondary">{{ $opd->responses_count }}</span>
                                </td>
                                <td class="text-center">
                                    @if($opd->responses_count > 0)
                                        <span class="badge bg-info fs-6">{{ number_format($opd->average_rating, 2) }}</span>
                                    @else
                                        <span class="text-muted">-</span>
                                    @endif
                                </td>
                                <td>
                                    <div class="btn-group" role="group">
                                        <a href="{{ route('admin.opd.results', $opd->id) }}" class="btn btn-sm btn-gov-primary">
                                            <i class="bi bi-eye me-1"></i> Hasil
                                        </a>
                                        <a href="{{ route('admin.opd.export.excel', $opd->id) }}" class="btn btn-sm btn-success">
                                            <i class="bi bi-file-earmark-excel me-1"></i> Excel
                                        </a>
                                        <a href="{{ route('admin.opd.export.pdf', $opd->id) }}" class="btn btn-sm btn-danger">
                                            <i class="bi bi-file-earmark-pdf me-1"></i> PDF
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="text-center py-4">
                                    <i class="bi bi-inbox text-muted" style="font-size: 3rem;"></i>
                                    <p class="text-muted mt-2 mb-0">Belum ada data OPD</p>
                                </td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@endsection

