<?php 
    $i = 0;
    $pegawai_link = ''; 
    ?>
    <div class="row">
@foreach($permohonan->ulasanIk as $ulasan)
    <?php 
    $i++;
    $last_periksa_id = $ulasan->id;
    ?> 
        <div class="col-md-6 col-sm-12">
          <div class="card card-round">
            <div class="card-body">
                <div class="row">
                    <div class="col-12">
                        <a href="{{route('admin.papar-pemeriksaan-lepas', ['id'=>$mohon_id, 'borang_ik_id'=>$ulasan->id])}}" class="btn btn-secondary mt-2">Lawatan {{$i}}</a>
                        <a href="{{route('admin.papar-cadangan-pegawai', [$mohon_id, $ulasan->id])}}" class="btn btn-info mt-2">Cadangan Pegawai</a>
                        <a href="{{route('admin.papar-ulasan-cadangan-pengarah', [$mohon_id, $ulasan->id])}}" class="btn btn-info mt-2">Ulasan Pengarah</a>
                    </div>
                </div>
                <div class="row mt-3">
                    <div class="col-auto">
                        <a href="{{route('admin.cetak-pemeriksaan-lepas', ['id'=>$mohon_id, 'borang_ik_id'=>$ulasan->id])}}" class="btn btn-success mtx-2"><i class="fa fa-file-pdf-o"></i> Cetak Lawatan {{$i}}</a>
                        @if(!is_null($ulasan->ulasanPegawai))
                        <a href="{{route('admin.cetak-cadangan-pegawai', [$mohon_id, $ulasan->id])}}" class="btn btn-success mtx-2"><i class="fa fa-file-pdf-o"></i> Cetak Ulasan Pegawai</a>
                        @endif
                    </div>
                </div>
            </div>
          </div>
        </div>

@endforeach
    </div>
@if(auth()->user()->hasRole(['pengarah', 'super'])&&($status_progress == 'ulasan pengarah')&&($borangulas?->id == $last_periksa_id))    
<form action="{{route('pegawai.simpan-ulasan-cadangan')}}" method="post">
    @csrf
    <input type="hidden" name="permohonan_id" value="{{$mohon_id}}">
    <input type="hidden" name="borang_ik_id" value="{{$borangulas?->id}}">
    <div class="row">
        <div class="col-12">
          <div class="card card-round">
            <div class="card-header">
              <div class="card-head-row card-tools-still-right">
                <h4 class="card-title">Ulasan ke atas Laporan dan Cadangan</h4>
              </div>
            </div> <!-- /.card-header -->
            <div class="card-body">
                            @if(auth()->user()->role == 'super')
                    <div class="row">
                        <div class="col-md-3">
                            <div class="mb-3">
                                <label for="dt_cadangan">Tarikh Cadangan</label>
                                <input id="dt_cadangan" class="form-control" type="date" name="dt_cadangan" value="{{ old('dt_cadangan', $borangulas?->dt_cadangan) }}" autofocus autocomplete="dt_cadangan"/>
                            </div>
                        </div> 
                        <div class="col-md-3">
                                <label for="peg_id">Nama Pegawai</label>
                            <select name="peg_id" id="peg_id" class="form-control form-select">
                                <option value="">Pilih Pegawai</option>
                                @foreach($pengs as $peng)
                                    <option value="{{$peng->id}}">{{$peng->name}}</option>
                                @endforeach
                            </select>
                        </div> 
                    </div>
                            @endif
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" id="dibawa_ke_mesyuarat" name="dibawa_ke_mesyuarat" value="1"
                                    @if($borangulas?->ulasanPegawai?->pengarah_bawa_mesyuarat == '1')
                                        {{'checked'}}
                                    @endif readonly>
                    <label class="form-check-label" for="dibawa_ke_mesyuarat" >Dibawa ke Mesyuarat Jawatankuasa Kesihatan dan Lesen untuk : </label> 
                </div>
                <table class="table mt-1">
                    <tbody>
                        <tr>
                            <td>
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" id="cadangan_dipertimbangkan" name="cadangan" value="dipertimbangkan"
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ulasan == 'dipertimbangkan')
                                                        {{'checked'}}
                                                    @endif >
                                    <label class="form-check-label" for="cadangan_dipertimbangkan" ><strong>Dipertimbangkan</strong>/diperakukan kelulusan lesen dengan bersyarat.</label> 
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" id="cadangan_ditolak" name="cadangan" value="ditolak"
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ulasan == 'ditolak')
                                                        {{'checked'}}
                                                    @endif >
                                    <label class="form-check-label" for="cadangan_tidak_menyokong" ><strong>Ditolak</strong> kerana : </label>
                                </div>
                                <div class="row">
                                    <div class="col-1">&nbsp;</div>
                                    <div class="col-sm-11">
                                        <div class="form-check">
                                            <input class="form-check-input" type="checkbox" name="ditolak_sebab" id="ditolak_sebab_gagal_patuhi_syarat" value="pemohon gagal mematuhi syarat"
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ditolak_sebab == 'pemohon gagal mematuhi syarat')
                                                        {{'checked'}}
                                                    @endif  />
                                            <label class="form-check-label" for="ditolak_sebab_gagal_patuhi_syarat" >pemohon gagal mematuhi syarat</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-1">&nbsp;</div>
                                    <div class="col-sm-11">
                                        <div class="form-check">
                                            <input class="form-check-input" type="checkbox" name="ditolak_sebab" id="ditolak_sebab_bukan_dipohon" value="perniagaan dijalankan bukan seperti dipohon"
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ditolak_sebab == 'perniagaan dijalankan bukan seperti dipohon')
                                                        {{'checked'}}
                                                    @endif  />
                                            <label class="form-check-label" for="ditolak_sebab_bukan_dipohon" >perniagaan dijalankan bukan seperti dipohon</label>
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" id="cadangan_ditangguhkan" name="cadangan" value="ditangguhkan"
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ulasan  == 'ditangguhkan')
                                                        {{'checked'}}
                                                    @endif >
                                    <label class="form-check-label" for="cadangan_ditangguhkan" ><strong>Ditangguhkan</strong> sehingga pemohon mematuhi syarat</label>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="form-group">
                                    <label class="form-check-label" for="catatan" >Catatan : </label>
                                    <textarea class="form-control" id="catatan" name="catatan" rows="2">{{ old('catatan', $borangulas?->ulasanPegawai?->pengarah_catatan) }}</textarea>                                        
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>          
          </div>
        </div> <!-- /.col -->               
    </div> <!--end::Row-->
    <div class="row justify-content-center">
        <div class="col-12">
                <input id="simpan" class="btn btn-secondary" type="submit" name="simpan" value="Simpan"/>
        </div> <!-- /.col -->               
    </div> <!--end::Row-->
