@extends('layouts.app')

@section('title', 'Kelola Informasi Publik - Admin PPID')

@section('content')
<div class="container">
    <div class="row mb-4">
        <div class="col-md-12">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h3 class="mb-1"><i class="bi bi-folder-fill me-2"></i>Kelola Informasi Publik</h3>
                    <p class="text-muted mb-0">Manajemen data informasi publik PPID</p>
                </div>
                <a href="{{ route('admin.ppid.informasi.create') }}" class="btn btn-gov-primary">
                    <i class="bi bi-plus-circle me-1"></i> Tambah Informasi
                </a>
            </div>
        </div>
    </div>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show shadow-sm" role="alert">
            <i class="bi bi-check-circle me-2"></i>
            <strong>Berhasil!</strong> {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    @if(session('error'))
        <div class="alert alert-danger alert-dismissible fade show shadow-sm" role="alert">
            <i class="bi bi-exclamation-triangle me-2"></i>
            <strong>Error!</strong> {{ session('error') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    <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 Informasi Publik</h5>
        </div>
        <div class="card-body">
            @if($informasi->count() > 0)
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead class="table-light">
                            <tr>
                                <th width="5%">No</th>
                                <th width="30%">Judul</th>
                                <th width="15%">Kategori</th>
                                <th width="10%">Tahun</th>
                                <th width="10%">Status</th>
                                <th width="15%">File</th>
                                <th width="15%">Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($informasi as $index => $item)
                                <tr>
                                    <td>{{ $informasi->firstItem() + $index }}</td>
                                    <td>
                                        <strong>{{ $item->judul }}</strong>
                                        <br>
                                        <small class="text-muted">{{ Str::limit($item->ringkasan, 60) }}</small>
                                    </td>
                                    <td>
                                        <span class="badge bg-{{ $item->kategori_warna }}">
                                            {{ $item->kategori_nama }}
                                        </span>
                                    </td>
                                    <td>{{ $item->tahun }}</td>
                                    <td>
                                        @if($item->is_published)
                                            <span class="badge bg-success">
                                                <i class="bi bi-check-circle"></i> Published
                                            </span>
                                        @else
                                            <span class="badge bg-secondary">
                                                <i class="bi bi-x-circle"></i> Draft
                                            </span>
                                        @endif
                                    </td>
                                    <td>
                                        @if($item->file_name)
                                            <i class="bi bi-file-earmark-pdf text-danger"></i>
                                            <small>{{ Str::limit($item->file_name, 20) }}</small>
                                        @else
                                            <small class="text-muted">Tidak ada file</small>
                                        @endif
                                    </td>
                                    <td>
                                        <div class="btn-group" role="group">
                                            <a href="{{ route('admin.ppid.informasi.edit', $item->id) }}"
                                               class="btn btn-sm btn-warning"
                                               title="Edit">
                                                <i class="bi bi-pencil"></i>
                                            </a>
                                            <button type="button"
                                                    class="btn btn-sm btn-danger"
                                                    onclick="confirmDelete({{ $item->id }})"
                                                    title="Hapus">
                                                <i class="bi bi-trash"></i>
                                            </button>
                                        </div>
                                        <form id="delete-form-{{ $item->id }}"
                                              action="{{ route('admin.ppid.informasi.destroy', $item->id) }}"
                                              method="POST"
                                              style="display: none;">
                                            @csrf
                                            @method('DELETE')
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>

                <div class="d-flex justify-content-center mt-4">
                    {{ $informasi->links() }}
                </div>
            @else
                <div class="text-center py-5">
                    <i class="bi bi-inbox" style="font-size: 3rem; color: #ccc;"></i>
                    <p class="text-muted mt-3">Belum ada data informasi publik</p>
                    <a href="{{ route('admin.ppid.informasi.create') }}" class="btn btn-gov-primary mt-2">
                        <i class="bi bi-plus-circle me-1"></i> Tambah Informasi Pertama
                    </a>
                </div>
            @endif
        </div>
    </div>
</div>

@push('scripts')
<script>
function confirmDelete(id) {
    if (confirm('Apakah Anda yakin ingin menghapus informasi ini?')) {
        document.getElementById('delete-form-' + id).submit();
    }
}
</script>
@endpush
@endsection
