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';
export class VegaDropdownCreateRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.onItemAdd = () => {
      this.createEventEmitter.emit(this.searchString);
      this.appenderController.hide();
    };
  }
  render() {
    const canRender = this.searchString &&
      this.dynamicOption &&
      !this.childrenController.isLabelExist(this.searchString);
    return (canRender && (h("fragment", null,
      h("div", { class: "vega-dropdown-add-item", onClick: this.onItemAdd, tabIndex: 0, role: "button", "aria-label": `Add ${this.searchString}`, onKeyDown: createEnterKeyHandlerToTriggerClick() },
        h("div", null,
          h("vega-icon", { icon: "plus-sign" })),
        h("span", { class: "v-break-all" }, `Add "${this.searchString}"`)),
      h("div", { class: "vega-dropdown-divider" }))));
  }
}
__decorate([
  MapToComponentField()
], VegaDropdownCreateRenderer.prototype, "searchString", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownCreateRenderer.prototype, "dynamicOption", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownCreateRenderer.prototype, "sourceForRender", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownCreateRenderer.prototype, "appenderController", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownCreateRenderer.prototype, "childrenController", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownCreateRenderer.prototype, "renderModeController", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownCreateRenderer.prototype, "createEventEmitter", void 0);
