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 changeManager from '../../../../helpers/change-manager/change-manager';
import { FORM_ELEMENT_VALUE_CHANGE } from '../../../../helpers/change-manager/subject/static-subject/static-subject-title';
/** manages the value and change events for a file uploader component. */
export class VegaFileUploaderValueController extends VegaSlimmer {
  /**
   * Emit the change event and notify the value change subject when component value change, reset the value to null if the value is not valid
   *
   * @param {VegaFileUploaderFile[]} newValue The new value
   */
  valueChangeHandler(newValue) {
    if (!newValue || Array.isArray(newValue)) {
      this.changeEventEmitter.emit(newValue);
      changeManager.notify(FORM_ELEMENT_VALUE_CHANGE, {
        host: this.host,
        detail: this.value,
      });
    }
    else if (newValue && !Array.isArray(newValue)) {
      this.setValue(null);
    }
  }
  /**
   * Set the component value to a new value
   *
   * @param {VegaFileUploaderFile[]|null} value The new value
   */
  setValue(value) {
    this.value = value;
  }
}
__decorate([
  MapToComponentField()
], VegaFileUploaderValueController.prototype, "host", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaFileUploaderValueController.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaFileUploaderValueController.prototype, "changeEventEmitter", void 0);
__decorate([
  MapToComponentMethod('watchValue')
], VegaFileUploaderValueController.prototype, "valueChangeHandler", null);
