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 VegaVirtualScrollRenderer extends VegaSlimmer {
  getContainerRef() {
    return this.virtualScrollContainerRef;
  }
  render() {
    return (h("div", { style: { maxHeight: `${this.viewportMaxHeight}px`, overflow: 'auto' }, class: "virtual-scroll-container", ref: (el) => (this.virtualScrollContainerRef = el) }, this.modeController.getMode() === 'normal'
      ? this.renderNormal()
      : this.renderVirtualScroll()));
  }
  renderNormal() {
    return (h(Fragment, null,
      this.source.map((item, index) => {
        return this.renderItem(item, index);
      }),
      this.loadingRenderer.render()));
  }
  renderVirtualScroll() {
    return (h("div", { style: {
        height: `${this.source.length * this.approxItemHeight}px`,
        position: 'relative',
      } },
      h("div", { class: "virtual-scroll-block", style: {
          transform: `translateY(${this.positionConfig.transformY}px)`,
        } },
        this.source
          .slice(this.positionConfig.startIndex, this.positionConfig.viewportStartIndex)
          .map((item, index) => {
          return this.renderItem(item, this.positionConfig.startIndex + index, this.approxItemHeight);
        }),
        this.source
          .slice(this.positionConfig.viewportStartIndex, this.positionConfig.endIndex)
          .map((item, index) => {
          return this.renderItem(item, this.positionConfig.viewportStartIndex + index);
        }),
        this.loadingRenderer.render())));
  }
}
__decorate([
  MapToComponentField()
], VegaVirtualScrollRenderer.prototype, "source", void 0);
__decorate([
  MapToComponentField()
], VegaVirtualScrollRenderer.prototype, "renderItem", void 0);
__decorate([
  MapToComponentField()
], VegaVirtualScrollRenderer.prototype, "approxItemHeight", void 0);
__decorate([
  MapToComponentField()
], VegaVirtualScrollRenderer.prototype, "positionConfig", void 0);
__decorate([
  MapToComponentField()
], VegaVirtualScrollRenderer.prototype, "viewportMaxHeight", void 0);
__decorate([
  MapToComponentField()
], VegaVirtualScrollRenderer.prototype, "modeController", void 0);
__decorate([
  MapToComponentField()
], VegaVirtualScrollRenderer.prototype, "loadingRenderer", void 0);
