@extends('layouts.master')

@section('page-css')
<link rel="stylesheet" media="screen, print" href="{{asset('assets/css/datagrid/datatables/datatables.bundle.css')}}">
@endsection
@section('content')
<div class="row">
    <div class="col-12 mb-3">
        <div class="d-flex flex-row justify-content-between">
            <div class="d-flex align-items-center">
                <div class="subheader mb-0">
                    <h1 class="subheader-title">
                        {{$title}}
                    </h1>
                </div>
            </div>
            <div class="align-items-end">
                <div class="card">
                    <div class="card-body p-2">
                        <div class="d-flex flex-row gap-3 justify-content-center align-items-center">
                            <div class="p-2 bg-secondary rounded">
                                <i class="fal fa-home"></i>
                            </div>
                            <div>
                                <h5 class="fw-700 mb-1">{{$nama_sekolah}}</h5>
                                <p class="mb-0">NPSN: {{$npsn}}</p>
                            </div>
                            <div class="d-flex flex-column gap-1">
                                <span class="badge bg-primary-light text-primary">{{$tingkat}}</span>
                                <span class="badge bg-success-light text-success">{{$status}}</span>
                                <span class="badge bg-info-light text-info">Level {{levelAdiwiyata($npsn)}}</span>
                            </div>
                        </div>  
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-12">
        @if ($errors->any())
            <div class="alert alert-danger">
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
        @if((session('group_alias') == 'dinas') || (session('group_alias') == 'suku_dinas'))
            <div class="card mb-2 bg-primary-light text-primary">
                <div class="card-body">
                    <h4 class="fw-500"><i class="fal fa-info-circle"></i>&nbsp;Verifikasi Kuesioner Leveling</h4>
                    <p>Sebelum melakukan verifikasi kuesioner leveling, silakan lakukan pengecekan validitas data terlebih dahulu untuk memastikan seluruh isian telah sesuai dan lengkap.</p>
                    <div class="d-flex gap-2">
                        @if(@$dok)
                            @if(@$dok->status == 0)
                                @if($kuesioner->tahun == date('Y'))
                                    <a href="#" data-href="{{url('usulan/adiwiyata/administrasi/verifikasi/'.encode_id($dok->DokumenAdministrasiId))}}" data-toggle="tooltip" title="Verifikasi Data" class="btn bg-success verifikasi text-white"><i class="fal fa-check"></i> Verifikasi</a>
                                    <a href="#" data-href="{{url('usulan/adiwiyata/administrasi/tolak/'.encode_id($dok->DokumenAdministrasiId))}}" data-toggle="tooltip" title="Tolak Verifikasi Data" class="btn bg-danger tolak text-white"><i class="fal fa-times"></i> Tolak Verifikasi</a>
                                @endif
                            @endif
                        @else
                            @if($kuesioner->tahun == date('Y'))
                                <a href="#" data-href="{{url('usulan/adiwiyata/administrasi/tolak_kosong/'.encode_id($kuesioner->KuesionerId))}}" data-toggle="tooltip" title="Tolak Verifikasi Data" class="btn bg-danger text-white tolak"><i class="fal fa-times text-white"></i> Tolak Verifikasi</a>
                            @endif
                        @endif
                    </div>
                </div>
            </div>
        @elseif (session('group_alias') == 'sekolah')
            @if(@$dok->status == 0)
                <div class="card mb-2 bg-primary-light text-primary">
                    <div class="card-body">
                        <h4 class="fw-500"><i class="fal fa-info-circle"></i>&nbsp;Verifikasi Kuesioner Leveling</h4>
                        <p class="mb-0">Kuesioner anda sedang dilakukan verifikasi oleh sudin/dinas terkait. Mohon Menunggu...</p>
                    </div>
                </div>
            @elseif(@$dok->status == 1)
                @if($kuesioner->status >= 3)
                    <div class="card mb-2 bg-primary-light text-primary">
                        <div class="card-body">
                            <h4 class="fw-500"><i class="fal fa-info-circle"></i>&nbsp;Pemenuhan Kriteria</h4>
                            <p class="mb-0">Pemenuhan Kriteria Sedang Dilakukan Verifikasi Oleh Pihak Penilai.</p>
                        </div>
                    </div>
                @else
                    <div class="card mb-2 bg-success-light text-success">
                        <div class="card-body">
                            <h4 class="fw-500"><i class="fal fa-info-circle"></i>&nbsp;Verifikasi Kuesioner Leveling</h4>
                            <p>Kuesioner Anda telah di-approve dan dinyatakan valid. Silakan melanjutkan ke tahapan berikutnya.</p>
                            <a href="{{ url('usulan/adiwiyata/kriteria') }}" class="btn btn-info">Pemenuhan Kriteria &nbsp; <i class="fal fa-arrow-right"></i></a>
                        </div>
                    </div>
                @endif
            @elseif(@$dok->status == 2)
                <?php
                    if(($kuesioner->level+1) == 1){
                        $jenis_usulan = 'Keputusan Gubernur tentang penetapan Sekolah Adiwiyata Kab/Kota';
                    }elseif(($kuesioner->level+1) == 2){
                        $jenis_usulan = 'Keputusan Gubernur tentang penetapan Sekolah Adiwiyata Provinsi';
                    }elseif(($kuesioner->level+1) == 3){
                        $jenis_usulan = 'Keputusan Gubernur tentang penetapan Sekolah Adiwiyata Nasional';
                    }elseif(($kuesioner->level+1) == 4){
                        $jenis_usulan = 'Keputusan Gubernur tentang penetapan Sekolah Adiwiyata Mandiri';
                    }
                ?>
                <div class="card mb-2 bg-danger-light text-white">
                    <div class="card-body">
                        <h4 class="fw-500"><i class="fal fa-info-circle"></i>&nbsp;Verifikasi Kuesioner Leveling</h4>
                        <p>Kuesioner Anda belum lolos verifikasi dan dinyatakan ditolak. Silakan periksa kembali isian kuesioner dan lakukan perbaikan.</p>
                        <a href="#" data-filetim="{{@$dok->file_sk_tim}}" data-fileusulan="{{@$dok->file_usulan}}" data-link="{{@$dok->link}}" data-level="{{$kuesioner->level}}" data-secureid="{{encode_id($kuesioner->KuesionerId)}}" data-toggle="modal" data-target="#modal" title="View Data" data-jenisusulan="{{$jenis_usulan}}" class="btn btn-primary btnModal">Perbaikan Data &nbsp; <i class="fal fa-pencil text-white"></i></a>
                    </div>
                </div>
            @else
            @endif
        @endif
        <form method="POST" action="{{route($route.'.store')}}" id="form" enctype="multipart/form-data">
            {{csrf_field()}}
            <div class="card">
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="fw-500 mb-3">Apakah Sekolah anda sudah pernah mendapatkan penghargaan adiwiyata? </label>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="custom-control custom-radio">
                                            <input type="radio" class="custom-control-input radioPenghargaan" value="0" {{@$kuesioner->level == 0 ? 'checked' : ''}} id="radioPenghargaanAdiwiyataBelum" required name="level">
                                            <label class="custom-control-label" for="radioPenghargaanAdiwiyataBelum">Belum</label>
                                        </div>
                                        <div class="custom-control custom-radio mt-2">
                                            <input type="radio" class="custom-control-input radioPenghargaan" value="1" {{@$kuesioner->level == 1 ? 'checked' : ''}} id="radioPenghargaanAdiwiyataKota" required name="level">
                                            <label class="custom-control-label" for="radioPenghargaanAdiwiyataKota">Adiwiyata Kab/Kota</label>
                                        </div>
                                        <div class="custom-control custom-radio mt-2">
                                            <input type="radio" class="custom-control-input radioPenghargaan" value="2" {{@$kuesioner->level == 2 ? 'checked' : ''}} id="radioPenghargaanAdiwiyataProvinsi" required name="level">
                                            <label class="custom-control-label" for="radioPenghargaanAdiwiyataProvinsi">Adiwiyata Provinsi</label>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="custom-control custom-radio mt-2">
                                            <input type="radio" class="custom-control-input radioPenghargaan" value="3" {{@$kuesioner->level == 3 ? 'checked' : ''}} id="radioPenghargaanAdiwiyataNasional" required name="level">
                                            <label class="custom-control-label" for="radioPenghargaanAdiwiyataNasional">Adiwiyata Nasional</label>
                                        </div>
                                        <div class="custom-control custom-radio mt-2">
                                            <input type="radio" class="custom-control-input radioPenghargaan" value="4" {{@$kuesioner->level == 4 ? 'checked' : ''}} id="radioPenghargaanAdiwiyataMandiri" required name="level">
                                            <label class="custom-control-label" for="radioPenghargaanAdiwiyataMandiri">Adiwiyata Mandiri</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group belumPernah {{@$kuesioner->level == 0 ? '' : 'd-none'}}">
                                <label class="fw-500 mb-3">Apakah sekolah anda sudah pernah mendapatkan informasi tentang Gerakan Peduli dan Berbudaya Lingkungan Hidup di Sekolah (GPBLHS) </label>
                                <div class="form-group">
                                    <div class="custom-control custom-radio">
                                        <input type="radio" class="custom-control-input info_pblhs" id="radioGerakanPeduliBelum" value="1" {{@$kuesioner->info_pblhs == '1' ? 'checked' : ''}} name="info_pblhs">
                                        <label class="custom-control-label" for="radioGerakanPeduliBelum">Belum Pernah</label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="custom-control custom-radio mt-2">
                                        <input type="radio" class="custom-control-input info_pblhs" id="radioGerakanPeduliSudah" value="2" {{@$kuesioner->info_pblhs == '2' ? 'checked' : ''}} name="info_pblhs">
                                        <label class="custom-control-label" for="radioGerakanPeduliSudah">Sudah Pernah</label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group belumPernah {{@$kuesioner->level == 0 ? '' : 'd-none'}}">
                                <label class="fw-500 mb-3">Apakah sekolah anda sudah membentuk Tim Adiwiyata Sekolah?</label>
                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-radio">
                                                <input type="radio" class="custom-control-input" id="radioTimAdiwiyataBelum" value="1" {{@$kuesioner->tim_adiwiyata == 1 ? 'checked' : '' }} name="tim_adiwiyata">
                                                <label class="custom-control-label" for="radioTimAdiwiyataBelum">Belum</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input class="form-control" disabled value="" placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-radio">
                                                <input type="radio" class="custom-control-input" id="radioTimAdiwiyataSudah" value="2" {{@$kuesioner->tim_adiwiyata == 2 ? 'checked' : '' }} name="tim_adiwiyata">
                                                <label class="custom-control-label" for="radioTimAdiwiyataSudah">Sudah</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input class="form-control" name="tim_adiwiyata_nomor_sk" value="{{@$kuesioner->tim_adiwiyata_nomor_sk}}" placeholder="Masukkan nomor SK Tim Adiwiyata" type="text">
                                        <input class="form-control" name="tim_adiwiyata_link" placeholder="Masukkan link Google Drive SK Tim Adiwiyata" type="file" accept=".pdf">
                                    </div>
                                    @if(@$kuesioner->tim_adiwiyata_link)
                                        <a href="{{asset('uploads/'.@$kuesioner->tim_adiwiyata_link)}}" class="btn btn-primary mt-2"><i class="fal fa-download"></i>&nbsp;File SK Tim Adiwiyata</a>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group belumPernah {{@$kuesioner->level == 0 ? '' : 'd-none'}}">
                                <label class="fw-500 mb-3">Jika pernah, dari media apa mendapatkannya, dan sebutkan nama instansi penyelenggaranya ?</label>
                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input media" name="media[]" value="1" {{ in_array(1, @$selectedMediaValues) ? 'checked' : '' }} id="checkSosialisasi">
                                                <label class="custom-control-label" for="checkSosialisasi">Sosialisasi</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="media_text[sosialisasi]" value="{{ @$selectedMediaTexts['sosialisasi']->text ?? '' }}" class="form-control media" placeholder="Tulis Instansi Penyelenggara">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input media" name="media[]" value="2" {{ in_array(2, @$selectedMediaValues) ? 'checked' : '' }} id="checkBimtek">
                                                <label class="custom-control-label" for="checkBimtek">Bimtek</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="media_text[bimtek]" value="{{ @$selectedMediaTexts['bimtek']->text ?? '' }}" class="form-control media" placeholder="Tulis Instansi Penyelenggara">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input media" name="media[]" value="3" {{ in_array(3, @$selectedMediaValues) ? 'checked' : '' }} id="checkWebinar">
                                                <label class="custom-control-label" for="checkWebinar">Webinar</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="media_text[webinar]" value="{{ @$selectedMediaTexts['webinar']->text ?? '' }}" class="form-control media" placeholder="Tulis Instansi Penyelenggara">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input media" name="media[]" value="4" {{ in_array(4, @$selectedMediaValues) ? 'checked' : '' }} id="checkYoutube">
                                                <label class="custom-control-label" for="checkYoutube">Youtube</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="media_text[youtube]" value="{{ @$selectedMediaTexts['youtube']->text ?? '' }}" class="form-control media" placeholder="Tulis Instansi Penyelenggara">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input media" name="media[]" value="5" {{ in_array(5, @$selectedMediaValues) ? 'checked' : '' }} id="checkLain">
                                                <label class="custom-control-label" for="checkLain">Lain-lain</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="media_text[lainlain]" value="{{ @$selectedMediaTexts['lainlain']->text ?? '' }}" class="form-control media" placeholder="Tulis Instansi Penyelenggara">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group belumPernah {{@$kuesioner->level == 0 ? '' : 'd-none'}}">
                                <label class="fw-500 mb-3">Materi apa saja yang masih kurang Anda pahami?</label>
                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input materi" name="materi[]" value="1" {{ in_array(1, @$selectedMateriValues) ? 'checked' : '' }} id="checkMateriKebijakan">
                                                <label class="custom-control-label" for="checkMateriKebijakan">Kebijakan Gerakan PBLHS</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="materi_text[kebijakan]" value="{{ @$selectedMateriTexts['kebijakan']->text ?? '' }}" class="form-control materi" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input materi" name="materi[]" value="2" {{ in_array(2, @$selectedMateriValues) ? 'checked' : '' }} id="checkMateriPerencanaan">
                                                <label class="custom-control-label" for="checkMateriPerencanaan">Perencanaan Gerakan PBLHS</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="materi_text[perencanaan]" value="{{ @$selectedMateriTexts['perencanaan']->text ?? '' }}" class="form-control materi" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input materi" name="materi[]" value="3" {{ in_array(3, @$selectedMateriValues) ? 'checked' : '' }} id="checkMateriPelaksanaan">
                                                <label class="custom-control-label" for="checkMateriPelaksanaan">Pelaksanaan Gerakan PBLHS</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="materi_text[pelaksanaan]" value="{{ @$selectedMateriTexts['pelaksanaan']->text ?? '' }}" class="form-control materi" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input materi" name="materi[]" value="4" {{ in_array(4, @$selectedMateriValues) ? 'checked' : '' }} id="checkMateriPemantauan">
                                                <label class="custom-control-label" for="checkMateriPemantauan">Pemantauan dan Evaluasi Gerakan PBLHS</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="materi_text[pemantauan]" value="{{ @$selectedMateriTexts['pemantauan']->text ?? '' }}" class="form-control materi" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input materi" name="materi[]" value="5" {{ in_array(5, @$selectedMateriValues) ? 'checked' : '' }} id="checkMateriLain">
                                                <label class="custom-control-label" for="checkMateriLain">Lain-lain</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="materi_text[lainlain]" value="{{ @$selectedMateriTexts['lainlain']->text ?? '' }}" class="form-control materi" placeholder="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group belumPernah {{@$kuesioner->level == 0 ? '' : 'd-none'}}">
                                <label class="fw-500 mb-3">Apakah sekolah anda bersedia untuk berkomitmen melaksanakan Gerakan PBLHS secara berkelanjutan? </label>
                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-radio">
                                                <input type="radio" class="custom-control-input" id="radioKomitmenBersedia" value="1" {{ in_array(1, @$selectedKomitmenValues) ? 'checked' : '' }} name="komitmen">
                                                <label class="custom-control-label" for="radioKomitmenBersedia">Bersedia</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="komitmen_text[bersedia]" value="{{ @$selectedKomitmenTexts['bersedia']->text ?? '' }}" disabled class="form-control" placeholder="">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-radio">
                                                <input type="radio" class="custom-control-input" id="radioKomitmenTidakBersedia" value="2" {{ in_array(2, @$selectedKomitmenValues) ? 'checked' : '' }} name="komitmen">
                                                <label class="custom-control-label" for="radioKomitmenTidakBersedia">Tidak Bersedia</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="komitmen_text[tidak_bersedia]" value="{{ @$selectedKomitmenTexts['tidak_bersedia']->text ?? '' }}" class="form-control" placeholder="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group belumPernah {{@$kuesioner->level == 0 ? '' : 'd-none'}}">
                                <label class="fw-500 mb-3">Kegiatan/aksi lingkungan yang pernah dilakukan oleh warga sekolah?</label>
                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="checkPemilahanSampah" value="1" {{ in_array(1, @$selectedKegiatanLingkunganValues) ? 'checked' : '' }} name="kegiatan_lingkungan[]">
                                                <label class="custom-control-label" for="checkPemilahanSampah">Pemilahan Sampah</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="kegiatan_lingkungan_text[pemilahan_sampah]" value="{{ @$selectedKegiatanLingkunganTexts['pemilahan_sampah']->text ?? '' }}" disabled class="form-control" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="checkPenanamanPohon" value="2" {{ in_array(2, @$selectedKegiatanLingkunganValues) ? 'checked' : '' }} name="kegiatan_lingkungan[]">
                                                <label class="custom-control-label" for="checkPenanamanPohon">Penanaman Pohon</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="kegiatan_lingkungan_text[penanaman_pohon]" value="{{ @$selectedKegiatanLingkunganTexts['penanaman_pohon']->text ?? '' }}" disabled class="form-control" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="checkKegiatan1" value="3" {{ in_array(3, @$selectedKegiatanLingkunganValues) ? 'checked' : '' }} name="kegiatan_lingkungan[]">
                                                <label class="custom-control-label" for="checkKegiatan1">Kegiatan/aksi lainnya</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="kegiatan_lingkungan_text[kegiatan_1]" value="{{ @$selectedKegiatanLingkunganTexts['kegiatan_1']->text ?? '' }}" class="form-control" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="checkKegiatan2" value="4" {{ in_array(4, @$selectedKegiatanLingkunganValues) ? 'checked' : '' }} name="kegiatan_lingkungan[]">
                                                <label class="custom-control-label" for="checkKegiatan2">Kegiatan/aksi lainnya</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="kegiatan_lingkungan_text[kegiatan_2]" value="{{ @$selectedKegiatanLingkunganTexts['kegiatan_2']->text ?? '' }}" class="form-control" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="checkKegiatan3" value="5" {{ in_array(5, @$selectedKegiatanLingkunganValues) ? 'checked' : '' }} name="kegiatan_lingkungan[]">
                                                <label class="custom-control-label" for="checkKegiatan3">Kegiatan/aksi lainnya</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="kegiatan_lingkungan_text[kegiatan_3]" value="{{ @$selectedKegiatanLingkunganTexts['kegiatan_3']->text ?? '' }}" class="form-control" placeholder="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group belumPernah {{@$kuesioner->level == 0 ? '' : 'd-none'}}">
                                <label class="fw-500 mb-3">Pihak yang terlibat dalam menjalankan kegiatan/aksi lingkungan </label>
                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="checkInternalWarga" value="1" {{ in_array(1, @$selectedPihakKegiatanLingkunganValues) ? 'checked' : '' }} name="pihak_kegiatan_lingkungan[]">
                                                <label class="custom-control-label" for="checkInternalWarga">Internal warga sekolah</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="pihak_kegiatan_lingkungan_text[internal]" value="{{ @$selectedPihakKegiatanLingkunganTexts['internal']->text ?? '' }}" disabled disabled class="form-control" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                          <div class="input-group-text">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="checkBekerjasama" value="2" {{ in_array(2, @$selectedPihakKegiatanLingkunganValues) ? 'checked' : '' }} name="pihak_kegiatan_lingkungan[]">
                                                <label class="custom-control-label" for="checkBekerjasama">Bekerjasama dengan Pihak Lainnya</label>
                                            </div>
                                          </div>
                                        </div>
                                        <input type="text" name="pihak_kegiatan_lingkungan_text[eksternal]" value="{{ @$selectedPihakKegiatanLingkunganTexts['eksternal']->text ?? '' }}" class="form-control" placeholder="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group sudahPernah {{@$kuesioner->level != 0 ? '' : 'd-none'}}">
                                <label class="fw-500 mb-3">Jika sudah pernah mendapatkan penghargaan adiwiyata, tahun berapa sekolah anda mendapatkan penghargaan adiwiyata?</label>
                                <div class="form-group">
                                    <label class="fw-500 mb-3">Tahun perolehan penghargaaan (kosongkan jika belum adiwiyata)</label>
                                    <select class="form-control form-control-sm tahun_penghargaan" name="tahun_penghargaan">
                                        <option value="">Pilih Tahun</option>
                                        @for($i = (date('Y')-5); $i <= (date('Y')); $i++)
                                        <option {{@$kuesioner->tahun_penghargaan == $i ? 'selected' : ''}} value="{{$i}}">{{$i}}</option>
                                        @endfor
                                    </select>
                                </div>
                                <div class="form-group">
                                        @if(@$kuesioner->link_sk_adiwiyata)
                                            <div class="form-group">
                                                <label class="fw-500 mb-3">Upload File SK adiwiyata / perpanjangan (kosongkan jika belum mendapat adiwiyata)</label>
                                                <div class="input-group">
                                                    <div class="input-group-prepend">
                                                        <div class="input-group-text bg-primary border-none">
                                                            <a class="text-white" href="{{asset('uploads/'.@$kuesioner->link_sk_adiwiyata)}}">Download File</a>
                                                        </div>
                                                    </div>
                                                    <input type="file" accept=".pdf value="{{@$kuesioner->link_sk_adiwiyata}}" class="form-control form-control-sm link_sk_adiwiyata" name="link_sk_adiwiyata" placeholder="Link SK adiwiyata / perpanjangan (kosongkan jika belum mendapat adiwiyata)">
                                                </div>
                                            </div>
                                        @else
                                            <div class="form-group">
                                                <label class="fw-500 mb-3">Upload File SK adiwiyata / perpanjangan (kosongkan jika belum mendapat adiwiyata)</label>
                                                <input type="file" value="{{@$kuesioner->link_sk_adiwiyata}}" class="form-control form-control-sm link_sk_adiwiyata" name="link_sk_adiwiyata" placeholder="Link SK adiwiyata / perpanjangan (kosongkan jika belum mendapat adiwiyata)">
                                            </div>
                                        @endif
                                        
                                    
                                    
                                </div>
                            </div>

                            <div class="form-group belumPernah {{@$kuesioner->level == 0 ? '' : 'd-none'}}">
                                @if(@$dok->file_usulan)
                                    <div class="form-group">
                                        <label class="fw-500 mb-3">Upload File Usulan Sekolah Adiwiyata</label>
                                        <div class="input-group">
                                            <div class="input-group-prepend">
                                                <div class="input-group-text">
                                                    <a href="{{asset('uploads/'.@$dok->file_usulan)}}">Download File</a>
                                                </div>
                                            </div>
                                            <input type="file" accept=".pdf" class="form-control" name="file_usulan">
                                        </div>
                                    </div>
                                @else
                                    <div class="form-group">
                                        <label class="fw-500 mb-3">Upload File Usulan Sekolah Adiwiyata</label>
                                        <input type="file" class="form-control form-control-sm" name="file_usulan">
                                    </div>
                                @endif
                            </div>
                            @if(!@$kuesioner)
                            <div class="form-group">
                                <button class="btn btn-success" id="btn-save"><i class="fal fa-save"></i>&nbsp;Simpan</button>
                            </div>
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
        <form action="#" method="POST" enctype="multipart/form-data" id="formAdmin" style="width: 100%;">
            {{csrf_field()}}
            <input type="hidden" name="secure_id" class="secure_id" value="">
            <div class="modal-content">
                <div class="modal-header">
                    <h5><b>Perbaikan Data {{$title}}</b></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true"><i class="fal fa-times"></i></span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="alert bg-primary-light text-primary mb-2">
                        <p class="mb-0"><i>Silahkan Upload Kembali File, Untuk Update Data</i></p>
                    </div>
                    <div class="bodyModal"></div>
                </div>
                @if(session('group_alias') == 'sekolah')
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary" id="btnSave">Simpan</button>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
                </div>
                @endif
            </div>
        </form>
    </div>
