<!-- Extend Layout -->
@extends('layout.app')
<!-- Add Custom CSS -->
@push('css')
<link rel="stylesheet" href="{{asset('/')}}plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="{{asset('/')}}plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
<link rel="stylesheet" href="{{asset('/')}}plugins/datatables-buttons/css/buttons.bootstrap4.min.css">

@endpush
<!-- Add Content Here -->
@section('content')
<!-- Include Sidebar -->
@include('layout.navbars.sidebar')
<div class="content-wrapper">
    <!-- Main content -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Layanan Aduan</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">Admin</a></li>
              <li class="breadcrumb-item active">Layanan Aduan</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <section class="content">
      <div class="card">
        <!-- /.card-header -->
        <div class="card-body">
          @if ($errors->any())
            <div class="alert alert-danger">
              <ul>
                @foreach ($errors->all() as $error )
                  <li>{{ $error }}</li>
                @endforeach
              </ul>
            </div>
          @endif
          @if(session('success'))
          <div class="alert alert-success">
            <ul>
                <li>{{ session('success') }}</li>
            </ul>
          </div>
          @endif
          <table id="example1" class="table table-bordered table-striped">
            <thead>
            <tr>
              <th>CaseID</th>
              <th>Nama Pelapor</th>
              <th>Nomor Pelapor</th>
              <th>Kategori</th>
              <th>Subjek</th>
              <th>Action</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($data as $datas)
            <tr>
              <td>{{ $datas->caseid }}</td> 
              <td>{{ $datas->nama }} </td>
              <td>{{ $datas->nomor_telepon }} </td>
              <td>{{ $datas->kategori }}</td>
              <td>{{ $datas->subjek }}</td>
              <td class="text-center ">
                <button class="btn btn-primary" data-toggle="modal" data-target="#A{{ $datas->id }}" >Details</button>
                @if($datas->keterangan_selesai==NULL)
                | <button class="btn btn-success" data-toggle="modal" data-target="#S{{ $datas->id }}" >Selesai</button> | 
                <button class="btn btn-danger" data-toggle="modal" data-target="#D{{ $datas->id }}" >Tolak</button>
                @endif
              </td>
            </tr>
            <!-- Modal Detail dan Terima -->
            <div class="modal fade" id="A{{$datas->id}}">
              <div class="modal-dialog modal-lg">
                <div class="modal-content">
                  <div class="modal-header">
                    <h4 class="modal-title">Details Data <b>{{ $datas->caseid }}</b></h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <div class="row">
                      <div class="col">
                        <label for="subjek">Subjek Laporan:</label>
                        <input type="text" id="subjek" class="form-control form-control-border" readonly value="{{ $datas->subjek }}">
                        <label for="kategori">Kategori:</label>
                        <input type="text" id="kategori" class="form-control form-control-border" readonly value="{{ $datas->kategori }}">
                        <label for="nama">Nama Pelapor:</label>
                        <input type="text" id="nama" class="form-control form-control-border" readonly value="{{ $datas->nama }}">
                        <label for="nomor_telepon">Nomor Telepon Pelapor:</label>
                        <input type="text" id="nomor_telepon" class="form-control form-control-border" readonly value="{{ $datas->nomor_telepon }}">
                        <label for="lokasi">Lokasi Permasalahan:</label>
                        <input type="text" id="lokasi" class="form-control form-control-border" readonly value="{{ $datas->lokasi }}">
                        <label for="deskripsi_laporan">Deskripsi Permasalahan:</label>
                        <textarea name="deskripsi_laporan" id="deskripsi_laporan" class="form-control form-control-border" readonly>{{ $datas->deskripsi_laporan }}</textarea>
                      </div>
                    </div>
                    <div class="row mt-3">
                      <div class="col">
                        <label for="file_transkrip">Lihat Lampiran<br>
                        <a href="{{asset('storage')}}/aduan/{{ $datas->bukti_laporan }}" target="_blank" class="btn btn-primary">Klik Disini</a>
                      </div>
                    </div>
                    
                  </div>
                  <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
                    <span>{{$datas->caseid}}</span>
                    @if($datas->ttd_operator=="-")
                      <form action="{{ route('layanan-dpudpa.terima')}}" method="post">
                      @csrf
                      <input type="hidden" name="id" value="{{$datas->id}}">
                      <button type="submit" class="btn btn-success">Terima</button>
                      </form>
                    @endif
                  </form>
                  </div>
                </div>
                <!-- /.modal-content -->
              </div>
              <!-- /.modal-dialog -->
            </div>
            <!-- /.modal-Selesai -->
            <div class="modal fade" id="S{{$datas->id}}">
              <div class="modal-dialog modal-lg">
                <div class="modal-content">
                  <div class="modal-header">
                    <h4 class="modal-title">Apa Anda Yakin Menyelesaikan Laporan : <b>{{ $datas->caseid }}</b></h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <div class="alert alert-info alert-dismissible">
                      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                      <h5><i class="icon fas fa-info"></i> Perhatian!</h5>
                      <span >Alasan yang Dimasukkan Disini, Dimasukkan Sebagai Lampiran.</span>
                    </div>
                  <form action="{{ route('layanan-aduan.selesai') }}" method="post">
                  @csrf
                  <div class="row">
                    <div class="col">
                      <label for="keterangan_selesai">Keterangan Penyelesaian:</label>
                      <textarea name="keterangan_selesai" class="form-control" id="alasan" cols="30" rows="10" 
                      placeholder="Masukkan Keterangan Penyelesaian Disini
                      Masukkan Penyelesaian Disini"></textarea>
                      <input type="hidden" name="id" value="{{$datas->id}}">
                    </div>
                  </div>
                  </div>
                  <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-success">Kirim</button>
                  </form>
                  </div>
                </div>
                <!-- /.modal-content -->
              </div>
              <!-- /.modal-dialog -->
            </div>
            <!-- /.modal-Delete -->
            <div class="modal fade" id="D{{$datas->id}}">
              <div class="modal-dialog modal-lg">
                <div class="modal-content">
                  <div class="modal-header">
                    <h4 class="modal-title">Apa Anda Yakin Ingin Menghapus Data : <b>{{ $datas->caseid }}</b></h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <div class="alert alert-info alert-dismissible">
                      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                      <h5><i class="icon fas fa-info"></i> Perhatian!</h5>
                      <span>Alasan yang Dimasukkan Disini, Dimasukkan Sebagai Lampiran.</span>
                    </div>
                  <form action="{{ route('layanan-aduan.destroy') }}" method="post">
                  @csrf @method('DELETE')
                  <div class="row">
                    <div class="col">
                      <label for="alasan">Alasan:</label>
                      <textarea name="alasan" class="form-control" id="alasan" cols="30" rows="10" 
                      placeholder="Masukkan Alasan Disini
                      Masukkan Alasan Disini"></textarea>
                      <input type="hidden" name="id" value="{{$datas->id}}">
                    </div>
                  </div>
                  </div>
                  <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-danger">Kirim</button>
                  </form>
                  </div>
                </div>
                <!-- /.modal-content -->
              </div>
              <!-- /.modal-dialog -->
            </div>
            @endforeach
            </tbody>
            <tfoot>
              <tr>
                <th>CaseID</th>
                <th>NIM</th>
                <th>Nama Mahasiswa</th>
                <th>DPU</th>
                <th>DPA</th>
                <th>Action</th>
              </tr>
            </tfoot>
          </table>
        </div>
        <!-- /.card-body -->
      </div>
      <!-- /.card -->
    </section>
    <!-- /.content -->
</div>
@endsection

<!-- Add Custom JS -->
@push('js')
<!-- DataTables  & Plugins -->
<script src="{{asset('/')}}plugins/datatables/jquery.dataTables.min.js"></script>
<script src="{{asset('/')}}plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="{{asset('/')}}plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="{{asset('/')}}plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="{{asset('/')}}plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="{{asset('/')}}plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="{{asset('/')}}plugins/jszip/jszip.min.js"></script>
<script src="{{asset('/')}}plugins/pdfmake/pdfmake.min.js"></script>
<script src="{{asset('/')}}plugins/pdfmake/vfs_fonts.js"></script>
<script src="{{asset('/')}}plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="{{asset('/')}}plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="{{asset('/')}}plugins/datatables-buttons/js/buttons.colVis.min.js"></script>

<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": [{
            // New button configuration
            text: 'Tambah Data', // Replace with your desired button text
            action: function ( e, dt, node, config ) {
                // Perform your custom action here, e.g., open a new tab with the external link
                window.open("{{ route('layanan-aduan.tambah')}}", '_blank');
            }
        },"csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');

  });
</script>
@endpush

