@can('service_complaint_create')
    <div style="margin-bottom: 10px;" class="row">
        <div class="col-lg-12">
            <a class="btn btn-success" href="{{ route('admin.service-complaints.create') }}">
                {{ trans('global.add') }} {{ trans('cruds.serviceComplaint.title_singular') }}
            </a>
        </div>
    </div>
@endcan

<div class="card">
    <div class="card-header">
        {{ trans('cruds.serviceComplaint.title_singular') }} {{ trans('global.list') }}
    </div>

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

                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.id') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.client') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.location') }}
                        </th>
                        <th>
                            {{ trans('cruds.contactContact.fields.location') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.asset') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.airdryer_serial_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.filter_serial_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.eco_drain_serial_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.air_receiver_serial_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.air_compressor_part_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.air_dryer_part_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.filter_part_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.eco_drain_part_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.asset.fields.air_reciever_part_no') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.service_type') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.visit_type') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.status') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.enginner_assigned') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.supervisor_assigned') }}
                        </th>
                        <th>
                            {{ trans('cruds.serviceComplaint.fields.service_date') }}
                        </th>
                        <th>
                            &nbsp;
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($serviceComplaints as $key => $serviceComplaint)
                        <tr data-entry-id="{{ $serviceComplaint->id }}">
                            <td>

                            </td>
                            <td>
                                {{ $serviceComplaint->id ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->client->company_name ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->location->location ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->location->location ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->air_compressor_serial_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->airdryer_serial_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->filter_serial_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->eco_drain_serial_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->air_receiver_serial_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->air_compressor_part_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->air_dryer_part_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->filter_part_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->eco_drain_part_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->asset->air_reciever_part_no ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->service_type->name ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->visit_type->name ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->status->name ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->enginner_assigned->name ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->supervisor_assigned->name ?? '' }}
                            </td>
                            <td>
                                {{ $serviceComplaint->service_date ?? '' }}
                            </td>
                            <td>
                                @can('service_complaint_show')
                                    <a class="btn btn-xs btn-primary" href="{{ route('admin.service-complaints.show', $serviceComplaint->id) }}">
                                        {{ trans('global.view') }}
                                    </a>
                                @endcan

                                @can('service_complaint_edit')
                                    <a class="btn btn-xs btn-info" href="{{ route('admin.service-complaints.edit', $serviceComplaint->id) }}">
                                        {{ trans('global.edit') }}
                                    </a>
                                @endcan

                                @can('service_complaint_delete')
                                    <form action="{{ route('admin.service-complaints.destroy', $serviceComplaint->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>

@section('scripts')
@parent
<script>
    $(function () {
  let dtButtons = $.extend(true, [], $.fn.dataTable.defaults.buttons)
@can('service_complaint_delete')
  let deleteButtonTrans = '{{ trans('global.datatables.delete') }}'
  let deleteButton = {
    text: deleteButtonTrans,
    url: "{{ route('admin.service-complaints.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() })
      }
    }
  }
  dtButtons.push(deleteButton)
@endcan

  $.extend(true, $.fn.dataTable.defaults, {
    orderCellsTop: true,
    order: [[ 1, 'desc' ]],
    pageLength: 100,
  });
  let table = $('.datatable-clientServiceComplaints:not(.ajaxTable)').DataTable({ buttons: dtButtons })
  $('a[data-toggle="tab"]').on('shown.bs.tab click', function(e){
      $($.fn.dataTable.tables(true)).DataTable()
          .columns.adjust();
  });
  
})

</script>
@endsection