/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/cdk/scrolling";
import * as i3 from "ng-zorro-antd/empty";
import * as i4 from "./option-item-group.component";
import * as i5 from "./option-item.component";
function NzOptionContainerComponent_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 4);
    i0.ɵɵelement(1, "nz-embed-empty", 5);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var ctx_r1205 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("specificContent", ctx_r1205.notFoundContent);
} }
function NzOptionContainerComponent_div_3_nz_option_item_group_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "nz-option-item-group", 9);
} if (rf & 2) {
    var item_r1208 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵproperty("nzLabel", item_r1208.groupLabel);
} }
function NzOptionContainerComponent_div_3_nz_option_item_3_Template(rf, ctx) { if (rf & 1) {
    var _r1213 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "nz-option-item", 10);
    i0.ɵɵlistener("itemHover", function NzOptionContainerComponent_div_3_nz_option_item_3_Template_nz_option_item_itemHover_0_listener($event) { i0.ɵɵrestoreView(_r1213); var ctx_r1212 = i0.ɵɵnextContext(2); return ctx_r1212.onItemHover($event); })("itemClick", function NzOptionContainerComponent_div_3_nz_option_item_3_Template_nz_option_item_itemClick_0_listener($event) { i0.ɵɵrestoreView(_r1213); var ctx_r1214 = i0.ɵɵnextContext(2); return ctx_r1214.onItemClick($event); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var item_r1208 = i0.ɵɵnextContext().$implicit;
    var ctx_r1210 = i0.ɵɵnextContext();
    i0.ɵɵproperty("icon", ctx_r1210.menuItemSelectedIcon)("customContent", item_r1208.nzCustomContent)("template", item_r1208.template)("grouped", !!item_r1208.groupLabel)("disabled", item_r1208.nzDisabled)("showState", ctx_r1210.mode === "tags" || ctx_r1210.mode === "multiple")("label", item_r1208.nzLabel)("compareWith", ctx_r1210.compareWith)("activatedValue", ctx_r1210.activatedValue)("listOfSelectedValue", ctx_r1210.listOfSelectedValue)("value", item_r1208.nzValue);
} }
function NzOptionContainerComponent_div_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementContainerStart(1, 6);
    i0.ɵɵtemplate(2, NzOptionContainerComponent_div_3_nz_option_item_group_2_Template, 1, 1, "nz-option-item-group", 7);
    i0.ɵɵtemplate(3, NzOptionContainerComponent_div_3_nz_option_item_3_Template, 1, 11, "nz-option-item", 8);
    i0.ɵɵelementContainerEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var item_r1208 = ctx.$implicit;
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngSwitch", item_r1208.type);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngSwitchCase", "group");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngSwitchCase", "item");
} }
function NzOptionContainerComponent_ng_template_4_Template(rf, ctx) { }
var NzOptionContainerComponent = /** @class */ (function () {
    function NzOptionContainerComponent() {
        this.notFoundContent = null;
        this.menuItemSelectedIcon = null;
        this.dropdownRender = null;
        this.activatedValue = null;
        this.listOfSelectedValue = [];
        this.mode = 'default';
        this.listOfContainerItem = [];
        this.itemClick = new EventEmitter();
        this.itemHover = new EventEmitter();
        this.scrollToBottom = new EventEmitter();
        this.scrolledIndex = 0;
        this.itemSize = 32;
        this.maxItemLength = 8;
    }
    NzOptionContainerComponent.prototype.onItemClick = function (value) {
        this.itemClick.emit(value);
    };
    NzOptionContainerComponent.prototype.onItemHover = function (value) {
        // TODO: bug when mouse inside the option container & keydown
        this.itemHover.emit(value);
    };
    NzOptionContainerComponent.prototype.trackValue = function (_index, option) {
        return option.key;
    };
    NzOptionContainerComponent.prototype.onScrolledIndexChange = function (index) {
        this.scrolledIndex = index;
        if (index === this.listOfContainerItem.length - this.maxItemLength) {
            this.scrollToBottom.emit();
        }
    };
    NzOptionContainerComponent.prototype.ngOnChanges = function (changes) {
        var _this = this;
        var listOfContainerItem = changes.listOfContainerItem, activatedValue = changes.activatedValue;
        if (listOfContainerItem || activatedValue) {
            var index = this.listOfContainerItem.findIndex(function (item) { return _this.compareWith(item.key, _this.activatedValue); });
            if (index < this.scrolledIndex || index >= this.scrolledIndex + this.maxItemLength) {
                this.cdkVirtualScrollViewport.scrollToIndex(index || 0);
            }
        }
    };
    /** @nocollapse */ NzOptionContainerComponent.ɵfac = function NzOptionContainerComponent_Factory(t) { return new (t || NzOptionContainerComponent)(); };
    /** @nocollapse */ NzOptionContainerComponent.ɵcmp = i0.ɵɵdefineComponent({ type: NzOptionContainerComponent, selectors: [["nz-option-container"]], viewQuery: function NzOptionContainerComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵstaticViewQuery(CdkVirtualScrollViewport, true);
        } if (rf & 2) {
            var _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.cdkVirtualScrollViewport = _t.first);
        } }, hostVars: 2, hostBindings: function NzOptionContainerComponent_HostBindings(rf, ctx) { if (rf & 2) {
            i0.ɵɵclassProp("ant-select-dropdown", true);
        } }, inputs: { notFoundContent: "notFoundContent", menuItemSelectedIcon: "menuItemSelectedIcon", dropdownRender: "dropdownRender", activatedValue: "activatedValue", listOfSelectedValue: "listOfSelectedValue", compareWith: "compareWith", mode: "mode", listOfContainerItem: "listOfContainerItem" }, outputs: { itemClick: "itemClick", itemHover: "itemHover", scrollToBottom: "scrollToBottom" }, exportAs: ["nzOptionContainer"], features: [i0.ɵɵNgOnChangesFeature], decls: 5, vars: 11, consts: [["class", "ant-select-item-empty", 4, "ngIf"], [3, "itemSize", "maxBufferPx", "minBufferPx", "scrolledIndexChange"], [4, "cdkVirtualFor", "cdkVirtualForOf", "cdkVirtualForTrackBy"], [3, "ngTemplateOutlet"], [1, "ant-select-item-empty"], ["nzComponentName", "select", 3, "specificContent"], [3, "ngSwitch"], [3, "nzLabel", 4, "ngSwitchCase"], [3, "icon", "customContent", "template", "grouped", "disabled", "showState", "label", "compareWith", "activatedValue", "listOfSelectedValue", "value", "itemHover", "itemClick", 4, "ngSwitchCase"], [3, "nzLabel"], [3, "icon", "customContent", "template", "grouped", "disabled", "showState", "label", "compareWith", "activatedValue", "listOfSelectedValue", "value", "itemHover", "itemClick"]], template: function NzOptionContainerComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div");
            i0.ɵɵtemplate(1, NzOptionContainerComponent_div_1_Template, 2, 1, "div", 0);
            i0.ɵɵelementStart(2, "cdk-virtual-scroll-viewport", 1);
            i0.ɵɵlistener("scrolledIndexChange", function NzOptionContainerComponent_Template_cdk_virtual_scroll_viewport_scrolledIndexChange_2_listener($event) { return ctx.onScrolledIndexChange($event); });
            i0.ɵɵtemplate(3, NzOptionContainerComponent_div_3_Template, 4, 3, "div", 2);
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(4, NzOptionContainerComponent_ng_template_4_Template, 0, 0, "ng-template", 3);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.listOfContainerItem.length === 0);
            i0.ɵɵadvance(1);
            i0.ɵɵstyleProp("height", ctx.listOfContainerItem.length * ctx.itemSize, "px")("max-height", ctx.itemSize * ctx.maxItemLength, "px");
            i0.ɵɵproperty("itemSize", ctx.itemSize)("maxBufferPx", ctx.itemSize * ctx.maxItemLength)("minBufferPx", ctx.itemSize * ctx.maxItemLength);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("cdkVirtualForOf", ctx.listOfContainerItem)("cdkVirtualForTrackBy", ctx.trackValue);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngTemplateOutlet", ctx.dropdownRender);
        } }, directives: [i1.NgIf, i2.CdkVirtualScrollViewport, i2.CdkFixedSizeVirtualScroll, i2.CdkVirtualForOf, i1.NgTemplateOutlet, i3.NzEmbedEmptyComponent, i1.NgSwitch, i1.NgSwitchCase, i4.NzOptionItemGroupComponent, i5.NzOptionItemComponent], encapsulation: 2, changeDetection: 0 });
    return NzOptionContainerComponent;
}());
export { NzOptionContainerComponent };
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(NzOptionContainerComponent, [{
        type: Component,
        args: [{
                selector: 'nz-option-container',
                exportAs: 'nzOptionContainer',
                changeDetection: ChangeDetectionStrategy.OnPush,
                encapsulation: ViewEncapsulation.None,
                preserveWhitespaces: false,
                template: "\n    <div>\n      <div *ngIf=\"listOfContainerItem.length === 0\" class=\"ant-select-item-empty\">\n        <nz-embed-empty nzComponentName=\"select\" [specificContent]=\"notFoundContent\"></nz-embed-empty>\n      </div>\n      <cdk-virtual-scroll-viewport\n        [itemSize]=\"itemSize\"\n        [maxBufferPx]=\"itemSize * maxItemLength\"\n        [minBufferPx]=\"itemSize * maxItemLength\"\n        (scrolledIndexChange)=\"onScrolledIndexChange($event)\"\n        [style.height.px]=\"listOfContainerItem.length * itemSize\"\n        [style.max-height.px]=\"itemSize * maxItemLength\"\n      >\n        <div *cdkVirtualFor=\"let item of listOfContainerItem; trackBy: trackValue\">\n          <ng-container [ngSwitch]=\"item.type\">\n            <nz-option-item-group *ngSwitchCase=\"'group'\" [nzLabel]=\"item.groupLabel\"></nz-option-item-group>\n            <nz-option-item\n              *ngSwitchCase=\"'item'\"\n              [icon]=\"menuItemSelectedIcon\"\n              [customContent]=\"item.nzCustomContent\"\n              [template]=\"item.template\"\n              [grouped]=\"!!item.groupLabel\"\n              [disabled]=\"item.nzDisabled\"\n              [showState]=\"mode === 'tags' || mode === 'multiple'\"\n              [label]=\"item.nzLabel\"\n              [compareWith]=\"compareWith\"\n              [activatedValue]=\"activatedValue\"\n              [listOfSelectedValue]=\"listOfSelectedValue\"\n              [value]=\"item.nzValue\"\n              (itemHover)=\"onItemHover($event)\"\n              (itemClick)=\"onItemClick($event)\"\n            ></nz-option-item>\n          </ng-container>\n        </div>\n      </cdk-virtual-scroll-viewport>\n      <ng-template [ngTemplateOutlet]=\"dropdownRender\"></ng-template>\n    </div>\n  ",
                host: {
                    '[class.ant-select-dropdown]': 'true'
                }
            }]
    }], null, { notFoundContent: [{
            type: Input
        }], menuItemSelectedIcon: [{
            type: Input
        }], dropdownRender: [{
            type: Input
        }], activatedValue: [{
            type: Input
        }], listOfSelectedValue: [{
            type: Input
        }], compareWith: [{
            type: Input
        }], mode: [{
            type: Input
        }], listOfContainerItem: [{
            type: Input
        }], itemClick: [{
            type: Output
        }], itemHover: [{
            type: Output
        }], scrollToBottom: [{
            type: Output
        }], cdkVirtualScrollViewport: [{
            type: ViewChild,
            args: [CdkVirtualScrollViewport, { static: true }]
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 