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 { h } from '@stencil/core';
import { VegaSlimmer, MapToComponentField } from 'vega-slimmer/core';
import { DomNodeSubjectObserverFactory } from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaBlur, VegaChange, VegaFocus } from '../../../../helpers/event-manager/event-id/vega-event-id';
/** The `VegaTimePickerInputRenderer` class is a TypeScript React component that renders a time picker input field. */
export class VegaTimePickerSingleInputRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * It is an event handler that is called when the `vega-input` component emits a `VegaChange` event.
     *
     * @param {CustomEvent} e event object
     */
    this.onChildVegaInputChange = (e) => {
      this.valueController.setValue(e.detail);
    };
  }
  /**
   * The function returns a reference to an HTML input element.
   *
   * @returns {HTMLVegaInputElement} an HTMLVegaInputElement.
   */
  getInputRef() {
    return this.timeInputRef;
  }
  /* istanbul ignore next */
  /**
   * The function updates the value of a time input field in a TypeScript React component.
   *
   * @param {string} value - A string value that will be used to update the input value.
   */
  updateInputValue(value) {
    this.timeInputRef.value = value;
  }
  /* istanbul ignore next */
  render() {
    return (h("div", { class: "time-picker-input" },
      h("vega-input", { "prefix-icon": "clock-face", placeholder: this.getPlaceholder(), disabled: this.disabled, readOnly: this.readOnly, size: this.size, value: typeof this.value === 'string' ? this.value : '', showClearIcon: this.showClearIcon, ref: (ref) => {
          this.timeInputRef = ref;
          this.handleVegaInputEvent(ref);
        } })));
  }
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-time-picker-keyboard-control-e2e}
   * @see{module:vega-time-picker-keyboard-control-e2e}
   */
  /* istanbul ignore next */
  /**
   * The function `handleVegaInputEvent` adds event observers to a given HTML input element for handling changes, focus, and blur events.
   *
   * @param {HTMLVegaInputElement} ref - The ref parameter is a reference to an HTML input element with the type "vega".
   */
  handleVegaInputEvent(ref) {
    DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaChange, (input) => {
      this.onChildVegaInputChange(input);
    });
    DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaFocus, () => {
      this.singleDropdownController.show();
    });
    //When the filled time format is incorrect, the value needs to be set to empty, the initial value may also be empty, so the input needs to be set to an empty value.
    DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaBlur, (input) => {
      this.valueController.checkValueAfterInputBlur(input);
    });
  }
  /**
   * get the vega input placeholder
   *
   * @returns {string} a string value
   */
  getPlaceholder() {
    return this.placeholder && typeof this.placeholder === 'string'
      ? this.placeholder
      : this.translationSlimmer.t('Select Time');
  }
}
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "placeholder", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "size", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "valueController", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "singleDropdownController", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "translationSlimmer", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "readOnly", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleInputRenderer.prototype, "showClearIcon", void 0);
