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

const binding = new Shiny.InputBinding();

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

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

  getValue(el) {
    return el.__shinyWebawesomeValue || [];
  },


  subscribe(el, callback) {
    el.__shinyWebawesomeCallback = (event) => {
      const selection = Array.isArray(event?.detail?.selection) ? event.detail.selection : [];
      el.__shinyWebawesomeValue = selection
        .map((item) => item?.id || null)
        .filter((id) => Boolean(id));
    if (selection.some((item) => !(item && item.id))) {
      window.ShinyWebawesomeWarn.warnOnce({
        key: "missing_tree_item_id",
        inputId: el.id,
        message: "`wa-tree` input omitted selected items without DOM ids from its Shiny value. Assign ids to selectable `wa-tree-item` elements to receive stable selection values. Suppress with `options(shiny.webawesome.warnings = list(missing_tree_item_id = FALSE))`."
      });
    }
      callback();
    };
    el.__shinyWebawesomeEvents = ["wa-selection-change"];
    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) {
    return;
  }
});

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