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 { getCountries } from '../../../../polyfill/libphonenumber';
import remoteInvocationRegistry from '../../../../helpers/remote-invocation/remote-invocation-registry';
import { COUNTRIES } from '../../assets/countries';
import { 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';
/**
 * The `CountrySelectController` class in TypeScript includes methods to set the search string and
 * countryCode properties.
 */
export class CountrySelectController extends VegaSlimmer {
  /**
   * Component lifecycle - connectedCallback
   */
  connectedCallback() {
    this.registerRemoteDropdownSearch();
  }
  /**
   * The function `setCountryCode` sets the countryCode property of an object to the specified VegaCountryCode value.
   *
   * @param {VegaCountryCode} countryCode - The `countryCode` parameter is of type `VegaCountryCode`, which is likely a
   * custom data type representing a country code.
   */
  setCountryCode(countryCode) {
    this.countryCode = countryCode;
  }
  /**
   * Registers a remote invocation call for a dropdown search.
   */
  registerRemoteDropdownSearch() {
    remoteInvocationRegistry.register(domNodeSubjectFactory.getSubject(this.host, VegaDropdownSearchInternalOverridden), this.filterDropdownSourcesBySearchString.bind(this));
  }
  /**
   * Remote invocation call for a dropdown search.
   *
   * @param {DropdownSourceItem[]} source - Source of dropdown.
   * @param {string} searchString - Searching string of dropdown.
   * @returns  {DropdownSourceItem[]}  The searched source.
   */
  filterDropdownSourcesBySearchString(source, searchString) {
    return source.filter((item) => `${COUNTRIES[item.key].toLowerCase()} +${item.label}`
      .toLowerCase()
      .includes(searchString.toLowerCase()));
  }
}
CountrySelectController.defaultCountryCode = 'US';
CountrySelectController.defaultAllowedCountryCodes = getCountries();
__decorate([
  MapToComponentField({ writable: true })
], CountrySelectController.prototype, "countryCode", void 0);
__decorate([
  MapToComponentField()
], CountrySelectController.prototype, "host", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], CountrySelectController.prototype, "connectedCallback", null);
