document.addEventListener('htmx:wsConfigSend', function (e) {
  if (e.target.classList.contains('intersection')) {
    const row = parseInt(e.target.dataset.row);
    const col = parseInt(e.target.dataset.col);

    // Set the custom JSON data
    e.detail.parameters = {
      type: 'make_move',
      row: row,
      col: col,
    };
  } else if (e.target.id == 'resign-button') {
    e.detail.parameters = {
      type: 'resign',
    };
  } else if (e.target.id == 'takeback-button') {
    e.detail.parameters = {
      type: 'takeback',
      action: 'request',
    };
  } else if (e.target.id == 'accept-takeback-button') {
    e.detail.parameters = {
      type: 'takeback',
      action: 'accept',
    };
  } else if (e.target.id == 'decline-takeback-button') {
    e.detail.parameters = {
      type: 'takeback',
      action: 'decline',
    };
  } else if (e.target.id == 'cancel-takeback-request-button') {
    e.detail.parameters = {
      type: 'takeback',
      action: 'cancel',
    };
  } else if (e.target.id == 'draw-button') {
    e.detail.parameters = {
      type: 'draw',
      action: 'request',
    };
  } else if (e.target.id == 'accept-draw-button') {
    e.detail.parameters = {
      type: 'draw',
      action: 'accept',
    };
  } else if (e.target.id == 'decline-draw-button') {
    e.detail.parameters = {
      type: 'draw',
      action: 'decline',
    };
  } else if (e.target.id == 'cancel-draw-request-button') {
    e.detail.parameters = {
      type: 'draw',
      action: 'cancel',
    };
  } else if (e.target.id == 'rematch-button') {
    e.detail.parameters = {
      type: 'rematch',
      action: 'request',
    };
  } else if (e.target.id == 'accept-rematch-button') {
    e.detail.parameters = {
      type: 'rematch',
      action: 'accept',
    };
  } else if (e.target.id == 'decline-rematch-button') {
    e.detail.parameters = {
      type: 'rematch',
      action: 'decline',
    };
  } else if (e.target.id == 'cancel-rematch-request-button') {
    e.detail.parameters = {
      type: 'rematch',
      action: 'cancel',
    };
  } else if (e.target.id == 'save-display-name-ws-button') {
    const displayNameInput = document.getElementById('display-name-input');
    e.detail.parameters = {
      type: 'update_display_name',
      displayName: displayNameInput ? displayNameInput.value.trim() : '',
    };
  }
});