</div>


@endsection
@section('page-js')
<script type="text/javascript">
    $('.radioPenghargaan').on('change',function(){
        var value = $(this).val();
        if(value == 0){
            $('.belumPernah').removeClass('d-none');
            $('.sudahPernah').addClass('d-none');
        }else{
            $('.belumPernah').addClass('d-none');
            $('.sudahPernah').removeClass('d-none');
        }
    });

    $('.info_pblhs').on('change',function(){
        if($(this).val() == 1){
            $('.media').attr('disabled',true);
            $('.materi').attr('disabled',true);
        }else{
            $('.media').removeAttr('disabled');
            $('.materi').removeAttr('disabled');
        }
    });

    $('#btn-save').on('click',function(e){
        e.preventDefault();

        let isValid = true;

        let level = $('input[name="level"]:checked').val();
        let tim_adiwiyata = $('input[name="tim_adiwiyata"]:checked').val();

        if(level >= 0){
            if(level == 0){
                if((tim_adiwiyata >= 1)){

                    if(tim_adiwiyata == 2){
                        if(($('input[name="tim_adiwiyata_nomor_sk"').val() == '') || ($('input[name="tim_adiwiyata_link"]').val() == '')){
                            toastr.error("Nomor SK dan Upload File Tim Adiwiyata Belum Diisi ", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});    
                        }
                    }

                    if(($('input[name="file_usulan"').val() == '')){
                        toastr.error("File Usulan Sekolah Adiwiyata Belum Di Upload ", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});    
                    }

                   if (
                        $('input[name="info_pblhs"]:checked').length > 0 &&  // Radio button
                        // $('input[name="media[]"]:checked').length > 0 &&     // Checkbox
                        // $('input[name="materi[]"]:checked').length > 0 &&
                        $('input[name="komitmen"]:checked').length > 0 &&
                        $('input[name="kegiatan_lingkungan[]"]:checked').length > 0 &&
                        $('input[name="pihak_kegiatan_lingkungan[]"]:checked').length > 0
                    ) {
                        toastr.success("Data Sudah Lengkap", 'Sukses!', {
                            positionClass: 'toast-bottom-right',
                            containerId: 'toast-bottom-right'
                        });    

                        $('#form').submit();
                    } else {
                        toastr.error("Data Belum Lengkap", 'Error!', {
                            positionClass: 'toast-bottom-right',
                            containerId: 'toast-bottom-right'
                        });                        
                    }


                }else{
                    toastr.error("Data Belum Lengkap ", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});    
                }
        }else{
            let tahun = $('.tahun_penghargaan').find(':selected').val();
            let link_sk_adiwiyata = $('.link_sk_adiwiyata').val();
            if((tahun == '') || (link_sk_adiwiyata == '')){
                toastr.error("Data Belum Lengkap", 'Error!', {
                    positionClass: 'toast-bottom-right',
                    containerId: 'toast-bottom-right'
                });
            }else{
                toastr.success("Data Sudah Lengkap", 'Sukses!', {
                    positionClass: 'toast-bottom-right',
                    containerId: 'toast-bottom-right'
                });    

                $('#form').submit();
            }
        }
            
        }else{
            toastr.error("Penghargaan adiwiyata Belum Diisi ", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
        }

        $('input[required], select[required], textarea[required]').each(function () {
            if ($(this).val().trim() === '') {
                isValid = false;
                $(this).css('border', '2px solid red'); // Tandai input yang kosong
            } else {
                $(this).css('border', ''); // Kembalikan ke border default
            }
        });

    });

    $(".tolak").on("click", function() {
        var base_url = $(this).attr('data-href');
        var id = $(this).attr('data-id');
        swal({
             title: "Tolak Dokumen!",
             text: "Apa anda yakin ingin tolak Dokumen ini ?",
             type: "warning",
             showCancelButton: true,
             confirmButtonColor: "#BF3131",
             confirmButtonText: "Tolak Sekarang",
             cancelButtonText: "Batal",
             closeOnConfirm: true,
             closeOnCancel: true
         },
         function(isConfirm) {
            if(isConfirm){
              
              request = $.ajax({
                  url: base_url,
                  xhrFields: {
                        withCredentials: true
                    },
                  type: "GET",
              });

              // Callback handler that will be called on success
              request.done(function(response, textStatus, jqXHR){
                  console.log(response);
                  toastr.success("Berhasil Update Data", 'Berhasil!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
                  window.location.href = '{{url("/kuesioner")}}';
                  history.pushState(null, null, location.href);
                  window.onpopstate = function () {
                      history.go(1);
                  };
              });

              // Callback handler that will be called on failure
              request.fail(function (jqXHR, textStatus, errorThrown){
                  toastr.error(
                      "Gagal "+textStatus, errorThrown
                  );
              });
            }
         }); 
        return false;
    });
    $(".verifikasi").on("click", function() {
        var base_url = $(this).attr('data-href');
        var id = $(this).attr('data-id');
        swal({
             title: "Verifikasi Dokumen!",
             text: "Apa anda yakin ingin verifikasi Dokumen ini ?",
             type: "warning",
             showCancelButton: true,
             confirmButtonColor: "#3F7D58",
             confirmButtonText: "Approve Sekarang",
             cancelButtonText: "Batal",
             closeOnConfirm: true,
             closeOnCancel: true
         },
         function(isConfirm) {
            if(isConfirm){
              
              request = $.ajax({
                  url: base_url,
                  xhrFields: {
                        withCredentials: true
                    },
                  type: "GET",
              });

              // Callback handler that will be called on success
              request.done(function(response, textStatus, jqXHR){
                  console.log(response);
                  toastr.success("Berhasil Update Data", 'Berhasil!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
                  window.location.href = '{{url("/kuesioner")}}';
                  history.pushState(null, null, location.href);
                  window.onpopstate = function () {
                      history.go(1);
                  };
              });

              // Callback handler that will be called on failure
              request.fail(function (jqXHR, textStatus, errorThrown){
                  toastr.error(
                      "Gagal "+textStatus, errorThrown
                  );
              });
            }
         }); 
        return false;
    });

    $('.btnModal').on('click', function(e) {
        $('.jenisusulan').html($(this).attr('data-jenisusulan'));
        $('.secure_id').val($(this).attr('data-secureid'));
        var assetURL = '{{asset("uploads")}}';
        var link = $(this).attr('data-link');
        var level = $(this).attr('data-level');
        var filetim = $(this).attr('data-filetim');
        var fileusulan = $(this).attr('data-fileusulan');
        var div = '';
        div += '<table class="table deleted table-nobordered wrap">';
            if(level == 0){
                div += '<tr>';
                    div += '<td width="20%">';
                        div += '<div>SK Tim Adiwiyata</div>';
                    div += '</td>';
                    div += '<td>';
                        div += '<input type="file" accept=".pdf" class="form-control is-required" name="sk_tim_adiwiyata">';
                        if(filetim != ''){
                            div += '<br><a href="'+assetURL+'/'+filetim+'" class="btn btn-sm btn-warning"><i class="fal fa-download  "></i> File SK Tim Adiwiyata</a> <br>';    
                        }
                        div += '<small class="text-danger">Format : .pdf, Maksimal File : 2MB</small>';
                    div += '</td>';
                div += '</tr>';
                div += '<tr>';
                    div += '<td width="20%">';
                        div += '<div>Surat Usulan</div>';
                    div += '</td>';
                    div += '<td>';
                        div += '<input type="file" accept=".pdf" class="form-control is-required" name="surat_usulan">';
                         if(fileusulan != ''){
                            div += '<br><a href="'+assetURL+'/'+fileusulan+'" class="btn btn-sm btn-warning"><i class="fal fa-download   "></i> File Usulan</a> <br>';    
                        }
                        div += '<small class="text-danger">Format : .pdf, Maksimal File : 2MB</small>';
                    div += '</td>';
                div += '</tr>';
            }else{
                div += '<tr>';
                    div += '<td width="50%">';
                        div += '<div>'+$(this).attr('data-jenisusulan')+'</div>';
                    div += '</td>';
                    div += '<td>';
                        div += '<input type="file" accept=".pdf" class="form-control is-required" name="file">';
                        div += '<small class="text-danger">Format : .pdf, Maksimal File : 2MB</small>';
                    div += '</td>';
                div += '</tr>';
            }
            div += '</table>';

            $('.bodyModal').html(div);


        if(link != ''){
            $('.link').show();
            $('.link').attr('href',link);
        }else{
            $('.link').hide();
            $('.link').attr('href','');
        }
    });

    $('#btnSave').on('click',function(e){
        e.preventDefault();
        let form = $('#formAdmin')[0];
        let formData = new FormData(form); 
        let isValid = true; // Flag validasi

        // Validasi manual field required
        $('.is-required').each(function () {
            let value = $(this).val()?.trim();
            if (!value) {
                isValid = false;
                $(this).addClass("is-invalid");
            } else {
                $(this).removeClass("is-invalid");
            }
        });

        if (!isValid) {
            toastr.error("Harap isi semua field yang wajib diisi", 'Error!', { positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right' });
            return;
        }

        $.ajax({
            url: "{{route('modules.usulan_adiwiyata.administrasi.store')}}", // Ganti dengan URL API-mu
            type: 'POST', // Bisa juga 'POST' kalau perlu
            xhrFields: {
                withCredentials: true
            },
            data: formData,
            processData: false, // Penting untuk FormData
            contentType: false, // Penting untuk FormData
            dataType: 'json', // Format respons JSON
            beforeSend: function () {
                $('#loading-spinner').show(); // Menampilkan spinner
            },
            success: function (response) {
                if(response.status == true){
                    toastr.success("Berhasil menyimpan data", 'Success!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
                }else{
                    toastr.warning(response.message, {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
                }
                location.reload();
            },
            error: function (xhr, status, error) {
                toastr.error("Maaf Terjadi Kesalahan Menyimpan Data", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
            },
            complete: function () {
                $('#loading-spinner').hide(); // Sembunyikan spinner setelah request selesai
            }
        });
    });
</script>
@endsection