@extends('pemerintah.main')

@section('content')
    <style>
        body {
            background-color: #f8f9fa;
        }

        .profile-container {
            max-width: 1500px;
            margin: 0 auto;
            padding: 30px;
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        }

        .profile-img {
            border: 3px solid #e9ecef;
            margin: 12px;
            padding: 5px;
            background-color: #fff;
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
        }

        .profile-img img {
            border-radius: 50%;
        }

        .card {
            border-radius: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
            margin-top: 20px;
        }

        .card-title {
            font-size: 1.75rem;
            margin-bottom: 15px;
            color: #343a40;
        }

        .edit-btn {
            background-color: #007bff;
            color: white;
            border-radius: 5px;
            padding: 10px 20px;
            text-decoration: none;
            margin-top: 20px;
            display: inline-block;
            transition: background-color 0.3s;
        }

        .edit-btn:hover {
            background-color: #0056b3;
        }

        .list-group-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .list-group-item strong {
            color: #6c757d;
        }

        @media (max-width: 768px) {
            .profile-container {
                padding: 15px;
            }
        }

        .text-center {
            display: flex;
            /* Menggunakan flexbox untuk memusatkan konten */
            flex-direction: column;
            /* Menyusun elemen secara vertikal */
            align-items: center;
            /* Memusatkan konten secara horizontal */
        }

        .profile-img {
            display: flex;

            justify-content: center;
            /* Memusatkan gambar secara horizontal */
            align-items: center;
            /* Memusatkan gambar secara vertikal */
            width: 200px;
            /* Lebar kontainer gambar */
            height: 200px;
            /* Tinggi kontainer gambar */
            border-radius: 50%;
            /* Membuat kontainer gambar menjadi bulat */
            overflow: hidden;
            /* Menghindari gambar melampaui batas kontainer */
            background-color: #f0f0f0;
            /* Warna latar belakang untuk tampilan */
        }

        .profile-img img {
            width: 100%;
            /* Memastikan gambar memenuhi lebar kontainer */
            height: 100%;
            /* Memastikan gambar memenuhi tinggi kontainer */
            object-fit: cover;
            /* Memastikan gambar terpotong dan tetap memenuhi area */
        }

        /* CSS untuk Container Pilihan Filter */
        .filter-container {
            background-color: #f8f9fa;
            /* Warna latar belakang */
            padding: 20px;
            /* Padding di sekitar konten */
            border-radius: 8px;
            /* Membuat sudut membulat */
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            /* Bayangan lembut di bawah container */
            margin-bottom: 20px;
            /* Jarak bawah untuk memisahkan dari elemen lain */
        }

        /* Menyesuaikan label untuk meningkatkan keterbacaan */
        .filter-container .form-label {
            font-weight: bold;
            /* Menggunakan teks tebal */
            margin-bottom: 15px;
            /* Jarak bawah untuk pemisahan dari checkbox */
            font-size: 1.2rem;
            /* Ukuran font yang lebih besar */
        }

        /* Gaya untuk checkbox */
        .filter-container .form-check {
            margin-bottom: 10px;
            /* Jarak bawah antara setiap checkbox */
        }

        /* Menambahkan efek hover pada checkbox */
        .filter-container .form-check-input:checked {
            background-color: #007bff;
            /* Warna latar belakang saat dicentang */
            border-color: #007bff;
            /* Warna border saat dicentang */
        }

        /* Gaya label checkbox */
        .filter-container .form-check-label {
            cursor: pointer;
            /* Menunjukkan pointer saat hover */
            font-size: 1rem;
            /* Ukuran font untuk label */
        }

        /* Gaya untuk checkbox saat hover */
        .filter-container .form-check-input:hover {
            outline: none;
            /* Menghapus outline default saat hover */
        }
    </style>

    <div class="container py-5 mt-5 profile-container">
        <div class="card">
            <div class="card-body">
                <div class="text-center">
                    <div class="profile-img">
                        <img src="{{ asset('storage/' . $detail->foto) }}" alt="Profile Picture" class="img-fluid"
                            width="150" height="150">
                    </div>
                    <h2 class="mt-3">{{ $user->full_name }}</h2>
                    <p class="text-muted">{{ ucfirst($user->role) }}</p>

                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-8">
                <!-- Profile Card -->
                <div class="card mb-8">
                    <div class="card-body">
                        <h4 class="card-title">Detail Profil</h4>
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item"><strong>NIK:</strong> {{ $user->nik }}</li>
                            <li class="list-group-item"><strong>Tanggal Lahir:</strong> {{ $user->birthdate }}</li>
                            <li class="list-group-item"><strong>Alamat:</strong> {{ $user->address }}</li>
                            <li class="list-group-item"><strong>Email:</strong> {{ $user->email }}</li>
                            <li class="list-group-item"><strong>Telepon:</strong> {{ $user->phone_number }}</li>

                            @if ($user->role == 'pemerintah')
                                <li class="list-group-item"><strong>Instansi:</strong> {{ $detail->institution_name }}
                                </li>
                            @elseif($user->role == 'umkm')
                                <li class="list-group-item"><strong>Nama UMKM:</strong> {{ $detail->umkm_name }}</li>
                                <li class="list-group-item"><strong>Tanggal Berdiri:</strong>
                                    {{ $detail->establishment_date_umkm }}</li>
                                {{-- <li class="list-group-item"><strong>Description:</strong> {{ $detail->description_umkm }}
                                </li> --}}
                                <li class="list-group-item"><strong>Nomor SIUP:</strong> {{ $detail->siup_number_umkm }}
                                </li>
                                <li class="list-group-item"><strong>Produk:</strong> {{ $detail->product }}</li>
                                <li class="list-group-item"><strong>Laporan Keuangan:</strong> <a
                                        href="{{ Storage::url($detail->laporan_keuangan) }}"
                                        download="{{ basename($detail->laporan_keuangan) }}"
                                        class="btn btn-primary">Download</a>
                                </li>
                                <li class="list-group-item"><strong>Kategori Pendapatan
                                        UMKM:</strong> {{ $detail->profit_umkm }}</li>
                            @elseif($user->role == 'investor')
                                @php
                                    $detail = $user->investorDetails;
                                @endphp

                                @if ($detail->category === 'personal' && $detail->personalDetails)
                                    @php
                                        $personalDetail = $detail->personalDetails;
                                    @endphp
                                    <li class="list-group-item"><strong>Nomor NPWP:</strong>
                                        {{ $personalDetail->npwp_number_inves_personal }}</li>
                                    <li class="list-group-item"><strong>Pekerjaan:</strong> {{ $personalDetail->job }}</li>
                                    <li class="list-group-item"><strong>Total Assets:</strong>
                                        {{ number_format($personalDetail->total_assets, 2, ',', '.') }}</li>
                                    <li class="list-group-item"><strong>Profit:</strong>
                                        {{ number_format($personalDetail->profit_inves_personal, 2, ',', '.') }}</li>
                                @elseif ($detail->category === 'perusahaan' && $detail->perusahaanDetails)
                                    @php
                                        $perusahaanDetail = $detail->perusahaanDetails;
                                    @endphp
                                    <li class="list-group-item"><strong>Nama Perusahaan:</strong>
                                        {{ $perusahaanDetail->company_name }}</li>
                                    {{-- <li class="list-group-item"><strong>Description:</strong>
                                        {{ $perusahaanDetail->description_inves_perusahaan }}</li> --}}
                                    <li class="list-group-item"><strong>Tanggal Berdiri:</strong>
                                        {{ $perusahaanDetail->establishment_date_inves_perusahaan }}</li>
                                    <li class="list-group-item"><strong>Nomor SIUP:</strong>
                                        {{ $perusahaanDetail->siup_number_inves_perusahaan }}</li>
                                    <li class="list-group-item"><strong>Nomor NIB:</strong>
                                        {{ $perusahaanDetail->nib_number }}
                                    </li>
                                    <li class="list-group-item"><strong>Nomor NPWP:</strong>
                                        {{ $perusahaanDetail->npwp_number_inves_perusahaan }}</li>
                                    <li class="list-group-item"><strong>Profit:</strong>
                                        {{ number_format($perusahaanDetail->profit_inves_perusahaan, 2, ',', '.') }}</li>
                                @else
                                    <li class="list-group-item">No details available for this investor.</li>
                                @endif
                            @elseif($user->role == 'akademisi')
                                <li class="list-group-item"><strong>Nama Perguruan Tinggi:</strong>
                                    {{ $detail->university_name }}
                                </li>
                                <li class="list-group-item"><strong>Fakultas:</strong> {{ $detail->faculty }}</li>
                                <li class="list-group-item"><strong>Bidang Keahlian:</strong>
                                    {{ $detail->expertise_field }}</li>
                            @elseif($user->role == 'komunitas')
                                <li class="list-group-item"><strong>Nama Komunitas:</strong> {{ $detail->community_name }}
                                </li>
                                <li class="list-group-item"><strong>Nomor Lisensi:</strong>
                                    {{ $detail->community_license }}</li>
                            @endif
                        </ul>
                        <a href="{{ route('profile.edit', $user->id) }}" class="edit-btn">Edit Profile</a>
                    </div>
                </div>
                <div class="card mb-8">
                    <div class="card-body">
                        <h4 class="card-title">Tentang</h4>
                        <ul class="list-group list-group-flush">
                            @if ($user->role == 'pemerintah')
                                <li class="list-group-item">{{ $detail->description_pemerintah }}</li>
                            @elseif ($user->role == 'akademisi')
                                <li class="list-group-item">{{ $detail->description_akademisi }}</li>
                            @elseif ($user->role == 'komunitas')
                                <li class="list-group-item">{{ $detail->description_komunitas }}</li>
                            @elseif ($user->role == 'umkm')
                                <li class="list-group-item">{{ $detail->description_umkm }}</li>
                            @elseif ($user->role == 'investor')
                                @if ($detail->category === 'perusahaan' && $detail->perusahaanDetails)
                                    @php
                                        $perusahaanDetail = $detail->perusahaanDetails;
                                    @endphp
                                @else
                                    <li class="list-group-item">Tidak ada rincian untuk investor ini.</li>
                                @endif
                            @else
                                <li class="list-group-item">Deskripsi tidak tersedia untuk peran ini.</li>
                            @endif
                        </ul>
                    </div>
                </div>

            </div>

            {{-- <div class="col-md-4">
                <div class="card mb-4">
                    <div class="card-body">
                        <h4 class="card-title">Preferences</h4>
                        <div class="filter-area bg-light p-4 rounded" style="border: 1px solid #ccc;">
                            <form id="filter-form" method="POST" action="{{ route('preferencesPermohonan.store') }}">
                                @csrf
                                <!-- Bidang Filter -->
                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Bidang</label>
                                    <div>
                                        @foreach (['Aplikasi dan permainan', 'Arsitektur', 'Desain', 'Film, video, dan animasi', 'Fotografi', 'Kriya', 'Kuliner', 'Mode', 'Musik', 'Penerbitan', 'Periklanan', 'Permainan rakyat', 'Radio dan televisi', 'Riset dan pengembangan', 'Seni pertunjukan', 'Seni rupa', 'Software'] as $bidang)
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input" id="bidang_{{ strtolower(str_replace(' ', '_', $bidang)) }}"
                                                    name="bidang_sub_sektor_ekonomi_kreatif[]" value="{{ $bidang }}"
                                                    {{ isset($preferences) && in_array($bidang, json_decode($preferences->bidang_sub_sektor_ekonomi_kreatif)) ? 'checked' : '' }}>
                                                <label class="form-check-label" for="bidang_{{ strtolower(str_replace(' ', '_', $bidang)) }}">{{ $bidang }}</label>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
            
                                <!-- Filter Kategori -->
                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Kategori</label>
                                    <div>
                                        @foreach (['Pelatihan', 'Pendanaan'] as $kategori)
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input" id="kategori_{{ strtolower($kategori) }}"
                                                    name="kategori[]" value="{{ $kategori }}"
                                                    {{ isset($preferences) && in_array($kategori, json_decode($preferences->kategori)) ? 'checked' : '' }}>
                                                <label class="form-check-label" for="kategori_{{ strtolower($kategori) }}">{{ $kategori }}</label>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
            
                                <!-- Filter Batas Terima Tawaran -->
                                <div class="col-md-12 mb-3">
                                    <label for="batas_terima_tawaran" class="form-label">Batas Terima Tawaran</label>
                                    <input type="date" id="batas_terima_tawaran" name="batas_terima_tawaran"
                                        value="{{ $preferences->batas_terima_tawaran ?? '' }}" class="form-control">
                                </div>
            
                                <!-- Range Filter for Biaya and Jumlah Dana -->
                                <div class="col-md-12 mb-3">
                                    <label for="range_biaya_jumlah_dana" class="form-label">Range Biaya dan Jumlah Dana
                                        (Min-Max)</label>
                                    <div class="input-group">
                                        <!-- Min Value -->
                                        <input type="number" step="0.01" id="range_min" name="range_min"
                                            class="form-control" placeholder="Min Value"
                                            value="{{ $preferences->range_min ?? '' }}">
                                        <span class="input-group-text">-</span>
                                        <!-- Max Value -->
                                        <input type="number" step="0.01" id="range_max" name="range_max"
                                            class="form-control" placeholder="Max Value"
                                            value="{{ $preferences->range_max ?? '' }}">
                                    </div>
                                </div>
            
                                <!-- Filter Status -->
                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Status</label>
                                    <div>
                                        @foreach (['Coming Soon', 'Berjalan', 'Selesai'] as $status)
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input" id="status_{{ strtolower(str_replace(' ', '_', $status)) }}"
                                                    name="status[]" value="{{ $status }}"
                                                    {{ isset($preferences) && in_array($status, json_decode($preferences->status)) ? 'checked' : '' }}>
                                                <label class="form-check-label" for="status_{{ strtolower(str_replace(' ', '_', $status)) }}">{{ $status }}</label>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
            
                                <div class="col-md-12">
                                    <button type="submit" class="btn btn-primary w-100">Filter</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div> --}}

            {{-- <div class="col-md-4">
                <div class="card mb-4">
                    <div class="card-body">
                        <h4 class="card-title">Preferences</h4>
                        <div class="filter-area bg-light p-4 rounded" style="border: 1px solid #ccc;">
                            <form id="filter-form" method="POST" action="{{ route('preferencesPermohonan.store') }}">
                                @csrf
                                <!-- Bidang Filter -->
                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Bidang</label>
                                    <div>
                                        @foreach (['Aplikasi dan permainan', 'Arsitektur', 'Desain', 'Film, video, dan animasi', 'Fotografi', 'Kriya', 'Kuliner', 'Mode', 'Musik', 'Penerbitan', 'Periklanan', 'Permainan rakyat', 'Radio dan televisi', 'Riset dan pengembangan', 'Seni pertunjukan', 'Seni rupa', 'Software'] as $bidang)
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input"
                                                    id="bidang_{{ strtolower(str_replace(' ', '_', $bidang)) }}"
                                                    name="bidang_sub_sektor_ekonomi_kreatif[]" value="{{ $bidang }}"
                                                    {{ isset($preferences) && is_array(json_decode($preferences->bidang_sub_sektor_ekonomi_kreatif)) && in_array($bidang, json_decode($preferences->bidang_sub_sektor_ekonomi_kreatif)) ? 'checked' : '' }}>
                                                <label class="form-check-label"
                                                    for="bidang_{{ strtolower(str_replace(' ', '_', $bidang)) }}">{{ $bidang }}</label>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>



                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Kategori</label>
                                    <div>
                                        @if (auth()->user()->role == 'pemerintah')
                                            @foreach (['Pelatihan', 'Pendanaan'] as $kategori)
                                                <div class="form-check">
                                                    <input type="checkbox" class="form-check-input"
                                                        id="kategori_{{ strtolower($kategori) }}" name="kategori[]"
                                                        value="{{ $kategori }}"
                                                        {{ isset($preferences) && is_array(json_decode($preferences->kategori)) && in_array($kategori, json_decode($preferences->kategori)) ? 'checked' : '' }}>
                                                    <label class="form-check-label"
                                                        for="kategori_{{ strtolower($kategori) }}">{{ $kategori }}</label>
                                                </div>
                                            @endforeach
                                        @elseif (in_array(auth()->user()->role, ['investor', 'umkm', 'akademisi', 'komunitas']))
                                            @foreach (['Pelatihan', 'Pendanaan', 'Riset'] as $kategori)
                                                <div class="form-check">
                                                    <input type="checkbox" class="form-check-input"
                                                        id="kategori_{{ strtolower($kategori) }}" name="kategori[]"
                                                        value="{{ $kategori }}"
                                                        {{ isset($preferences) && is_array(json_decode($preferences->kategori)) && in_array($kategori, json_decode($preferences->kategori)) ? 'checked' : '' }}>
                                                    <label class="form-check-label"
                                                        for="kategori_{{ strtolower($kategori) }}">{{ $kategori }}</label>
                                                </div>
                                            @endforeach
                                        @endif
                                    </div>
                                </div>


                                <!-- Filter Batas Terima Tawaran -->
                                <div class="col-md-12 mb-3">
                                    <label for="batas_terima_tawaran" class="form-label">Batas Terima Tawaran</label>
                                    <input type="date" id="batas_terima_tawaran" name="batas_terima_tawaran"
                                        value="{{ isset($preferences->batas_terima_tawaran) ? $preferences->batas_terima_tawaran : '' }}"
                                        class="form-control">
                                </div>

                                <!-- Range Filter for Biaya and Jumlah Dana -->
                                @if (auth()->user()->role == 'pemerintah' || auth()->user()->role == 'investor')
                                    <div class="col-md-12 mb-3">
                                        <label for="range_biaya_jumlah_dana" class="form-label">Range Biaya dan Jumlah
                                            Dana
                                            (Min-Max)</label>
                                        <div class="input-group">
                                            <!-- Min Value -->
                                            <input type="number" step="0.01" id="range_min" name="range_min"
                                                class="form-control" placeholder="Min Value"
                                                value="{{ isset($preferences->range_min) ? $preferences->range_min : '' }}">
                                            <span class="input-group-text">-</span>
                                            <!-- Max Value -->
                                            <input type="number" step="0.01" id="range_max" name="range_max"
                                                class="form-control" placeholder="Max Value"
                                                value="{{ isset($preferences->range_max) ? $preferences->range_max : '' }}">
                                        </div>
                                    </div>
                                @endif

                                <!-- Filter Status -->
                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Status</label>
                                    <div>
                                        @foreach (['Coming Soon', 'Berjalan', 'Selesai'] as $status)
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input"
                                                    id="status_{{ strtolower(str_replace(' ', '_', $status)) }}"
                                                    name="status[]" value="{{ $status }}"
                                                    {{ isset($preferences) && is_array(json_decode($preferences->status)) && in_array($status, json_decode($preferences->status)) ? 'checked' : '' }}>
                                                <label class="form-check-label"
                                                    for="status_{{ strtolower(str_replace(' ', '_', $status)) }}">{{ $status }}</label>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>

                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Audiens</label>
                                    <textarea class="form-control" id="audiens" name="audiens" rows="3" placeholder="Masukkan audiens...">{{ isset($preferences->audiens) ? $preferences->audiens : '' }}</textarea>
                                </div>

                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Benefit</label>
                                    <textarea class="form-control" id="benefit" name="benefit" rows="3" placeholder="Masukkan benefit...">{{ isset($preferences->benefit) ? $preferences->benefit : '' }}</textarea>
                                </div>

                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Durasi (Dalam Bulan)</label>
                                    <input type="number" id="durasi" name="durasi" class="form-control"
                                        placeholder="Masukkan durasi..."
                                        value="{{ isset($preferences->durasi) ? $preferences->durasi : '' }}">
                                </div>

                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Lokasi</label>
                                    <input type="text" id="lokasi" name="lokasi" class="form-control"
                                        placeholder="Masukkan lokasi..."
                                        value="{{ isset($preferences->lokasi) ? $preferences->lokasi : '' }}">
                                </div>

                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Metodologi</label>
                                    <textarea class="form-control" id="metodologi" name="metodologi" rows="3"
                                        placeholder="Masukkan metodologi...">{{ isset($preferences->metodologi) ? $preferences->metodologi : '' }}</textarea>
                                </div>

                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Rincian Kebutuhan</label>
                                    <textarea class="form-control" id="rincian_kebutuhan" name="rincian_kebutuhan" rows="3"
                                        placeholder="Masukkan rincian kebutuhan...">{{ isset($preferences->rincian_kebutuhan) ? $preferences->rincian_kebutuhan : '' }}</textarea>
                                </div>

                                <div class="col-md-12 mb-3">
                                    <label class="form-label">Penerima Manfaat Pengguna Project</label>
                                    <textarea class="form-control" id="penerima_manfaat_pengguna_project" name="penerima_manfaat_pengguna_project"
                                        rows="3" placeholder="Masukkan penerima manfaat pengguna project...">{{ isset($preferences->penerima_manfaat_pengguna_project) ? $preferences->penerima_manfaat_pengguna_project : '' }}</textarea>
                                </div>


                                <div class="col-md-12">
                                    <button type="submit" class="btn btn-primary w-100">Filter</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div> --}}

            <div class="col-md-4">
                <div class="card mb-4">
                    <div class="card-body">
                        <h4 class="card-title">Preferensi</h4>

                        <div class="filter-area bg-light p-4 rounded" style="border: 1px solid #ccc;">
                            @if ($errors->any())
                                <div class="alert alert-danger">
                                    <ul>
                                        @foreach ($errors->all() as $error)
                                            <li>{{ $error }}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif

                            <form id="filter-form" method="POST" action="{{ route('preferencesPermohonan.store') }}">
                                @csrf



                                <div class="filter-container">
                                    <div class="col-md-12 mb-3">
                                        <label class="form-label">Pilih Filter</label>

                                        <!-- Filter Bidang -->
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="filter_bidang"
                                                name="filters[]" value="bidang"
                                                {{ in_array('bidang', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_bidang">Bidang</label>
                                        </div>

                                        <!-- Filter Kategori -->
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="filter_kategori"
                                                name="filters[]" value="kategori"
                                                {{ in_array('kategori', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_kategori">Kategori</label>
                                        </div>

                                        <!-- Filter Audiens -->
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="filter_audiens"
                                                name="filters[]" value="audiens"
                                                {{ in_array('audiens', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_audiens">Audiens</label>
                                        </div>

                                        <!-- Filter Batas Terima Tawaran -->
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input"
                                                id="filter_batas_terima_tawaran" name="filters[]"
                                                value="batas_terima_tawaran"
                                                {{ in_array('batas_terima_tawaran', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_batas_terima_tawaran">Batas Terima
                                                Tawaran</label>
                                        </div>



                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="filter_range_dana"
                                                name="filters[]" value="range_dana"
                                                {{ in_array('range_dana', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_range_dana">Range Biaya dan Jumlah
                                                Dana</label>
                                        </div>


                                        <!-- Filter Status -->
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="filter_status"
                                                name="filters[]" value="status"
                                                {{ in_array('status', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_status">Status</label>
                                        </div>

                                        <!-- Filter Benefit -->
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="filter_benefit"
                                                name="filters[]" value="benefit"
                                                {{ in_array('benefit', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_benefit">Benefit</label>
                                        </div>

                                        <!-- Filter Durasi -->
                                        @if (auth()->user()->role == 'umkm' || auth()->user()->role == 'komunitas')
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input" id="filter_durasi"
                                                    name="filters[]" value="durasi"
                                                    {{ in_array('durasi', $selectedFilters) ? 'checked' : '' }}>
                                                <label class="form-check-label" for="filter_durasi">Durasi</label>
                                            </div>
                                        @endif

                                        <!-- Filter Lokasi -->
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="filter_lokasi"
                                                name="filters[]" value="lokasi"
                                                {{ in_array('lokasi', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_lokasi">Lokasi</label>
                                        </div>

                                        <!-- Filter Metodologi -->
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="filter_metodologi"
                                                name="filters[]" value="metodologi"
                                                {{ in_array('metodologi', $selectedFilters) ? 'checked' : '' }}>
                                            <label class="form-check-label" for="filter_metodologi">Metodologi</label>
                                        </div>

                                        <!-- Filter Rincian Kebutuhan -->
                                        @if (auth()->user()->role == 'pemerintah' || auth()->user()->role == 'investor')
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input"
                                                    id="filter_rincian_kebutuhan" name="filters[]"
                                                    value="rincian_kebutuhan"
                                                    {{ in_array('rincian_kebutuhan', $selectedFilters) ? 'checked' : '' }}>
                                                <label class="form-check-label" for="filter_rincian_kebutuhan">Rincian
                                                    Kebutuhan</label>
                                            </div>
                                        @endif

                                        <!-- Filter Penerima Manfaat Pengguna Project -->
                                        @if (auth()->user()->role == 'pemerintah' || auth()->user()->role == 'investor')
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input"
                                                    id="filter_penerima_manfaat" name="filters[]"
                                                    value="penerima_manfaat"
                                                    {{ in_array('penerima_manfaat', $selectedFilters) ? 'checked' : '' }}>
                                                <label class="form-check-label" for="filter_penerima_manfaat">Penerima
                                                    Manfaat Pengguna Project</label>
                                            </div>
                                        @endif
                                    </div>
                                </div>


                                <!-- Bidang Filter -->
                                <div class="col-md-12 mb-3" id="bidang_filter">
                                    <label class="form-label">Bidang</label>
                                    <div>
                                        @foreach (['Aplikasi dan permainan', 'Arsitektur', 'Desain', 'Film, video, dan animasi', 'Fotografi', 'Kriya', 'Kuliner', 'Mode', 'Musik', 'Penerbitan', 'Periklanan', 'Permainan rakyat', 'Radio dan televisi', 'Riset dan pengembangan', 'Seni pertunjukan', 'Seni rupa', 'Software'] as $bidang)
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input"
                                                    id="bidang_{{ strtolower(str_replace(' ', '_', $bidang)) }}"
                                                    name="bidang_sub_sektor_ekonomi_kreatif[]"
                                                    value="{{ $bidang }}"
                                                    {{ isset($preferences) && is_array(json_decode($preferences->bidang_sub_sektor_ekonomi_kreatif)) && in_array($bidang, json_decode($preferences->bidang_sub_sektor_ekonomi_kreatif)) ? 'checked' : '' }}>
                                                <label class="form-check-label"
                                                    for="bidang_{{ strtolower(str_replace(' ', '_', $bidang)) }}">{{ $bidang }}</label>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>

                                <div class="col-md-12 mb-3" id="kategori_filter">
                                    <label class="form-label">Kategori</label>
                                    <div>
                                        @if (auth()->user()->role == 'pemerintah')
                                            @foreach (['Pelatihan', 'Pendanaan'] as $kategori)
                                                <div class="form-check">
                                                    <input type="checkbox" class="form-check-input"
                                                        id="kategori_{{ strtolower($kategori) }}" name="kategori[]"
                                                        value="{{ $kategori }}"
                                                        {{ isset($preferences) && is_array(json_decode($preferences->kategori)) && in_array($kategori, json_decode($preferences->kategori)) ? 'checked' : '' }}>
                                                    <label class="form-check-label"
                                                        for="kategori_{{ strtolower($kategori) }}">{{ $kategori }}</label>
                                                </div>
                                            @endforeach
                                        @elseif (in_array(auth()->user()->role, ['investor', 'umkm', 'akademisi', 'komunitas']))
                                            @foreach (['Pelatihan', 'Pendanaan', 'Riset'] as $kategori)
                                                <div class="form-check">
                                                    <input type="checkbox" class="form-check-input"
                                                        id="kategori_{{ strtolower($kategori) }}" name="kategori[]"
                                                        value="{{ $kategori }}"
                                                        {{ isset($preferences) && is_array(json_decode($preferences->kategori)) && in_array($kategori, json_decode($preferences->kategori)) ? 'checked' : '' }}>
                                                    <label class="form-check-label"
                                                        for="kategori_{{ strtolower($kategori) }}">{{ $kategori }}</label>
                                                </div>
                                            @endforeach
                                        @endif
                                    </div>
                                </div>

                                <!-- Filter Batas Terima Tawaran -->
                                {{-- <div class="col-md-12 mb-3" id="batas_terima_tawaran_filter">
                                    <label for="batas_terima_tawaran" class="form-label">Batas Terima Tawaran</label>
                                    <input type="date" id="batas_terima_tawaran" name="batas_terima_tawaran"
                                        value="{{ isset($preferences->batas_terima_tawaran) ? $preferences->batas_terima_tawaran : '' }}"
                                        class="form-control">
                                </div> --}}

                                <!-- Range Filter for Biaya and Jumlah Dana -->

                                <div class="col-md-12 mb-3" id="range_biaya_jumlah_dana_filter">
                                    <label for="range_biaya_jumlah_dana" class="form-label">Range Biaya dan Jumlah
                                        Dana (Min-Max)</label>
                                    <div class="input-group">
                                        <input type="number" step="0.01" id="range_min" name="range_min"
                                            class="form-control" placeholder="Min Value"
                                            value="{{ isset($preferences->range_min) ? $preferences->range_min : '' }}">
                                        <span class="input-group-text">-</span>
                                        <input type="number" step="0.01" id="range_max" name="range_max"
                                            class="form-control" placeholder="Max Value"
                                            value="{{ isset($preferences->range_max) ? $preferences->range_max : '' }}">
                                    </div>
                                </div>


                                <!-- Filter Status -->
                                <div class="col-md-12 mb-3" id="status_filter">
                                    <label class="form-label">Status</label>
                                    <div>
                                        @foreach (['Coming Soon', 'Berjalan', 'Selesai'] as $status)
                                            <div class="form-check">
                                                <input type="checkbox" class="form-check-input"
                                                    id="status_{{ strtolower(str_replace(' ', '_', $status)) }}"
                                                    name="status[]" value="{{ $status }}"
                                                    {{ isset($preferences) && is_array(json_decode($preferences->status)) && in_array($status, json_decode($preferences->status)) ? 'checked' : '' }}>
                                                <label class="form-check-label"
                                                    for="status_{{ strtolower(str_replace(' ', '_', $status)) }}">{{ $status }}</label>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>

                                <!-- Filter Audiens -->
                                <div class="col-md-12 mb-3" id="audiens_filter">
                                    <label class="form-label">Audiens</label>
                                    <textarea id="audiens" name="audiens" class="form-control" placeholder="Masukkan audiens">{{ isset($preferences->audiens) ? $preferences->audiens : '' }}</textarea>
                                </div>

                                <!-- Filter Batas Terima Tawaran -->
                                <div class="col-md-12 mb-3" id="batas_terima_tawaran_filter">
                                    <label for="batas_terima_tawaran" class="form-label">Batas Terima Tawaran</label>
                                    <input type="date" id="batas_terima_tawaran" name="batas_terima_tawaran"
                                        value="{{ isset($preferences->batas_terima_tawaran) ? $preferences->batas_terima_tawaran : '' }}"
                                        class="form-control">
                                </div>



                                <!-- Filter Benefit -->
                                <div class="col-md-12 mb-3" id="benefit_filter">
                                    <label class="form-label">Benefit</label>
                                    <textarea id="benefit" name="benefit" class="form-control" placeholder="Masukkan benefit">{{ isset($preferences->benefit) ? $preferences->benefit : '' }}</textarea>
                                </div>


                                <!-- Filter Durasi -->
                                @if (auth()->user()->role == 'umkm' || auth()->user()->role == 'komunitas')
                                    <div class="col-md-12 mb-3" id="durasi_filter">
                                        <label class="form-label">Durasi</label>
                                        <div>
                                            <input type="number" id="durasi_min" name="durasi_min" class="form-control"
                                                placeholder="Durasi Min (jam)"
                                                value="{{ isset($preferences->durasi_min) ? $preferences->durasi_min : '' }}">
                                            <input type="number" id="durasi_max" name="durasi_max" class="form-control"
                                                placeholder="Durasi Max (jam)"
                                                value="{{ isset($preferences->durasi_max) ? $preferences->durasi_max : '' }}">
                                        </div>
                                    </div>
                                @endif

                                <!-- Filter Lokasi -->
                                <div class="col-md-12 mb-3" id="lokasi_filter">
                                    <label class="form-label">Lokasi</label>
                                    <input type="text" id="lokasi" name="lokasi" class="form-control"
                                        placeholder="Masukkan Lokasi"
                                        value="{{ isset($preferences->lokasi) ? $preferences->lokasi : '' }}">
                                </div>

                                <!-- Filter Metodologi -->
                                <div class="col-md-12 mb-3" id="metodologi_filter">
                                    <label class="form-label">Metodologi</label>
                                    <textarea id="metodologi" name="metodologi" class="form-control" placeholder="Masukkan Metodologi">{{ isset($preferences->metodologi) ? $preferences->metodologi : '' }}</textarea>
                                </div>


                    

                                <!-- Filter Rincian Kebutuhan -->
                                @if (auth()->user()->role == 'pemerintah' || auth()->user()->role == 'investor')
                                    <div class="col-md-12 mb-3" id="rincian_kebutuhan_filter">
                                        <label class="form-label">Rincian Kebutuhan</label>
                                        <textarea id="rincian_kebutuhan" name="rincian_kebutuhan" class="form-control" rows="3"
                                            placeholder="Masukkan Rincian Kebutuhan">{{ isset($preferences->rincian_kebutuhan) ? $preferences->rincian_kebutuhan : '' }}</textarea>
                                    </div>
                                @endif

                                <!-- Filter Penerima Manfaat-->
                                @if (auth()->user()->role == 'pemerintah' || auth()->user()->role == 'investor')
                                    <div class="col-md-12 mb-3" id="penerima_manfaat_filter">
                                        <label class="form-label">Penerima Manfaat</label>
                                        <textarea id="penerima_manfaat" name="penerima_manfaat" class="form-control"
                                            placeholder="Masukkan penerima manfaat">{{ isset($preferences->penerima_manfaat) ? $preferences->penerima_manfaat : '' }}</textarea>
                                    </div>
                                @endif

                                <button type="submit" class="btn btn-primary">Simpan Preferensi</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>


            <script>
                document.addEventListener('DOMContentLoaded', function() {
                    // Ambil semua checkbox filter
                    const checkboxes = document.querySelectorAll('.form-check-input');
                    const filterSections = {
                        filter_bidang: document.getElementById('bidang_filter'),
                        filter_kategori: document.getElementById('kategori_filter'),
                        filter_audiens: document.getElementById('audiens_filter'),
                        filter_batas_terima_tawaran: document.getElementById('batas_terima_tawaran_filter'),
                        filter_range_dana: document.getElementById('range_biaya_jumlah_dana_filter'),
                        filter_status: document.getElementById('status_filter'),
                        filter_benefit: document.getElementById('benefit_filter'),
                        filter_durasi: document.getElementById('durasi_filter'),
                        filter_lokasi: document.getElementById('lokasi_filter'),
                        filter_metodologi: document.getElementById('metodologi_filter'),
                        filter_rincian_kebutuhan: document.getElementById('rincian_kebutuhan_filter'),
                        filter_penerima_manfaat: document.getElementById('penerima_manfaat_filter'),
                    };

                    // Fungsi untuk menampilkan atau menyembunyikan filter berdasarkan checkbox yang dipilih
                    function updateFilters() {
                        for (const checkbox of checkboxes) {
                            const filterId = checkbox.id;
                            const section = filterSections[filterId];
                            if (checkbox.checked) {
                                section.style.display = 'block'; // Tampilkan filter
                            } else {
                                section.style.display = 'none'; // Sembunyikan filter
                            }
                        }
                    }

                    // Tambahkan event listener untuk setiap checkbox
                    checkboxes.forEach(checkbox => {
                        checkbox.addEventListener('change', updateFilters);
                    });

                    // Panggil fungsi untuk mengatur tampilan filter saat halaman dimuat
                    updateFilters();
                });
            </script>

            {{-- <script>
                document.addEventListener('DOMContentLoaded', function() {
                    // Ambil semua checkbox filter
                    const checkboxes = document.querySelectorAll('.form-check-input');
                    const filterSections = {
                        filter_bidang: document.getElementById('bidang_filter'),
                        filter_kategori: document.getElementById('kategori_filter'),
                        filter_audiens: document.getElementById('audiens_filter'),
                        filter_batas_terima_tawaran: document.getElementById('batas_terima_tawaran_filter'),
                        filter_range_dana: document.getElementById('range_biaya_jumlah_dana_filter'),
                        filter_status: document.getElementById('status_filter'),
                        filter_benefit: document.getElementById('benefit_filter'),
                        filter_durasi: document.getElementById('durasi_filter'),
                        filter_lokasi: document.getElementById('lokasi_filter'),
                        filter_metodologi: document.getElementById('metodologi_filter'),
                        filter_rincian_kebutuhan: document.getElementById('rincian_kebutuhan_filter'),
                        filter_penerima_manfaat: document.getElementById('penerima_manfaat_filter'),
                    };

                    // Fungsi untuk menampilkan atau menyembunyikan filter berdasarkan checkbox yang dipilih
                    function updateFilters() {
                        for (const checkbox of checkboxes) {
                            const filterId = checkbox.id;
                            const section = filterSections[filterId];

                            // Tampilkan filter jika checkbox dicentang atau jika section sudah ditampilkan sebelumnya
                            if (checkbox.checked || section.style.display === 'block') {
                                section.style.display = 'block'; // Tampilkan filter
                            } else {
                                section.style.display = 'none'; // Sembunyikan filter
                            }
                        }
                    }

                    // Restore status checkbox dari localStorage saat halaman dimuat
                    checkboxes.forEach(checkbox => {
                        const storedValue = localStorage.getItem(checkbox.id);
                        if (storedValue === 'true') {
                            checkbox.checked = true; // Set checkbox sebagai dicentang
                        }
                    });

                    // Tambahkan event listener untuk setiap checkbox
                    checkboxes.forEach(checkbox => {
                        checkbox.addEventListener('change', function() {
                            // Simpan status checkbox ke localStorage saat berubah
                            localStorage.setItem(checkbox.id, checkbox.checked);
                            updateFilters();
                        });
                    });

                    // Panggil fungsi untuk mengatur tampilan filter saat halaman dimuat
                    updateFilters(); // Memastikan filter yang dicentang tetap terlihat saat halaman dimuat
                });
            </script> --}}



        </div>
    @endsection
