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 { LogUtility } from '../../../../../utils/log';
import { FORM_ELEMENT_VALUE_CHANGE } from '../../../../../helpers/change-manager/subject/static-subject/static-subject-title';
import ChangeManager from '../../../../../helpers/change-manager/change-manager';
/**
 * Manager the value of vega selection chip group.
 */
export class VegaSelectionChipGroupValueController extends VegaSlimmer {
  /**
   * The `watchValue` function emits a change event with the current value and notifies the
   * `ChangeManager` about a form element value change.
   */
  watchValue() {
    this.changeEventEmitter.emit(this.value);
    ChangeManager.notify(FORM_ELEMENT_VALUE_CHANGE, {
      host: this.host,
      detail: this.value,
    });
  }
  /**
   * Set group value.
   *
   * @param {string[] | string} value - value.
   */
  setValue(value) {
    if (this.valueGuard(value)) {
      this.value = value;
    }
  }
  /**
   * The function `valueGuard` checks if the input value is valid based on the select type.
   *
   * @param {string[] | string} value - value.
   * @returns {boolean} is valid value.
   */
  valueGuard(value) {
    switch (this.selectType) {
      case 'radio':
        return typeof value === 'string';
      case 'checkbox':
        return Array.isArray(value) && value.every((item) => typeof item === 'string');
      default:
        LogUtility.warn(`Invalid selection chip group value ${value} for ${this.selectType} mode`);
        return false;
    }
  }
}
__decorate([
  MapToComponentField()
], VegaSelectionChipGroupValueController.prototype, "host", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaSelectionChipGroupValueController.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionChipGroupValueController.prototype, "changeEventEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionChipGroupValueController.prototype, "selectType", void 0);
__decorate([
  MapToComponentMethod('watchValue')
], VegaSelectionChipGroupValueController.prototype, "watchValue", null);
