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 { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { DomNodeSubjectObserverFactory } from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaClick, VegaLabelButtonClick } from '../../../../helpers/event-manager/event-id/vega-event-id';
import changeManager from '../../../../helpers/change-manager/change-manager';
import domNodeSubjectFactory from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { VegaInternalFocusVegaInput } from '../../../../helpers/event-manager/event-id/vega-internal-event-id';
export class VegaInputRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.handleLabelButtonClick = () => {
      this.labelButtonClickEventEmitter.emit();
    };
    /*
     * The below method is e2e-test covered in
     * @see{module:vega-input-focus-by-label}
     */
    /* istanbul ignore next */
    this.handleLabelClick = () => {
      changeManager.notify(domNodeSubjectFactory.getSubject(this.host, VegaInternalFocusVegaInput), {});
    };
  }
  render() {
    return (h("div", { class: "vega-input", part: "container-wrapper" },
      this.renderLabelDom(),
      this.renderInputContainer(),
      this.renderHintDom()));
  }
  renderInputContainer() {
    return this.renderModeController.isSource() || this.renderModeController.isTemplate()
      ? this.inputSuggestionsRenderer.render(this.inputContainerRenderer.render())
      : this.inputContainerRenderer.render();
  }
  renderLabelDom() {
    return (h("vega-field-label", { "is-field-required": this.required, disabled: this.disabled, label: this.label, suffixButtonProps: this.labelSuffixButtonProps, suffixButtonConfig: this.labelSuffixButtonConfig, ref: (node) => {
        DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, VegaLabelButtonClick, this.handleLabelButtonClick);
        DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, VegaClick, this.handleLabelClick);
      } }));
  }
  renderHintDom() {
    return this.hint !== '' ? (h("div", { class: "vega-hint" },
      h("label", null, this.hint))) : null;
  }
}
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "required", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "label", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "hint", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "labelSuffixButtonProps", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "labelSuffixButtonConfig", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "labelButtonClickEventEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "inputContainerRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "inputSuggestionsRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaInputRenderer.prototype, "renderModeController", void 0);
