@extends('layouts.app')

@section('title', 'Kelola OPD - SKM Survey')

@section('content')
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col-12">
            <h2 style="color: #1e3a8a; font-weight: 700;">
                <i class="bi bi-building me-2"></i> Kelola Organisasi Perangkat Daerah (OPD)
            </h2>
            <p class="text-muted">Kelola data Organisasi Perangkat Daerah untuk Survey Kepuasan Masyarakat</p>
        </div>
    </div>

    <div class="card card-gov shadow-sm mb-4">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h5 class="mb-0">
                <i class="bi bi-list-ul me-2"></i> Daftar OPD
            </h5>
            <a href="{{ route('admin.opds.create') }}" class="btn btn-gov-primary">
                <i class="bi bi-plus-circle me-2"></i> Tambah OPD
            </a>
        </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: 200px;">Deskripsi</th>
                            <th style="width: 120px;" class="text-center">Total Response</th>
                            <th style="width: 100px;" class="text-center">Status</th>
                            <th style="width: 250px;" 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>
                                    <small class="text-muted">{{ \Illuminate\Support\Str::limit($opd->description, 50) }}</small>
                                </td>
                                <td class="text-center">
                                    <span class="badge bg-secondary">{{ $opd->responses_count }}</span>
                                </td>
                                <td class="text-center">
                                    @if($opd->is_active)
                                        <span class="badge bg-success">Aktif</span>
                                    @else
                                        <span class="badge bg-secondary">Nonaktif</span>
                                    @endif
                                </td>
                                <td>
                                    <div class="btn-group" role="group">
                                        <a href="{{ route('admin.opds.show', $opd->id) }}" class="btn btn-sm btn-info">
                                            <i class="bi bi-eye"></i> Detail
                                        </a>
                                        <a href="{{ route('admin.opds.edit', $opd->id) }}" class="btn btn-sm btn-primary">
                                            <i class="bi bi-pencil"></i> Edit
                                        </a>
                                        <a href="{{ route('admin.opd.results', $opd->id) }}" class="btn btn-sm btn-success">
                                            <i class="bi bi-graph-up"></i> Hasil
                                        </a>
                                        <form action="{{ route('admin.opds.destroy', $opd->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Apakah Anda yakin ingin menghapus OPD ini?');">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-sm btn-danger">
                                                <i class="bi bi-trash"></i> Hapus
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="7" 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>
                                    <a href="{{ route('admin.opds.create') }}" class="btn btn-gov-primary mt-3">
                                        <i class="bi bi-plus-circle me-2"></i> Tambah OPD Pertama
                                    </a>
                                </td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@endsection

