@extends('pemerintah.main')

@section('content')
    <!-- Page Title -->
    <div class="page-title-area">
        <div class="d-table">
            <div class="d-table-cell">
                <div class="container">
                    <div class="title-item">
                        <h2 class="text-wrap w-100">Permohonan Program</h2> <!-- Tambahkan w-100 -->
                        <ul>
                            <li>
                                <a>Beranda</a>
                            </li>
                            <li>
                                <i class='bx bx-chevrons-right'></i>
                            </li>
                            <li>
                                <span>Permohonan Program</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Page Title -->
    <div class="container mt-5">
        <h1 class="mb-4">Daftar Program</h1>

        @if (session('success'))
            <div class="alert alert-success">
                {{ session('success') }}
            </div>
        @endif

        @if (session('error'))
            <div class="alert alert-danger">
                {{ session('error') }}
            </div>
        @endif

        <a href="{{ route('permohonanprojects.create') }}" class="btn btn-primary mb-3">Tambahkan Permohonan Program
            Baru</a>

        <div class="row">
            @foreach ($projects as $project)
                <div class="col-md-4 mb-4">
                    <div class="card">
                        @if ($project->foto_proyek)
                            <img src="{{ asset('storage/' . $project->foto_proyek) }}" class="card-img-top"
                                alt="{{ $project->judul_project }}">
                        @else
                            <img src="https://via.placeholder.com/400x200" class="card-img-top" alt="Placeholder Image">
                        @endif

                        <div class="card-body">
                            <h5 class="card-title">{{ $project->judul_project }}</h5>
                            <p class="card-text">{{ Str::words($project->latar_belakang, 100) }}</p>
                            <a href="{{ $project->kategori === 'Pelatihan'
                                ? route('permohonanpelatihan.show', $project->id)
                                : ($project->kategori === 'Pendanaan'
                                    ? route('permohonanpendanaan.show', $project->id)
                                    : ($project->kategori === 'Riset'
                                        ? route('permohonanriset.show', $project->id)
                                        : ($project->kategori === 'Project Investor'
                                            ? route('permohonanproyek-investor.show', $project->id)
                                            : '#'))) }}"
                                class="btn btn-info">View</a>

                            <a href="{{ route('permohonanprojects.edit', $project->id) }}" class="btn btn-warning">Edit</a>
                            {{-- <form action="{{ route('permohonanprojects.destroy', $project->id) }}" method="POST"
                                style="display:inline;">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="btn btn-danger">Delete</button>

                            </form> --}}

                            <!-- Tombol yang memicu modal konfirmasi -->
                            <button type="button" class="btn btn-danger" data-bs-toggle="modal"
                                data-bs-target="#confirmDeleteModal">
                                Delete
                            </button>

                            <!-- Modal Konfirmasi Penghapusan -->
                            <div class="modal fade" id="confirmDeleteModal" tabindex="-1"
                                aria-labelledby="confirmDeleteModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title" id="confirmDeleteModalLabel">Konfirmasi Hapus</h5>
                                            <button type="button" class="btn-close" data-bs-dismiss="modal"
                                                aria-label="Close"></button>
                                        </div>
                                        <div class="modal-body">
                                            Apa anda yakin ingin menghapus program ini?
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-secondary"
                                                data-bs-dismiss="modal">Batal</button>
                                            <!-- Form delete yang akan dipanggil setelah konfirmasi -->
                                            <form action="{{ route('permohonanprojects.destroy', $project->id) }}"
                                                method="POST" style="display:inline;">
                                                @csrf
                                                @method('DELETE')
                                                <button type="submit" class="btn btn-danger">Ya, Hapus</button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!-- Bootstrap JS (pastikan sudah ditambahkan) -->
                            <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

                        </div>
                    </div>
                </div>
            @endforeach
        </div>
    </div>
@endsection
