var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
import remoteInvocationRegistry from '../../../../helpers/remote-invocation/remote-invocation-registry';
import { VegaDropdownRenderItemInternalOverridden, VegaDropdownSearchInternalOverridden, } from '../../../../helpers/event-manager/event-id/vega-internal-event-id';
import domNodeSubjectFactory from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
/** Manager remote invocation */
export class VegaDropdownRemoteInvocationController extends VegaSlimmer {
  /**
   * Component lifecycle - connectedCallback
   */
  connectedCallback() {
    this.remotePhoneNumberSearchSubject = domNodeSubjectFactory.getSubjectFromParentNodeByEventId(this.host, VegaDropdownSearchInternalOverridden);
    this.remotePhoneNumberItemRenderSubject = domNodeSubjectFactory.getSubjectFromParentNodeByEventId(this.host, VegaDropdownRenderItemInternalOverridden);
  }
  /**
   *  Call the search function in input-phone-number.
   *
   * @param {unknown[]} args - arguments of remote search function
   * @returns {Nullable<VegaDropdownSourceItem[]>} - searched items.
   */
  callRemoteSearch(...args) {
    if (this.remotePhoneNumberSearchSubject) {
      const searchResult = remoteInvocationRegistry.call(this.remotePhoneNumberSearchSubject, ...args);
      if (searchResult)
        return searchResult;
    }
    return null;
  }
  /**
   * Call the item render function in input-phone-number.
   *
   * @param {unknown[]} args - arguments of remote item render function
   * @returns {Nullable<HTMLVegaDropdownItemElement>} - rendered item
   */
  callRemoteItemRender(...args) {
    if (this.remotePhoneNumberItemRenderSubject) {
      const renderResult = remoteInvocationRegistry.call(this.remotePhoneNumberItemRenderSubject, ...args);
      if (renderResult)
        return renderResult;
    }
    return null;
  }
}
__decorate([
  MapToComponentField()
], VegaDropdownRemoteInvocationController.prototype, "host", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaDropdownRemoteInvocationController.prototype, "connectedCallback", null);
