@extends('layouts.admin')
@section('content')
@can('kegiatanpkapk_create')
    <div style="margin-bottom: 10px;" class="row">
        <div class="col-lg-12">
            <a class="btn btn-success" href="{{ route("admin.kegiatanpkapks.create") }}">
                {{ trans('global.add') }} {{ trans('cruds.kegiatanpkapk.title_singular') }}
            </a>
        </div>
    </div>
@endcan
<div class="card">
    <div class="card-header">
        {{ trans('cruds.kegiatanpkapk.title_singular') }} {{ trans('global.list') }}
    </div>

    <div class="card-body">
        <div class="table-responsive">
            <table class=" table table-bordered table-striped table-hover datatable">
                <thead>
                    <tr>
                        <th width="10">

                        </th>
                        <th>
                            {{ trans('cruds.kegiatanpkapk.fields.nama') }}
                        </th>
                        <th>
                            {{ trans('cruds.referensipkapk.fields.nip') }}
                        </th>
                        <th>
                            {{ trans('cruds.kegiatanpkapk.fields.kegiatan') }}
                        </th>
                        <th>
                            {{ trans('cruds.referensi.fields.kegiatan') }}
                        </th>
                        <th>
                            {{ trans('cruds.referensi.fields.angka_kredit') }}
                        </th>
                        <th>
                            {{ trans('cruds.referensi.fields.pelaksana_ak_permen') }}
                        </th>
                        <th>
                            {{ trans('cruds.kegiatanpkapk.fields.nama_klien') }}
                        </th>
                        <th>
                            {{ trans('cruds.identitasKlien.fields.no_register') }}
                        </th>
                        <th>
                            {{ trans('cruds.kegiatanpkapk.fields.penilaian') }}
                        </th>
                        <th>
                            {{ trans('cruds.kegiatanpkapk.fields.dokumen') }}
                        </th>
                        <th>
                            &nbsp;
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($kegiatanpkapks as $key => $kegiatanpkapk)
                        <tr data-entry-id="{{ $kegiatanpkapk->id }}">
                            <td>

                            </td>
                            <td>
                                {{ $kegiatanpkapk->nama->nama ?? '' }}
                            </td>
                            <td>
                                {{ $kegiatanpkapk->nama->nip ?? '' }}
                            </td>
                            <td>
                                {{ $kegiatanpkapk->kegiatan->detail_kegiatan ?? '' }}
                            </td>
                            <td>
                                {{ $kegiatanpkapk->kegiatan->kegiatan ?? '' }}
                            </td>
                            <td>
                                {{ $kegiatanpkapk->kegiatan->angka_kredit ?? '' }}
                            </td>
                            <td>
                                {{ $kegiatanpkapk->kegiatan->pelaksana_ak_permen ?? '' }}
                            </td>
                            <td>
                                {{ $kegiatanpkapk->nama_klien->nama ?? '' }}
                            </td>
                            <td>
                                {{ $kegiatanpkapk->nama_klien->no_register ?? '' }}
                            </td>
                            <td>
                                {{ App\Kegiatanpkapk::PENILAIAN_RADIO[$kegiatanpkapk->penilaian] ?? '' }}
                            </td>
                            <td>
                                @if($kegiatanpkapk->dokumen)
                                    @foreach($kegiatanpkapk->dokumen as $key => $media)
                                        <a href="{{ $media->getUrl() }}" target="_blank">
                                            {{ trans('global.view_file') }}
                                        </a>
                                    @endforeach
                                @endif
                            </td>
                            <td>
                                @can('kegiatanpkapk_show')
                                    <a class="btn btn-xs btn-primary" href="{{ route('admin.kegiatanpkapks.show', $kegiatanpkapk->id) }}">
                                        {{ trans('global.view') }}
                                    </a>
                                @endcan
                                @can('kegiatanpkapk_edit')
                                    <a class="btn btn-xs btn-info" href="{{ route('admin.kegiatanpkapks.edit', $kegiatanpkapk->id) }}">
                                        {{ trans('global.edit') }}
                                    </a>
                                @endcan
                                @can('kegiatanpkapk_delete')
                                    <form action="{{ route('admin.kegiatanpkapks.destroy', $kegiatanpkapk->id) }}" method="POST" onsubmit="return confirm('{{ trans('global.areYouSure') }}');" style="display: inline-block;">
                                        <input type="hidden" name="_method" value="DELETE">
                                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                        <input type="submit" class="btn btn-xs btn-danger" value="{{ trans('global.delete') }}">
                                    </form>
                                @endcan
                            </td>

                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
@section('scripts')
@parent
<script>
    $(function () {
  let deleteButtonTrans = '{{ trans('global.datatables.delete') }}'
  let deleteButton = {
    text: deleteButtonTrans,
    url: "{{ route('admin.kegiatanpkapks.massDestroy') }}",
    className: 'btn-danger',
    action: function (e, dt, node, config) {
      var ids = $.map(dt.rows({ selected: true }).nodes(), function (entry) {
          return $(entry).data('entry-id')
      });

      if (ids.length === 0) {
        alert('{{ trans('global.datatables.zero_selected') }}')

        return
      }

      if (confirm('{{ trans('global.areYouSure') }}')) {
        $.ajax({
          headers: {'x-csrf-token': _token},
          method: 'POST',
          url: config.url,
          data: { ids: ids, _method: 'DELETE' }})
          .done(function () { location.reload() })
      }
    }
  }
  let dtButtons = $.extend(true, [], $.fn.dataTable.defaults.buttons)
@can('kegiatanpkapk_delete')
  dtButtons.push(deleteButton)
@endcan

  $('.datatable:not(.ajaxTable)').DataTable({ buttons: dtButtons })
})

</script>
@endsection