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 { isArrayOfType, isDropdownSourceItemType } from '../../../../types/type-guard';
/**
 * The `VegaDropdownSourceController` class is responsible for handling and formatting the source data
 * for a dropdown component in a TypeScript application.
 */
export class VegaDropdownSourceController extends VegaSlimmer {
  /**
   * Component lifecycle - [componentWillLoad]
   */
  componentWillLoad() {
    this.handleSource();
  }
  /**
   * The function "watchSource" calls the function "handleSource".
   */
  watchSource() {
    this.handleSource();
  }
  /** watchCaseSensitive */
  watchCaseSensitive() {
    this.handleSource();
  }
  /**
   * The function sets the source for rendering by searching for a formatted source.
   */
  setRenderSource() {
    if (this.renderModeController.isSourceRenderMode()) {
      this.sourceForRender = this.searchController.search(this.source);
    }
  }
  /**
   * The function "handleSource" performs validation, formatting, and rendering of a source.
   */
  handleSource() {
    this.validSource();
    this.setRenderSource();
  }
  /**
   * The function "validSource" checks if the "source" variable is an array of "VegaDropdownSourceItem"
   * type, and if not, assigns an empty array to it.
   */
  validSource() {
    this.source = isArrayOfType(this.source, isDropdownSourceItemType)
      ? this.source
      : [];
  }
}
__decorate([
  MapToComponentField({ writable: true })
], VegaDropdownSourceController.prototype, "source", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaDropdownSourceController.prototype, "sourceForRender", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownSourceController.prototype, "searchController", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownSourceController.prototype, "renderModeController", void 0);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaDropdownSourceController.prototype, "componentWillLoad", null);
__decorate([
  MapToComponentMethod('watchSource')
], VegaDropdownSourceController.prototype, "watchSource", null);
__decorate([
  MapToComponentMethod('watchCaseSensitive')
], VegaDropdownSourceController.prototype, "watchCaseSensitive", null);
