<style>
</style>

<x-app-layout>
  <x-slot name="header">
    <h2 class="font-semibold text-xl text-gray-800 leading-tight">
      <i class="fas fa-users"></i> Utenti
    </h2>
  </x-slot>

  <div class="row justify-content-center mb-4">
    <div class="col-xl-6 col-lg-6">
      <div class="card">
        <div class="card-body">
          @if(Session::has('flash_message'))
          <div class="alert alert-success">
            {{ Session::get('flash_message') }}
          </div>
          @endif

          {{ $dataTable_user->table() }}

          {{ $dataTable_user->scripts() }}

        </div>
      </div>
    </div>

    <div class="col-xl-6 col-lg-6" id="user_detail">
    </div>
  </div>

</x-app-layout>

<script>
$(document).ready(function(){
  $.ajaxSetup({
    headers: {
      'X-CSRF-TOKEN': '{{csrf_token()}}'
    }
  });

  $("#dataTable_user").on('dblclick', 'tbody td', function (e) {
    window.LaravelDataTables["dataTable_user-editor"].edit( $(this).closest('tr'), {
      title: 'Modifica',
      buttons: 'Aggiorna',
    });
  });

  // Editor edit
  $("#dataTable_user").on('click', 'a#editor_edit', function (e) {
    e.preventDefault();
    window.LaravelDataTables["dataTable_user-editor"].edit( $(this).closest('tr'), {
      title: 'Modifica',
      buttons: 'Aggiorna',
    });
  });

  // Editor delete
  $("#dataTable_user").on('click', 'a#editor_delete', function (e) {
    e.preventDefault();
    window.LaravelDataTables["dataTable_user-editor"].remove( $(this).closest('tr'), {
      title: 'Cancella record',
      message: 'Sei sicuro di voler eliminare il record selezionato?',
      buttons: 'Cancella record'
    } );
  } );
});

function initComplete(){
  $('button').removeClass('dt-button');
  $("#dataTable_user").attr('width', '100%');
}

function load_progetti(user_id){
  $('#user_detail').load("{{ route('user.progetti') }}?user_id="+user_id);
}

function load_ruoli(user_id){
  $("#user_detail").load("{!! url('user/roles?user_id="+user_id+"') !!}");
}
</script>