</form>

@section('js')
  <!-- Select2 -->
    <script src="{{ asset('plugins/select2/js/select2.full.min.js') }}"></script>
@endsection

@else
    @if(!is_null($borangulas?->ulasanPegawai))
    <div class="row">
        <div class="col-12">
          <div class="card card-round">
            <div class="card-header">
              <div class="card-head-row card-tools-still-right">
                <h4 class="card-title">Ulasan ke atas Laporan dan Cadangan</h4>
              </div>
            </div> <!-- /.card-header -->
            <div class="card-body">
                    <div class="row">
                        <div class="col-md-3">
                            <div class="mb-3">
                                <label for="dt_cadang">Tarikh Cadangan</label>
                                <input id="dt_cadang" class="form-control" type="text" name="dt_cadang" value="{{ old('dt_cadang', $borangulas?->ulasanPegawai?->dt_pegawai_ulas) }}" autofocus autocomplete="dt_cadang" readonly/>
                            </div>
                        </div> 
                    </div>
                <div class="form-check">
                    @if($borangulas?->ulasanPegawai?->pengarah_bawa_mesyuarat == '1')
                        <i class="far fa-check-square fa-lg"></i>
                        <label class="form-check-label" for="dibawa_ke_mesyuarat" >Dibawa ke Mesyuarat Jawatankuasa Kesihatan dan Lesen untuk : </label> 
                    @endif 
                </div>
                <table class="table mt-1">
                    <tbody>
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ulasan == 'dipertimbangkan')
                        <tr class="table-success">
                            <td>
                                <div class="form-check">
                                                        <i class="far fa-check-square fa-lg"></i>
                                    <label class="form-check-label" for="cadangan_dipertimbangkan" ><strong>Dipertimbangkan</strong>/diperakukan kelulusan lesen dengan bersyarat.</label> 
                                </div>
                            </td>
                        </tr>
                                                    @endif
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ulasan == 'ditolak')
                        <tr class="table-danger">
                            <td>
                                <div class="form-check">
                                                        <i class="far fa-check-square fa-lg"></i>
                                    <label class="form-check-label" for="cadangan_tidak_menyokong" ><strong>Ditolak</strong> kerana : </label>
                                </div>
                                <div class="row">
                                    <div class="col-1">&nbsp;</div>
                                    <div class="col-sm-11">
                                        <div class="form-check">
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ditolak_sebab == 'pemohon gagal mematuhi syarat')
                                                        <i class="far fa-check-square fa-lg"></i>
                                                    @endif  
                                            <label class="form-check-label" for="ditolak_sebab_gagal_patuhi_syarat" >pemohon gagal mematuhi syarat</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-1">&nbsp;</div>
                                    <div class="col-sm-11">
                                        <div class="form-check">
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ditolak_sebab == 'perniagaan dijalankan bukan seperti dipohon')
                                                        <i class="far fa-check-square fa-lg"></i>
                                                    @endif 
                                            <label class="form-check-label" for="ditolak_sebab_bukan_dipohon" >perniagaan dijalankan bukan seperti dipohon</label>
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                                                    @endif
                                                    @if($borangulas?->ulasanPegawai?->pengarah_ulasan  == 'ditangguhkan')
                        <tr class="table-warning">
                            <td>
                                <div class="form-check">
                                    <i class="far fa-check-square fa-lg"></i>
                                    <label class="form-check-label" for="cadangan_ditangguhkan" ><strong>Ditangguhkan</strong> sehingga pemohon mematuhi syarat</label>
                                </div>
                            </td>
                        </tr>
                                                    @endif 
                        <tr>
                            <td>
                                <div class="form-group">
                                    <label class="form-check-label" for="catatan" >Catatan : </label>
                                    <textarea class="form-control" id="catatan" name="catatan" rows="2" readonly>{{ old('catatan', $borangulas?->ulasanPegawai?->pengarah_catatan) }}</textarea>                                        
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>          
          </div>
        </div> <!-- /.col -->               
    </div> <!--end::Row-->
    @endif
@endif