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 { Fragment, h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
export class VegaDropdownListRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.defaultMaxHeightOfItemsContainer = 400;
  }
  /**
   * The below method is e2e-test covered in
   * @see{module:vega-dropdown-keyboard-control-e2e}
   */
  /* istanbul ignore next */
  getVirtualScrollRef() {
    return this.virtualScrollRef;
  }
  getTemplateContainerRef() {
    return this.templateContainerRef;
  }
  renderBySource() {
    return (h(Fragment, null,
      this.renderLoading(),
      this.renderDropdownListBySource()));
  }
  renderBySlot() {
    return (h(Fragment, null,
      this.renderLoading(),
      this.renderDropdownListBySlot()));
  }
  renderLoading() {
    return (h("div", { class: {
        'vega-dropdown-loading': true,
        'v-hidden': !this.isLoading,
      } },
      h("vega-flex", { gap: "size-8", direction: "row" },
        h("vega-loading-indicator", { size: "small" }),
        h("span", null, "Loading"))));
  }
  renderDropdownListBySource() {
    return (h(Fragment, null,
      h("div", { class: {
          'vega-dropdown-empty-list': true,
          'v-hidden': this.isLoading || this.sourceForRender.length > 0,
        } }, this.searchString
        ? this.translationSlimmer.t(this.searchNoResultsText)
        : this.translationSlimmer.t('No options')),
      h("ul", { role: "menu", class: {
          'v-hidden': this.isLoading || this.sourceForRender.length === 0,
        } },
        h("vega-virtual-scroll", { source: this.sourceForRender, 
          /* eslint-disable-next-line react/jsx-no-bind */
          renderItem: (item, index, fixHeight) => {
            return item['children']
              ? this.groupLevelRenderer.render(item, index, fixHeight)
              : this.itemLevelRenderer.render(item, fixHeight);
          }, viewportMaxHeight: this.defaultMaxHeightOfItemsContainer, ref: (e) => (this.virtualScrollRef = e), isLoading: this.isLazyLoading, virtualizationThreshold: this.virtualizationThreshold }))));
  }
  renderDropdownListBySlot() {
    return (h("ul", { role: "menu", class: {
        [`vega-dropdown-item-display-${this.itemDisplayRule}`]: true,
        ['v-hidden']: this.isLoading,
      }, ref: (ref) => (this.templateContainerRef = ref), onScroll: this.scrollableController.onScroll },
      h("slot", { name: "items" })));
  }
}
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "isLoading", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "searchString", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "itemDisplayRule", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "sourceForRender", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "itemLevelRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "groupLevelRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "isLazyLoading", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "isDropdownShow", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "searchNoResultsText", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "renderModeController", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "scrollableController", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "translationSlimmer", void 0);
__decorate([
  MapToComponentField()
], VegaDropdownListRenderer.prototype, "virtualizationThreshold", void 0);
