// actualiza los status en la base de datos

function send_data(target) {
  let id = target.dataset.id;
  let valor = target.value != "Null" ? target.value : null;
  let data = { id, value: valor };


  if (valor === 'Archivado') {
      let table = $('#dbContact').DataTable();
      let row = table.row(`tr[data-id="${id}"]`);
      row.remove().draw();
  }

  fetch('/user/manage-record', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(data),
      credentials: 'include'
  });
}

document.getElementById('dbContact').addEventListener('change', (event) => {
  if (event.target.matches('select.form-select[data-id]')) {
      send_data(event.target);
  }
});


