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 { Component, Prop, Element, Watch, Method, Host, h, State } from '@stencil/core';
import { InjectVegaGlobalSlimmer, InjectVegaSlimmer, methodPlaceholder, } from 'vega-slimmer/core';
import { VegaVirtualScrollPositionController } from './slimmers/controllers/vega-virtual-scroll-position-controller';
import { VegaVirtualScrollScrollableController } from './slimmers/controllers/vega-virtual-scroll-scrollable-controller';
import { VegaVirtualScrollRenderer } from './slimmers/renderers/vega-virtual-scroll-renderer';
import { sanitizeVegaComponent } from '../../utils/component';
import { VegaVirtualScrollModeController } from './slimmers/controllers/vega-virtual-scroll-mode-controller';
import { VegaVirtualScrollLoadingIndicatorRenderer } from './slimmers/renderers/vega-virtual-scroll-loading-indicator-renderer';
import { VegaComponentUsageRuntimeMetricsSlimmer } from '../../helpers/slimmers/component-usage-runtime-metrics';
/**
 * @vegaVersion 1.13.0
 */
/**
 * Items that really need to be rendered include header, viewport and footer.
 * The number of header and footer is determined by extendItemsCount,
 * and the number of viewport is the viewportMaxHeight divided by approxItemHeight.
 */
export class VegaVirtualScroll {
  constructor() {
    this.globalSlimmers = {};
    this.modeController = new VegaVirtualScrollModeController();
    this.positionController = new VegaVirtualScrollPositionController();
    this.scrollableController = new VegaVirtualScrollScrollableController();
    this.renderer = new VegaVirtualScrollRenderer();
    this.loadingRenderer = new VegaVirtualScrollLoadingIndicatorRenderer();
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    this.scrollTop = 0;
    /** The all items of source *
     * @vegaVersion 1.13.0
     */
    this.source = [];
    /** The approximate height of each item *
     * @vegaVersion 1.13.0
     */
    this.approxItemHeight = 40;
    /** The max height of viewport *
     * @vegaVersion 1.13.0
     */
    this.viewportMaxHeight = 320;
    /**
     * Determines whether the dropdown displays a loading status.
     *
     * @vegaVersion 2.3.0
     */
    this.isLoading = false;
    /**
     * The count of the source that will be used as the threshold for determining whether to use virtual scrolling.
     * If the count of source exceeds this threshold, we employ virtual scrolling. Otherwise, normal item rendering is used
     * If the value is 0, it means we will disable the virtualization all the time.
     *
     * @vegaVersion 2.3.0
     */
    this.virtualizationThreshold = 60;
    /** We set this key to check the source is really change and should refresh virtual scroll *
     * @vegaVersion 1.26.0
     */
    this.sourceItemIdentifier = 'key';
  }
  watchScrollTop() {
    methodPlaceholder();
  }
  watchSourceChange(newValue, oldValue) {
    methodPlaceholder(newValue, oldValue);
  }
  watchApproxItemHeight() {
    methodPlaceholder();
  }
  watchViewportMaxHeight() {
    methodPlaceholder();
  }
  watchVirtualizationThreshold() {
    methodPlaceholder();
  }
  /**
   * Scroll to the index of the item in the list by setting the scrollTop property of the virtual scroll
   * container to the index of the item multiplied by the approximate height of each item in the list.
   *
   * @vegaVersion 1.13.0
   */
  async scrollToIndex(index) {
    methodPlaceholder(index);
  }
  render() {
    return sanitizeVegaComponent(h(Host, null, this.renderer.render()), this.host);
  }
  static get is() { return "vega-virtual-scroll"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["vega-virtual-scroll.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["vega-virtual-scroll.css"]
  }; }
  static get properties() { return {
    "source": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "SourceItemType[]",
        "resolved": "DropdownSourceItem[]",
        "references": {
          "SourceItemType": {
            "location": "import",
            "path": "./types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.13.0"
          }],
        "text": "The all items of source *"
      },
      "defaultValue": "[]"
    },
    "approxItemHeight": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.13.0"
          }],
        "text": "The approximate height of each item *"
      },
      "attribute": "approx-item-height",
      "reflect": false,
      "defaultValue": "40"
    },
    "viewportMaxHeight": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.13.0"
          }],
        "text": "The max height of viewport *"
      },
      "attribute": "viewport-max-height",
      "reflect": false,
      "defaultValue": "320"
    },
    "isLoading": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.3.0"
          }],
        "text": "Determines whether the dropdown displays a loading status."
      },
      "attribute": "is-loading",
      "reflect": false,
      "defaultValue": "false"
    },
    "virtualizationThreshold": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.3.0"
          }],
        "text": "The count of the source that will be used as the threshold for determining whether to use virtual scrolling.\nIf the count of source exceeds this threshold, we employ virtual scrolling. Otherwise, normal item rendering is used\nIf the value is 0, it means we will disable the virtualization all the time."
      },
      "attribute": "virtualization-threshold",
      "reflect": false,
      "defaultValue": "60"
    },
    "sourceItemIdentifier": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.26.0"
          }],
        "text": "We set this key to check the source is really change and should refresh virtual scroll *"
      },
      "attribute": "source-item-identifier",
      "reflect": false,
      "defaultValue": "'key'"
    },
    "renderItem": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "(item: SourceItemType, index?: number, fixHeight?: number) => HTMLElement",
        "resolved": "(item: DropdownSourceItem, index?: number, fixHeight?: number) => HTMLElement",
        "references": {
          "SourceItemType": {
            "location": "import",
            "path": "./types"
          },
          "HTMLElement": {
            "location": "global"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.13.0"
          }],
        "text": "The method of render item.\nYou should bind to the host component then you can set the css and event of item on the host component.\nexample: <vega-virtual-scroll renderItem={this.renderSourceItem.bind(this)}></vega-virtual-scroll> .\nYou should watch the fixHeight, if it have value, you should set {height: `${fixHeight}px`, boxSizing: 'border-box', overflow: 'hidden'} to you item,\notherwise, you can do nothing."
      }
    }
  }; }
  static get states() { return {
    "positionConfig": {},
    "scrollTop": {}
  }; }
  static get methods() { return {
    "scrollToIndex": {
      "complexType": {
        "signature": "(index: number) => Promise<void>",
        "parameters": [{
            "tags": [],
            "text": ""
          }],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "Scroll to the index of the item in the list by setting the scrollTop property of the virtual scroll\ncontainer to the index of the item multiplied by the approximate height of each item in the list.",
        "tags": [{
            "name": "vegaVersion",
            "text": "1.13.0"
          }]
      }
    }
  }; }
  static get elementRef() { return "host"; }
  static get watchers() { return [{
      "propName": "scrollTop",
      "methodName": "watchScrollTop"
    }, {
      "propName": "source",
      "methodName": "watchSourceChange"
    }, {
      "propName": "approxItemHeight",
      "methodName": "watchApproxItemHeight"
    }, {
      "propName": "viewportMaxHeight",
      "methodName": "watchViewportMaxHeight"
    }, {
      "propName": "virtualizationThreshold",
      "methodName": "watchVirtualizationThreshold"
    }]; }
}
__decorate([
  InjectVegaGlobalSlimmer()
], VegaVirtualScroll.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaVirtualScroll.prototype, "modeController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaVirtualScroll.prototype, "positionController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaVirtualScroll.prototype, "scrollableController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaVirtualScroll.prototype, "renderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaVirtualScroll.prototype, "loadingRenderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaVirtualScroll.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
