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 { createEnterKeyHandlerToTriggerClick } from '../../../../utils/accessibility';
import changeManager from '../../../../helpers/change-manager/change-manager';
import domNodeSubjectFactory from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { VegaInternalFocusVegaInput, VegaInternalUpdateVegaInputValue, } from '../../../../helpers/event-manager/event-id/vega-internal-event-id';
export class VegaInputInputContainerRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.renderPrefixText = () => {
      return this.prefixText && h("div", { class: "prefix-text" }, this.prefixText);
    };
    this.renderSuffixText = () => {
      return this.suffixText && h("div", { class: "suffix-text" }, this.suffixText);
    };
    this.onClickClearIcon = () => {
      changeManager.notify(domNodeSubjectFactory.getSubject(this.host, VegaInternalUpdateVegaInputValue), '');
    };
    this.isClearIconVisible = () => {
      return !this.disabled && Boolean(this.value);
    };
    this.onClearInputFocus = () => {
      this.inputContainerRef.classList.add('no-focus');
    };
    this.onClearInputBlur = () => {
      this.inputContainerRef.classList.remove('no-focus');
    };
    this.onContainerClick = () => {
      changeManager.notify(domNodeSubjectFactory.getSubject(this.host, VegaInternalFocusVegaInput), {});
    };
  }
  getInputContainerRef() {
    return this.inputContainerRef;
  }
  render() {
    return (
    // This container uses onClick to delegate focus to the inner <input> when clicking anywhere in the input area.
    // It is a layout wrapper, not an interactive widget, so adding a role would be semantically incorrect.
    // eslint-disable-next-line jsx-a11y/no-static-element-interactions
    h("div", { ref: (e) => (this.inputContainerRef = e), part: "input-container", class: {
        'vega-input-container': true,
        'with-value': !!this.value,
        [`vega-input-size-${this.size}`]: true,
        'vega-input-disabled': this.disabled,
        'compact-input-width': this.isCompactInputWidth,
      }, onClick: this.onContainerClick, "aria-disabled": this.disabled ? 'true' : undefined, onKeyDown: createEnterKeyHandlerToTriggerClick() },
      this.prefixSlotRenderer.render(),
      this.renderPrefixText(),
      this.inputRenderer.render(),
      this.renderSuffixText(),
      this.type === 'password'
        ? this.passwordEyeRenderer.render()
        : this.showClearIcon && this.renderClearIcon()));
  }
  renderClearIcon() {
    return (h("div", { class: {
        'vega-input-clear-icon': true,
        'invisible': !this.isClearIconVisible(),
      }, tabIndex: !this.disabled ? 0 : -1, "aria-label": "clear input", role: "button", onClick: this.onClickClearIcon, onKeyDown: createEnterKeyHandlerToTriggerClick(), onFocusin: this.onClearInputFocus, onFocusout: this.onClearInputBlur },
      h("vega-icon", { icon: "close" })));
  }
}
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "size", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "type", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "showClearIcon", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "prefixText", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "suffixText", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "isCompactInputWidth", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "prefixSlotRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "passwordEyeRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaInputInputContainerRenderer.prototype, "inputRenderer", void 0);
