// # Generated by tools/generate_components.R. Do not edit by hand.

const binding = new Shiny.InputBinding();

$.extend(binding, {
  find(scope) {
    return $(scope).find('wa-button[id]');
  },

  getId(el) {
    return el.id;
  },

  getValue(el) {
    return $(el).data("val") || 0;
  },
  getType(el) {
    return "shiny.action";
  },

  subscribe(el, callback) {
    el.__shinyWebawesomeCallback = () => {
      const val = $(el).data("val") || 0;
      $(el).data("val", val + 1);
      callback(false);
    };
    el.__shinyWebawesomeEvents = ["click"];
    el.__shinyWebawesomeEvents.forEach((eventName) => {
      el.addEventListener(eventName, el.__shinyWebawesomeCallback);
    });
  },

  unsubscribe(el, callback) {
    if (el.__shinyWebawesomeCallback) {
      (el.__shinyWebawesomeEvents || []).forEach((eventName) => {
        el.removeEventListener(eventName, el.__shinyWebawesomeCallback);
      });
      delete el.__shinyWebawesomeEvents;
      delete el.__shinyWebawesomeCallback;
    }
  },

  receiveMessage(el, data) {
    if (Object.prototype.hasOwnProperty.call(data, "disabled")) {
      if (data.disabled) {
        el.setAttribute("disabled", "");
      } else {
        el.removeAttribute("disabled");
      }
    }
  }
});

Shiny.inputBindings.register(binding, 'shiny.webawesome.wa_button');
