@extends('layouts.admin')
@section('content')
@can('bimbingan_create')
    <div style="margin-bottom: 10px;" class="row">
        <div class="col-lg-12">
            <a class="btn btn-success" href="{{ route("admin.bimbingans.create") }}">
                {{ trans('global.add') }} {{ trans('cruds.bimbingan.title_singular') }}
            </a>
        </div>
    </div>
@endcan
<div class="card">
    <div class="card-header">
        {{ trans('cruds.bimbingan.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.bimbingan.fields.nama') }}
                        </th>
                        <th>
                            {{ trans('cruds.bimbingan.fields.no_register') }}
                        </th>
                        <th>
                            &nbsp;
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($bimbingans as $key => $bimbingan)
                        <tr data-entry-id="{{ $bimbingan->id }}">
                            <td>

                            </td>
                            <td>
                                {{ $bimbingan->nama->nama ?? '' }}
                            </td>
                            <td>
                                {{ $bimbingan->no_register ?? '' }}
                            </td>
                            <td>
                                @can('bimbingan_show')
                                    <a class="btn btn-xs btn-primary" href="{{ route('admin.bimbingans.show', $bimbingan->id) }}">
                                        {{ trans('global.view') }}
                                    </a>
                                @endcan
                                @can('bimbingan_edit')
                                    <a class="btn btn-xs btn-info" href="{{ route('admin.bimbingans.edit', $bimbingan->id) }}">
                                        {{ trans('global.edit') }}
                                    </a>
                                @endcan
                                @can('bimbingan_delete')
                                    <form action="{{ route('admin.bimbingans.destroy', $bimbingan->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.bimbingans.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('bimbingan_delete')
  dtButtons.push(deleteButton)
@endcan

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

</script>
@endsection