import { NgForOf, NgClass, NgIf, NgTemplateOutlet, NgStyle, CommonModule } from '@angular/common';
import { ɵɵelement, ɵɵnextContext, ɵɵproperty, ɵɵdefineComponent, ɵɵNgOnChangesFeature, ɵɵelementStart, ɵɵtemplate, ɵɵelementEnd, ɵɵclassMapInterpolate1, ɵɵadvance, ɵsetClassMetadata, Component, ChangeDetectionStrategy, Input, ɵɵpureFunction2, ɵɵclassProp, ɵɵelementContainerStart, ɵɵelementContainerEnd, ɵɵgetCurrentView, ɵɵlistener, ɵɵrestoreView, ɵɵpipe, ɵɵpipeBind4, ɵɵsanitizeHtml, EventEmitter, TemplateRef, ɵɵdirectiveInject, NgZone, Renderer2, ElementRef, ChangeDetectorRef, ɵɵviewQuery, ɵɵqueryRefresh, ɵɵloadQuery, ɵɵstyleProp, ɵɵpropertyInterpolate, ɵɵattribute, Host, Optional, ViewChild, Output, HostListener, ɵɵdefineInjectable, Injectable, ɵɵstaticContentQuery, ɵɵProvidersFeature, SkipSelf, forwardRef, ɵɵInheritDefinitionFeature, ContentChild, ɵɵdefineNgModule, ɵɵdefineInjector, ɵɵsetNgModuleScope, NgModule } from '@angular/core';
import { NzTreeBaseService, NzNoAnimationDirective, NzHighlightPipe, treeCollapseMotion, InputBoolean, NzTreeBase, flattenTreeData, NzConfigService, NzTreeHigherOrderServiceToken, WithConfig, NzOutletModule, NzNoAnimationModule, NzHighlightModule } from 'ng-zorro-antd/core';
import { NzIconDirective, NzIconModule } from 'ng-zorro-antd/icon';
import { __decorate, __metadata } from 'tslib';
import { Subject, fromEvent } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NG_VALUE_ACCESSOR } from '@angular/forms';

/**
 * @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
 */
function NzTreeIndentComponent_span_1_Template(rf, ctx) { if (rf & 1) {
    ɵɵelement(0, "span", 2);
} if (rf & 2) {
    const index_r1048 = ctx.index;
    const ctx_r1046 = ɵɵnextContext();
    ɵɵproperty("ngClass", ctx_r1046.unitMapOfClass(index_r1048));
} }
class NzTreeIndentComponent {
    constructor() {
        this.listOfUnit = [];
    }
    unitMapOfClass(index) {
        return {
            [`${this.nzPrefixCls}-indent-unit`]: true,
            [`${this.nzPrefixCls}-indent-unit-start`]: this.nzIsStart[index + 1],
            [`${this.nzPrefixCls}-indent-unit-end`]: this.nzIsEnd[index + 1]
        };
    }
    ngOnInit() { }
    ngOnChanges(changes) {
        const { nzTreeLevel } = changes;
        if (nzTreeLevel) {
            this.listOfUnit = [...new Array(nzTreeLevel.currentValue || 0)];
        }
    }
}
/** @nocollapse */ NzTreeIndentComponent.ɵfac = function NzTreeIndentComponent_Factory(t) { return new (t || NzTreeIndentComponent)(); };
/** @nocollapse */ NzTreeIndentComponent.ɵcmp = ɵɵdefineComponent({ type: NzTreeIndentComponent, selectors: [["nz-tree-indent"]], inputs: { nzPrefixCls: "nzPrefixCls", nzTreeLevel: "nzTreeLevel", nzIsStart: "nzIsStart", nzIsEnd: "nzIsEnd" }, exportAs: ["nzTreeIndent"], features: [ɵɵNgOnChangesFeature], decls: 2, vars: 4, consts: [["aria-hidden", "true"], [3, "ngClass", 4, "ngFor", "ngForOf"], [3, "ngClass"]], template: function NzTreeIndentComponent_Template(rf, ctx) { if (rf & 1) {
        ɵɵelementStart(0, "span", 0);
        ɵɵtemplate(1, NzTreeIndentComponent_span_1_Template, 1, 1, "span", 1);
        ɵɵelementEnd();
    } if (rf & 2) {
        ɵɵclassMapInterpolate1("", ctx.nzPrefixCls, "-indent");
        ɵɵadvance(1);
        ɵɵproperty("ngForOf", ctx.listOfUnit);
    } }, directives: [NgForOf, NgClass], encapsulation: 2, changeDetection: 0 });
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzTreeIndentComponent, [{
        type: Component,
        args: [{
                selector: 'nz-tree-indent',
                exportAs: 'nzTreeIndent',
                template: `
    <span aria-hidden="true" class="{{ nzPrefixCls }}-indent">
      <span *ngFor="let i of listOfUnit; let index = index" [ngClass]="unitMapOfClass(index)"></span>
    </span>
  `,
                changeDetection: ChangeDetectionStrategy.OnPush,
                preserveWhitespaces: false
            }]
    }], null, { nzPrefixCls: [{
            type: Input
        }], nzTreeLevel: [{
            type: Input
        }], nzIsStart: [{
            type: Input
        }], nzIsEnd: [{
            type: Input
        }] }); })();

const _c0 = ["dragElement"];
function NzTreeNodeComponent_ng_container_3_ng_container_2_ng_container_1_1_ng_template_0_Template(rf, ctx) { }
const _c1 = function (a0, a1) { return { $implicit: a0, origin: a1 }; };
function NzTreeNodeComponent_ng_container_3_ng_container_2_ng_container_1_1_Template(rf, ctx) { if (rf & 1) {
    ɵɵtemplate(0, NzTreeNodeComponent_ng_container_3_ng_container_2_ng_container_1_1_ng_template_0_Template, 0, 0, "ng-template", 5);
} if (rf & 2) {
    const ctx_r1058 = ɵɵnextContext(4);
    ɵɵproperty("ngTemplateOutlet", ctx_r1058.nzExpandedIcon)("ngTemplateOutletContext", ɵɵpureFunction2(2, _c1, ctx_r1058.nzTreeNode, ctx_r1058.nzTreeNode.origin));
} }
function NzTreeNodeComponent_ng_container_3_ng_container_2_ng_container_1_i_2_Template(rf, ctx) { if (rf & 1) {
    ɵɵelement(0, "i", 9);
} if (rf & 2) {
    const ctx_r1059 = ɵɵnextContext(4);
    ɵɵclassProp("ant-select-tree-switcher-icon", ctx_r1059.nzSelectMode)("ant-tree-switcher-icon", !ctx_r1059.nzSelectMode);
} }
function NzTreeNodeComponent_ng_container_3_ng_container_2_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    ɵɵelementContainerStart(0);
    ɵɵtemplate(1, NzTreeNodeComponent_ng_container_3_ng_container_2_ng_container_1_1_Template, 1, 5, undefined, 3);
    ɵɵtemplate(2, NzTreeNodeComponent_ng_container_3_ng_container_2_ng_container_1_i_2_Template, 1, 4, "i", 8);
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1056 = ɵɵnextContext(3);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1056.isTemplateRef(ctx_r1056.nzExpandedIcon));
    ɵɵadvance(1);
    ɵɵproperty("ngIf", !ctx_r1056.isTemplateRef(ctx_r1056.nzExpandedIcon));
} }
function NzTreeNodeComponent_ng_container_3_ng_container_2_i_2_Template(rf, ctx) { if (rf & 1) {
    ɵɵelement(0, "i", 10);
} if (rf & 2) {
    ɵɵproperty("nzSpin", true);
} }
function NzTreeNodeComponent_ng_container_3_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    ɵɵelementContainerStart(0);
    ɵɵtemplate(1, NzTreeNodeComponent_ng_container_3_ng_container_2_ng_container_1_Template, 3, 2, "ng-container", 3);
    ɵɵtemplate(2, NzTreeNodeComponent_ng_container_3_ng_container_2_i_2_Template, 1, 1, "i", 7);
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1054 = ɵɵnextContext(2);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", !ctx_r1054.nzTreeNode.isLoading);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1054.nzTreeNode.isLoading);
} }
function NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_1_ng_template_0_Template(rf, ctx) { }
function NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_1_Template(rf, ctx) { if (rf & 1) {
    ɵɵtemplate(0, NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_1_ng_template_0_Template, 0, 0, "ng-template", 5);
} if (rf & 2) {
    const ctx_r1063 = ɵɵnextContext(4);
    ɵɵproperty("ngTemplateOutlet", ctx_r1063.nzExpandedIcon)("ngTemplateOutletContext", ɵɵpureFunction2(2, _c1, ctx_r1063.nzTreeNode, ctx_r1063.nzTreeNode.origin));
} }
function NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_ng_container_2_i_1_Template(rf, ctx) { if (rf & 1) {
    ɵɵelement(0, "i", 13);
} if (rf & 2) {
    const ctx_r1066 = ɵɵnextContext(5);
    ɵɵproperty("nzType", ctx_r1066.isSwitcherOpen ? "minus-square" : "plus-square");
} }
function NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_ng_container_2_i_2_Template(rf, ctx) { if (rf & 1) {
    ɵɵelement(0, "i", 14);
} }
function NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    ɵɵelementContainerStart(0);
    ɵɵtemplate(1, NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_ng_container_2_i_1_Template, 1, 1, "i", 11);
    ɵɵtemplate(2, NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_ng_container_2_i_2_Template, 1, 0, "i", 12);
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1064 = ɵɵnextContext(4);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1064.isShowLineIcon);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", !ctx_r1064.isShowLineIcon);
} }
function NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    ɵɵelementContainerStart(0);
    ɵɵtemplate(1, NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_1_Template, 1, 5, undefined, 3);
    ɵɵtemplate(2, NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_ng_container_2_Template, 3, 2, "ng-container", 3);
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1061 = ɵɵnextContext(3);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1061.isTemplateRef(ctx_r1061.nzExpandedIcon));
    ɵɵadvance(1);
    ɵɵproperty("ngIf", !ctx_r1061.isTemplateRef(ctx_r1061.nzExpandedIcon));
} }
function NzTreeNodeComponent_ng_container_3_ng_container_3_i_2_Template(rf, ctx) { if (rf & 1) {
    ɵɵelement(0, "i", 10);
} if (rf & 2) {
    ɵɵproperty("nzSpin", true);
} }
function NzTreeNodeComponent_ng_container_3_ng_container_3_Template(rf, ctx) { if (rf & 1) {
    ɵɵelementContainerStart(0);
    ɵɵtemplate(1, NzTreeNodeComponent_ng_container_3_ng_container_3_ng_container_1_Template, 3, 2, "ng-container", 3);
    ɵɵtemplate(2, NzTreeNodeComponent_ng_container_3_ng_container_3_i_2_Template, 1, 1, "i", 7);
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1055 = ɵɵnextContext(2);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", !ctx_r1055.nzTreeNode.isLoading);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1055.nzTreeNode.isLoading);
} }
function NzTreeNodeComponent_ng_container_3_Template(rf, ctx) { if (rf & 1) {
    const _r1069 = ɵɵgetCurrentView();
    ɵɵelementContainerStart(0);
    ɵɵelementStart(1, "span", 6);
    ɵɵlistener("click", function NzTreeNodeComponent_ng_container_3_Template_span_click_1_listener($event) { ɵɵrestoreView(_r1069); const ctx_r1068 = ɵɵnextContext(); return ctx_r1068.clickExpand($event); });
    ɵɵtemplate(2, NzTreeNodeComponent_ng_container_3_ng_container_2_Template, 3, 2, "ng-container", 3);
    ɵɵtemplate(3, NzTreeNodeComponent_ng_container_3_ng_container_3_Template, 3, 2, "ng-container", 3);
    ɵɵelementEnd();
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1050 = ɵɵnextContext();
    ɵɵadvance(1);
    ɵɵproperty("ngClass", ctx_r1050.nzNodeSwitcherClass);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1050.isShowSwitchIcon);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1050.nzShowLine);
} }
function NzTreeNodeComponent_ng_container_4_Template(rf, ctx) { if (rf & 1) {
    const _r1071 = ɵɵgetCurrentView();
    ɵɵelementContainerStart(0);
    ɵɵelementStart(1, "span", 6);
    ɵɵlistener("click", function NzTreeNodeComponent_ng_container_4_Template_span_click_1_listener($event) { ɵɵrestoreView(_r1071); const ctx_r1070 = ɵɵnextContext(); return ctx_r1070.clickCheckBox($event); });
    ɵɵelement(2, "span");
    ɵɵelementEnd();
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1051 = ɵɵnextContext();
    ɵɵadvance(1);
    ɵɵproperty("ngClass", ctx_r1051.nzNodeCheckboxClass);
    ɵɵadvance(1);
    ɵɵclassProp("ant-tree-checkbox-inner", !ctx_r1051.nzSelectMode)("ant-select-tree-checkbox-inner", ctx_r1051.nzSelectMode);
} }
function NzTreeNodeComponent_ng_template_6_Template(rf, ctx) { }
function NzTreeNodeComponent_ng_container_7_span_1_i_2_Template(rf, ctx) { if (rf & 1) {
    ɵɵelement(0, "i", 19);
} if (rf & 2) {
    const ctx_r1073 = ɵɵnextContext(3);
    ɵɵproperty("nzType", ctx_r1073.nzIcon);
} }
function NzTreeNodeComponent_ng_container_7_span_1_Template(rf, ctx) { if (rf & 1) {
    ɵɵelementStart(0, "span", 17);
    ɵɵelementStart(1, "span", 17);
    ɵɵtemplate(2, NzTreeNodeComponent_ng_container_7_span_1_i_2_Template, 1, 1, "i", 18);
    ɵɵelementEnd();
    ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1072 = ɵɵnextContext(2);
    ɵɵclassProp("ant-tree-icon__open", ctx_r1072.isSwitcherOpen)("ant-tree-icon__close", ctx_r1072.isSwitcherClose)("ant-tree-icon_loading", ctx_r1072.nzTreeNode.isLoading);
    ɵɵproperty("ngClass", ctx_r1072.nzNodeContentLoadingClass);
    ɵɵadvance(1);
    ɵɵproperty("ngClass", ctx_r1072.nzNodeContentIconClass);
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1072.nzIcon);
} }
function NzTreeNodeComponent_ng_container_7_Template(rf, ctx) { if (rf & 1) {
    ɵɵelementContainerStart(0);
    ɵɵtemplate(1, NzTreeNodeComponent_ng_container_7_span_1_Template, 3, 9, "span", 15);
    ɵɵelement(2, "span", 16);
    ɵɵpipe(3, "nzHighlight");
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1053 = ɵɵnextContext();
    ɵɵadvance(1);
    ɵɵproperty("ngIf", ctx_r1053.nzTreeNode.icon && ctx_r1053.nzShowIcon);
    ɵɵadvance(1);
    ɵɵproperty("innerHTML", ɵɵpipeBind4(3, 2, ctx_r1053.nzTreeNode.title, ctx_r1053.matchedValue, "", "font-highlight"), ɵɵsanitizeHtml);
} }
class NzTreeNodeComponent {
    constructor(nzTreeService, ngZone, renderer, elRef, cdr, noAnimation) {
        this.nzTreeService = nzTreeService;
        this.ngZone = ngZone;
        this.renderer = renderer;
        this.elRef = elRef;
        this.cdr = cdr;
        this.noAnimation = noAnimation;
        this.nzHideUnMatched = false;
        this.nzNoAnimation = false;
        this.nzSelectMode = false;
        this.nzShowIcon = false;
        this.nzSearchValue = '';
        this.nzClick = new EventEmitter();
        this.nzDblClick = new EventEmitter();
        this.nzContextMenu = new EventEmitter();
        this.nzCheckBoxChange = new EventEmitter();
        this.nzExpandChange = new EventEmitter();
        this.nzOnDragStart = new EventEmitter();
        this.nzOnDragEnter = new EventEmitter();
        this.nzOnDragOver = new EventEmitter();
        this.nzOnDragLeave = new EventEmitter();
        this.nzOnDrop = new EventEmitter();
        this.nzOnDragEnd = new EventEmitter();
        // default var
        this.prefixCls = 'ant-tree';
        this.nzNodeClass = {};
        this.nzNodeSwitcherClass = {};
        this.nzNodeContentClass = {};
        this.nzNodeCheckboxClass = {};
        this.nzNodeContentIconClass = {};
        this.nzNodeContentLoadingClass = {};
        /**
         * drag var
         */
        this.destroy$ = new Subject();
        this.dragPos = 2;
        this.dragPosClass = {
            '0': 'drag-over',
            '1': 'drag-over-gap-bottom',
            '-1': 'drag-over-gap-top'
        };
    }
    /**
     * default set
     */
    get displayStyle() {
        // to hide unmatched nodes
        return this.nzSearchValue &&
            this.nzHideUnMatched &&
            !this.nzTreeNode.isMatched &&
            !this.nzTreeNode.isExpanded &&
            this.nzTreeNode.canHide
            ? 'none'
            : '';
    }
    get matchedValue() {
        return this.nzTreeNode.isMatched ? this.nzSearchValue : '';
    }
    get nzIcon() {
        return this.nzTreeNode.icon;
    }
    get canDraggable() {
        return this.nzDraggable && !this.nzTreeNode.isDisabled ? true : null;
    }
    get isShowLineIcon() {
        return !this.nzTreeNode.isLeaf && this.nzShowLine;
    }
    get isShowSwitchIcon() {
        return !this.nzTreeNode.isLeaf && !this.nzShowLine;
    }
    get isSwitcherOpen() {
        return this.nzTreeNode.isExpanded && !this.nzTreeNode.isLeaf;
    }
    get isSwitcherClose() {
        return !this.nzTreeNode.isExpanded && !this.nzTreeNode.isLeaf;
    }
    /**
     * reset node class
     */
    setClassMap() {
        this.prefixCls = this.nzSelectMode ? 'ant-select-tree' : 'ant-tree';
        this.nzNodeClass = {
            [`${this.prefixCls}-treenode`]: true,
            [`${this.prefixCls}-treenode-disabled`]: this.nzTreeNode.isDisabled,
            [`${this.prefixCls}-treenode-switcher-open`]: this.isSwitcherOpen,
            [`${this.prefixCls}-treenode-switcher-close`]: this.isSwitcherClose,
            [`${this.prefixCls}-treenode-checkbox-checked`]: this.nzTreeNode.isChecked,
            [`${this.prefixCls}-treenode-checkbox-indeterminate`]: this.nzTreeNode.isHalfChecked,
            [`${this.prefixCls}-treenode-selected`]: this.nzTreeNode.isSelected,
            [`${this.prefixCls}-treenode-loading`]: this.nzTreeNode.isLoading
        };
        this.nzNodeSwitcherClass = {
            [`${this.prefixCls}-switcher`]: true,
            [`${this.prefixCls}-switcher-noop`]: this.nzTreeNode.isLeaf,
            [`${this.prefixCls}-switcher_open`]: this.isSwitcherOpen,
            [`${this.prefixCls}-switcher_close`]: this.isSwitcherClose
        };
        this.nzNodeCheckboxClass = {
            [`${this.prefixCls}-checkbox`]: true,
            [`${this.prefixCls}-checkbox-checked`]: this.nzTreeNode.isChecked,
            [`${this.prefixCls}-checkbox-indeterminate`]: this.nzTreeNode.isHalfChecked,
            [`${this.prefixCls}-checkbox-disabled`]: this.nzTreeNode.isDisabled || this.nzTreeNode.isDisableCheckbox
        };
        this.nzNodeContentClass = {
            [`${this.prefixCls}-node-content-wrapper`]: true,
            [`${this.prefixCls}-node-content-wrapper-open`]: this.isSwitcherOpen,
            [`${this.prefixCls}-node-content-wrapper-close`]: this.isSwitcherClose,
            [`${this.prefixCls}-node-selected`]: this.nzTreeNode.isSelected
        };
        this.nzNodeContentIconClass = {
            [`${this.prefixCls}-iconEle`]: true,
            [`${this.prefixCls}-icon__customize`]: true
        };
        this.nzNodeContentLoadingClass = {
            [`${this.prefixCls}-iconEle`]: true
        };
    }
    onMousedown(event) {
        if (this.nzSelectMode) {
            event.preventDefault();
        }
    }
    /**
     * collapse node
     * @param event
     */
    clickExpand(event) {
        event.preventDefault();
        if (!this.nzTreeNode.isLoading && !this.nzTreeNode.isLeaf) {
            // set async state
            if (this.nzAsyncData && this.nzTreeNode.children.length === 0 && !this.nzTreeNode.isExpanded) {
                this.nzTreeNode.isLoading = true;
            }
            this.nzTreeNode.setExpanded(!this.nzTreeNode.isExpanded);
        }
        this.nzTreeService.setExpandedNodeList(this.nzTreeNode);
        const eventNext = this.nzTreeService.formatEvent('expand', this.nzTreeNode, event);
        this.nzExpandChange.emit(eventNext);
    }
    clickSelect(event) {
        event.preventDefault();
        if (this.nzTreeNode.isSelectable && !this.nzTreeNode.isDisabled) {
            this.nzTreeNode.isSelected = !this.nzTreeNode.isSelected;
        }
        this.nzTreeService.setSelectedNodeList(this.nzTreeNode);
        const eventNext = this.nzTreeService.formatEvent('click', this.nzTreeNode, event);
        this.nzClick.emit(eventNext);
    }
    dblClick(event) {
        event.preventDefault();
        const eventNext = this.nzTreeService.formatEvent('dblclick', this.nzTreeNode, event);
        this.nzDblClick.emit(eventNext);
    }
    contextMenu(event) {
        event.preventDefault();
        const eventNext = this.nzTreeService.formatEvent('contextmenu', this.nzTreeNode, event);
        this.nzContextMenu.emit(eventNext);
    }
    /**
     * check node
     * @param event
     */
    clickCheckBox(event) {
        event.preventDefault();
        // return if node is disabled
        if (this.nzTreeNode.isDisabled || this.nzTreeNode.isDisableCheckbox) {
            return;
        }
        this.nzTreeNode.isChecked = !this.nzTreeNode.isChecked;
        this.nzTreeNode.isHalfChecked = false;
        this.nzTreeService.setCheckedNodeList(this.nzTreeNode);
        const eventNext = this.nzTreeService.formatEvent('check', this.nzTreeNode, event);
        this.nzCheckBoxChange.emit(eventNext);
    }
    /**
     * drag event
     * @param e
     */
    clearDragClass() {
        const dragClass = ['drag-over-gap-top', 'drag-over-gap-bottom', 'drag-over'];
        dragClass.forEach(e => {
            this.renderer.removeClass(this.dragElement.nativeElement, e);
        });
    }
    handleDragStart(e) {
        try {
            // ie throw error
            // firefox-need-it
            e.dataTransfer.setData('text/plain', this.nzTreeNode.key);
        }
        catch (error) {
            // empty
        }
        this.nzTreeService.setSelectedNode(this.nzTreeNode);
        const eventNext = this.nzTreeService.formatEvent('dragstart', this.nzTreeNode, e);
        this.nzOnDragStart.emit(eventNext);
    }
    handleDragEnter(e) {
        e.preventDefault();
        // reset position
        this.dragPos = 2;
        this.ngZone.run(() => {
            const eventNext = this.nzTreeService.formatEvent('dragenter', this.nzTreeNode, e);
            this.nzOnDragEnter.emit(eventNext);
        });
    }
    handleDragOver(e) {
        e.preventDefault();
        const dropPosition = this.nzTreeService.calcDropPosition(e);
        if (this.dragPos !== dropPosition) {
            this.clearDragClass();
            this.dragPos = dropPosition;
            // leaf node will pass
            if (!(this.dragPos === 0 && this.nzTreeNode.isLeaf)) {
                this.renderer.addClass(this.dragElement.nativeElement, this.dragPosClass[this.dragPos]);
            }
        }
        const eventNext = this.nzTreeService.formatEvent('dragover', this.nzTreeNode, e);
        this.nzOnDragOver.emit(eventNext);
    }
    handleDragLeave(e) {
        e.preventDefault();
        this.ngZone.run(() => {
            this.clearDragClass();
        });
        const eventNext = this.nzTreeService.formatEvent('dragleave', this.nzTreeNode, e);
        this.nzOnDragLeave.emit(eventNext);
    }
    handleDragDrop(e) {
        this.ngZone.run(() => {
            this.clearDragClass();
            const node = this.nzTreeService.getSelectedNode();
            if (!node || (node && node.key === this.nzTreeNode.key) || (this.dragPos === 0 && this.nzTreeNode.isLeaf)) {
                return;
            }
            // pass if node is leafNo
            const dropEvent = this.nzTreeService.formatEvent('drop', this.nzTreeNode, e);
            const dragEndEvent = this.nzTreeService.formatEvent('dragend', this.nzTreeNode, e);
            if (this.nzBeforeDrop) {
                this.nzBeforeDrop({
                    dragNode: this.nzTreeService.getSelectedNode(),
                    node: this.nzTreeNode,
                    pos: this.dragPos
                }).subscribe((canDrop) => {
                    if (canDrop) {
                        this.nzTreeService.dropAndApply(this.nzTreeNode, this.dragPos);
                    }
                    this.nzOnDrop.emit(dropEvent);
                    this.nzOnDragEnd.emit(dragEndEvent);
                });
            }
            else if (this.nzTreeNode) {
                this.nzTreeService.dropAndApply(this.nzTreeNode, this.dragPos);
                this.nzOnDrop.emit(dropEvent);
            }
        });
    }
    handleDragEnd(e) {
        e.preventDefault();
        this.ngZone.run(() => {
            // if user do not custom beforeDrop
            if (!this.nzBeforeDrop) {
                const eventNext = this.nzTreeService.formatEvent('dragend', this.nzTreeNode, e);
                this.nzOnDragEnd.emit(eventNext);
            }
        });
    }
    /**
     * Listening to dragging events.
     */
    handDragEvent() {
        this.ngZone.runOutsideAngular(() => {
            if (this.nzDraggable) {
                this.destroy$ = new Subject();
                fromEvent(this.elRef.nativeElement, 'dragstart')
                    .pipe(takeUntil(this.destroy$))
                    .subscribe((e) => this.handleDragStart(e));
                fromEvent(this.elRef.nativeElement, 'dragenter')
                    .pipe(takeUntil(this.destroy$))
                    .subscribe((e) => this.handleDragEnter(e));
                fromEvent(this.elRef.nativeElement, 'dragover')
                    .pipe(takeUntil(this.destroy$))
                    .subscribe((e) => this.handleDragOver(e));
                fromEvent(this.elRef.nativeElement, 'dragleave')
                    .pipe(takeUntil(this.destroy$))
                    .subscribe((e) => this.handleDragLeave(e));
                fromEvent(this.elRef.nativeElement, 'drop')
                    .pipe(takeUntil(this.destroy$))
                    .subscribe((e) => this.handleDragDrop(e));
                fromEvent(this.elRef.nativeElement, 'dragend')
                    .pipe(takeUntil(this.destroy$))
                    .subscribe((e) => this.handleDragEnd(e));
            }
            else {
                this.destroy$.next();
                this.destroy$.complete();
            }
        });
    }
    isTemplateRef(value) {
        return value instanceof TemplateRef;
    }
    markForCheck() {
        this.cdr.markForCheck();
    }
    ngOnInit() {
        this.nzTreeNode.component = this;
    }
    ngOnChanges(changes) {
        const { nzDraggable } = changes;
        if (nzDraggable) {
            this.handDragEvent();
        }
        this.setClassMap();
    }
    ngOnDestroy() {
        this.destroy$.next();
        this.destroy$.complete();
    }
}
/** @nocollapse */ NzTreeNodeComponent.ɵfac = function NzTreeNodeComponent_Factory(t) { return new (t || NzTreeNodeComponent)(ɵɵdirectiveInject(NzTreeBaseService), ɵɵdirectiveInject(NgZone), ɵɵdirectiveInject(Renderer2), ɵɵdirectiveInject(ElementRef), ɵɵdirectiveInject(ChangeDetectorRef), ɵɵdirectiveInject(NzNoAnimationDirective, 9)); };
/** @nocollapse */ NzTreeNodeComponent.ɵcmp = ɵɵdefineComponent({ type: NzTreeNodeComponent, selectors: [["nz-tree-node"]], viewQuery: function NzTreeNodeComponent_Query(rf, ctx) { if (rf & 1) {
        ɵɵviewQuery(_c0, true);
    } if (rf & 2) {
        var _t;
        ɵɵqueryRefresh(_t = ɵɵloadQuery()) && (ctx.dragElement = _t.first);
    } }, hostBindings: function NzTreeNodeComponent_HostBindings(rf, ctx) { if (rf & 1) {
        ɵɵlistener("mousedown", function NzTreeNodeComponent_mousedown_HostBindingHandler($event) { return ctx.onMousedown($event); });
    } }, inputs: { nzTreeNode: "nzTreeNode", nzShowLine: "nzShowLine", nzShowExpand: "nzShowExpand", nzCheckable: "nzCheckable", nzAsyncData: "nzAsyncData", nzHideUnMatched: "nzHideUnMatched", nzNoAnimation: "nzNoAnimation", nzSelectMode: "nzSelectMode", nzShowIcon: "nzShowIcon", nzExpandedIcon: "nzExpandedIcon", nzTreeTemplate: "nzTreeTemplate", nzBeforeDrop: "nzBeforeDrop", nzSearchValue: "nzSearchValue", nzDraggable: "nzDraggable" }, outputs: { nzClick: "nzClick", nzDblClick: "nzDblClick", nzContextMenu: "nzContextMenu", nzCheckBoxChange: "nzCheckBoxChange", nzExpandChange: "nzExpandChange", nzOnDragStart: "nzOnDragStart", nzOnDragEnter: "nzOnDragEnter", nzOnDragOver: "nzOnDragOver", nzOnDragLeave: "nzOnDragLeave", nzOnDrop: "nzOnDrop", nzOnDragEnd: "nzOnDragEnd" }, exportAs: ["nzTreeNode"], features: [ɵɵNgOnChangesFeature], decls: 8, vars: 21, consts: [["role", "treeitem", 3, "ngClass"], ["dragElement", ""], [3, "nzTreeLevel", "nzPrefixCls", "nzIsStart", "nzIsEnd"], [4, "ngIf"], [3, "title", "ngClass", "dblclick", "click", "contextmenu"], [3, "ngTemplateOutlet", "ngTemplateOutletContext"], [3, "ngClass", "click"], ["nz-icon", "", "nzType", "loading", "class", "ant-tree-switcher-loading-icon", 3, "nzSpin", 4, "ngIf"], ["nz-icon", "", "nzType", "caret-down", 3, "ant-select-tree-switcher-icon", "ant-tree-switcher-icon", 4, "ngIf"], ["nz-icon", "", "nzType", "caret-down"], ["nz-icon", "", "nzType", "loading", 1, "ant-tree-switcher-loading-icon", 3, "nzSpin"], ["nz-icon", "", "class", "ant-tree-switcher-line-icon", 3, "nzType", 4, "ngIf"], ["nz-icon", "", "nzType", "file", "class", "ant-tree-switcher-line-icon", 4, "ngIf"], ["nz-icon", "", 1, "ant-tree-switcher-line-icon", 3, "nzType"], ["nz-icon", "", "nzType", "file", 1, "ant-tree-switcher-line-icon"], [3, "ant-tree-icon__open", "ant-tree-icon__close", "ant-tree-icon_loading", "ngClass", 4, "ngIf"], [1, "ant-tree-title", 3, "innerHTML"], [3, "ngClass"], ["nz-icon", "", 3, "nzType", 4, "ngIf"], ["nz-icon", "", 3, "nzType"]], template: function NzTreeNodeComponent_Template(rf, ctx) { if (rf & 1) {
        ɵɵelementStart(0, "div", 0, 1);
        ɵɵelement(2, "nz-tree-indent", 2);
        ɵɵtemplate(3, NzTreeNodeComponent_ng_container_3_Template, 4, 3, "ng-container", 3);
        ɵɵtemplate(4, NzTreeNodeComponent_ng_container_4_Template, 3, 5, "ng-container", 3);
        ɵɵelementStart(5, "span", 4);
        ɵɵlistener("dblclick", function NzTreeNodeComponent_Template_span_dblclick_5_listener($event) { return ctx.dblClick($event); })("click", function NzTreeNodeComponent_Template_span_click_5_listener($event) { return ctx.clickSelect($event); })("contextmenu", function NzTreeNodeComponent_Template_span_contextmenu_5_listener($event) { return ctx.contextMenu($event); });
        ɵɵtemplate(6, NzTreeNodeComponent_ng_template_6_Template, 0, 0, "ng-template", 5);
        ɵɵtemplate(7, NzTreeNodeComponent_ng_container_7_Template, 4, 7, "ng-container", 3);
        ɵɵelementEnd();
        ɵɵelementEnd();
    } if (rf & 2) {
        ɵɵstyleProp("display", ctx.displayStyle);
        ɵɵproperty("ngClass", ctx.nzNodeClass);
        ɵɵadvance(2);
        ɵɵproperty("nzTreeLevel", ctx.nzTreeNode.level)("nzPrefixCls", ctx.prefixCls)("nzIsStart", ctx.nzTreeNode.isStart)("nzIsEnd", ctx.nzTreeNode.isEnd);
        ɵɵadvance(1);
        ɵɵproperty("ngIf", ctx.nzShowExpand);
        ɵɵadvance(1);
        ɵɵproperty("ngIf", ctx.nzCheckable);
        ɵɵadvance(1);
        ɵɵclassProp("draggable", ctx.canDraggable);
        ɵɵpropertyInterpolate("title", ctx.nzTreeNode.title);
        ɵɵproperty("ngClass", ctx.nzNodeContentClass);
        ɵɵattribute("draggable", ctx.canDraggable)("aria-grabbed", ctx.canDraggable);
        ɵɵadvance(1);
        ɵɵproperty("ngTemplateOutlet", ctx.nzTreeTemplate)("ngTemplateOutletContext", ɵɵpureFunction2(18, _c1, ctx.nzTreeNode, ctx.nzTreeNode.origin));
        ɵɵadvance(1);
        ɵɵproperty("ngIf", !ctx.nzTreeTemplate);
    } }, directives: [NgClass, NzTreeIndentComponent, NgIf, NgTemplateOutlet, NzIconDirective], pipes: [NzHighlightPipe], encapsulation: 2, data: { animation: [treeCollapseMotion] }, changeDetection: 0 });
__decorate([
    InputBoolean(),
    __metadata("design:type", Boolean)
], NzTreeNodeComponent.prototype, "nzShowLine", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Boolean)
], NzTreeNodeComponent.prototype, "nzShowExpand", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Boolean)
], NzTreeNodeComponent.prototype, "nzCheckable", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Boolean)
], NzTreeNodeComponent.prototype, "nzAsyncData", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeNodeComponent.prototype, "nzHideUnMatched", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeNodeComponent.prototype, "nzNoAnimation", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeNodeComponent.prototype, "nzSelectMode", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeNodeComponent.prototype, "nzShowIcon", void 0);
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzTreeNodeComponent, [{
        type: Component,
        args: [{
                selector: 'nz-tree-node',
                exportAs: 'nzTreeNode',
                template: `
    <div #dragElement role="treeitem" [ngClass]="nzNodeClass" [style.display]="displayStyle">
      <nz-tree-indent
        [nzTreeLevel]="nzTreeNode.level"
        [nzPrefixCls]="prefixCls"
        [nzIsStart]="nzTreeNode.isStart"
        [nzIsEnd]="nzTreeNode.isEnd"
      ></nz-tree-indent>
      <ng-container *ngIf="nzShowExpand">
        <!-- render switcher -->
        <span [ngClass]="nzNodeSwitcherClass" (click)="clickExpand($event)">
          <ng-container *ngIf="isShowSwitchIcon">
            <ng-container *ngIf="!nzTreeNode.isLoading">
              <ng-template
                *ngIf="isTemplateRef(nzExpandedIcon)"
                [ngTemplateOutlet]="nzExpandedIcon"
                [ngTemplateOutletContext]="{ $implicit: nzTreeNode, origin: nzTreeNode.origin }"
              >
              </ng-template>
              <i
                *ngIf="!isTemplateRef(nzExpandedIcon)"
                nz-icon
                nzType="caret-down"
                [class.ant-select-tree-switcher-icon]="nzSelectMode"
                [class.ant-tree-switcher-icon]="!nzSelectMode"
              >
              </i>
            </ng-container>
            <i *ngIf="nzTreeNode.isLoading" nz-icon nzType="loading" [nzSpin]="true" class="ant-tree-switcher-loading-icon"></i>
          </ng-container>
          <ng-container *ngIf="nzShowLine">
            <ng-container *ngIf="!nzTreeNode.isLoading">
              <ng-template
                *ngIf="isTemplateRef(nzExpandedIcon)"
                [ngTemplateOutlet]="nzExpandedIcon"
                [ngTemplateOutletContext]="{ $implicit: nzTreeNode, origin: nzTreeNode.origin }"
              >
              </ng-template>
              <ng-container *ngIf="!isTemplateRef(nzExpandedIcon)">
                <i
                  *ngIf="isShowLineIcon"
                  nz-icon
                  [nzType]="isSwitcherOpen ? 'minus-square' : 'plus-square'"
                  class="ant-tree-switcher-line-icon"
                ></i>
                <i *ngIf="!isShowLineIcon" nz-icon nzType="file" class="ant-tree-switcher-line-icon"></i>
              </ng-container>
            </ng-container>
            <i *ngIf="nzTreeNode.isLoading" nz-icon nzType="loading" [nzSpin]="true" class="ant-tree-switcher-loading-icon"></i>
          </ng-container>
        </span>
      </ng-container>
      <ng-container *ngIf="nzCheckable">
        <span [ngClass]="nzNodeCheckboxClass" (click)="clickCheckBox($event)">
          <span [class.ant-tree-checkbox-inner]="!nzSelectMode" [class.ant-select-tree-checkbox-inner]="nzSelectMode"></span>
        </span>
      </ng-container>
      <span
        title="{{ nzTreeNode.title }}"
        [attr.draggable]="canDraggable"
        [attr.aria-grabbed]="canDraggable"
        [ngClass]="nzNodeContentClass"
        [class.draggable]="canDraggable"
        (dblclick)="dblClick($event)"
        (click)="clickSelect($event)"
        (contextmenu)="contextMenu($event)"
      >
        <ng-template [ngTemplateOutlet]="nzTreeTemplate" [ngTemplateOutletContext]="{ $implicit: nzTreeNode, origin: nzTreeNode.origin }">
        </ng-template>
        <ng-container *ngIf="!nzTreeTemplate">
          <span
            *ngIf="nzTreeNode.icon && nzShowIcon"
            [class.ant-tree-icon__open]="isSwitcherOpen"
            [class.ant-tree-icon__close]="isSwitcherClose"
            [class.ant-tree-icon_loading]="nzTreeNode.isLoading"
            [ngClass]="nzNodeContentLoadingClass"
          >
            <span [ngClass]="nzNodeContentIconClass">
              <i nz-icon *ngIf="nzIcon" [nzType]="nzIcon"></i>
            </span>
          </span>
          <span class="ant-tree-title" [innerHTML]="nzTreeNode.title | nzHighlight: matchedValue:'':'font-highlight'"> </span>
        </ng-container>
      </span>
    </div>
  `,
                changeDetection: ChangeDetectionStrategy.OnPush,
                preserveWhitespaces: false,
                animations: [treeCollapseMotion]
            }]
    }], function () { return [{ type: NzTreeBaseService }, { type: NgZone }, { type: Renderer2 }, { type: ElementRef }, { type: ChangeDetectorRef }, { type: NzNoAnimationDirective, decorators: [{
                type: Host
            }, {
                type: Optional
            }] }]; }, { dragElement: [{
            type: ViewChild,
            args: ['dragElement', { static: false }]
        }], nzTreeNode: [{
            type: Input
        }], nzShowLine: [{
            type: Input
        }], nzShowExpand: [{
            type: Input
        }], nzCheckable: [{
            type: Input
        }], nzAsyncData: [{
            type: Input
        }], nzHideUnMatched: [{
            type: Input
        }], nzNoAnimation: [{
            type: Input
        }], nzSelectMode: [{
            type: Input
        }], nzShowIcon: [{
            type: Input
        }], nzExpandedIcon: [{
            type: Input
        }], nzTreeTemplate: [{
            type: Input
        }], nzBeforeDrop: [{
            type: Input
        }], nzSearchValue: [{
            type: Input
        }], nzDraggable: [{
            type: Input
        }], nzClick: [{
            type: Output
        }], nzDblClick: [{
            type: Output
        }], nzContextMenu: [{
            type: Output
        }], nzCheckBoxChange: [{
            type: Output
        }], nzExpandChange: [{
            type: Output
        }], nzOnDragStart: [{
            type: Output
        }], nzOnDragEnter: [{
            type: Output
        }], nzOnDragOver: [{
            type: Output
        }], nzOnDragLeave: [{
            type: Output
        }], nzOnDrop: [{
            type: Output
        }], nzOnDragEnd: [{
            type: Output
        }], onMousedown: [{
            type: HostListener,
            args: ['mousedown', ['$event']]
        }] }); })();

/**
 * @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
 */
class NzTreeService extends NzTreeBaseService {
    constructor() {
        super();
    }
}
/** @nocollapse */ NzTreeService.ɵfac = function NzTreeService_Factory(t) { return new (t || NzTreeService)(); };
/** @nocollapse */ NzTreeService.ɵprov = ɵɵdefineInjectable({ token: NzTreeService, factory: NzTreeService.ɵfac });
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzTreeService, [{
        type: Injectable
    }], function () { return []; }, null); })();

const _c0$1 = ["nzTreeTemplate"];
function NzTreeComponent_ng_container_6_Template(rf, ctx) { if (rf & 1) {
    const _r1077 = ɵɵgetCurrentView();
    ɵɵelementContainerStart(0);
    ɵɵelementStart(1, "nz-tree-node", 4);
    ɵɵlistener("nzExpandChange", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzExpandChange_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1076 = ɵɵnextContext(); return ctx_r1076.eventTriggerChanged($event); })("nzClick", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzClick_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1078 = ɵɵnextContext(); return ctx_r1078.eventTriggerChanged($event); })("nzDblClick", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzDblClick_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1079 = ɵɵnextContext(); return ctx_r1079.eventTriggerChanged($event); })("nzContextMenu", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzContextMenu_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1080 = ɵɵnextContext(); return ctx_r1080.eventTriggerChanged($event); })("nzCheckBoxChange", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzCheckBoxChange_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1081 = ɵɵnextContext(); return ctx_r1081.eventTriggerChanged($event); })("nzOnDragStart", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzOnDragStart_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1082 = ɵɵnextContext(); return ctx_r1082.eventTriggerChanged($event); })("nzOnDragEnter", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzOnDragEnter_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1083 = ɵɵnextContext(); return ctx_r1083.eventTriggerChanged($event); })("nzOnDragOver", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzOnDragOver_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1084 = ɵɵnextContext(); return ctx_r1084.eventTriggerChanged($event); })("nzOnDragLeave", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzOnDragLeave_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1085 = ɵɵnextContext(); return ctx_r1085.eventTriggerChanged($event); })("nzOnDragEnd", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzOnDragEnd_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1086 = ɵɵnextContext(); return ctx_r1086.eventTriggerChanged($event); })("nzOnDrop", function NzTreeComponent_ng_container_6_Template_nz_tree_node_nzOnDrop_1_listener($event) { ɵɵrestoreView(_r1077); const ctx_r1087 = ɵɵnextContext(); return ctx_r1087.eventTriggerChanged($event); });
    ɵɵelementEnd();
    ɵɵelementContainerEnd();
} if (rf & 2) {
    const node_r1075 = ctx.$implicit;
    const ctx_r1074 = ɵɵnextContext();
    ɵɵadvance(1);
    ɵɵproperty("nzTreeNode", node_r1075.data)("nzSelectMode", ctx_r1074.nzSelectMode)("nzShowLine", ctx_r1074.nzShowLine)("nzExpandedIcon", ctx_r1074.nzExpandedIcon)("nzDraggable", ctx_r1074.nzDraggable)("nzCheckable", ctx_r1074.nzCheckable)("nzShowExpand", ctx_r1074.nzShowExpand)("nzAsyncData", ctx_r1074.nzAsyncData)("nzSearchValue", ctx_r1074.nzSearchValue)("nzHideUnMatched", ctx_r1074.nzHideUnMatched)("nzBeforeDrop", ctx_r1074.nzBeforeDrop)("nzShowIcon", ctx_r1074.nzShowIcon)("nzTreeTemplate", ctx_r1074.treeTemplate)("@.disabled", ctx_r1074.noAnimation == null ? null : ctx_r1074.noAnimation.nzNoAnimation)("nzNoAnimation", ctx_r1074.noAnimation == null ? null : ctx_r1074.noAnimation.nzNoAnimation);
} }
function NzTreeServiceFactory(higherOrderService, treeService) {
    return higherOrderService ? higherOrderService : treeService;
}
const NZ_CONFIG_COMPONENT_NAME = 'tree';
class NzTreeComponent extends NzTreeBase {
    // Handle emit event end
    constructor(nzTreeService, nzConfigService, cdr, noAnimation) {
        super(nzTreeService);
        this.nzConfigService = nzConfigService;
        this.cdr = cdr;
        this.noAnimation = noAnimation;
        this.nzShowExpand = true;
        this.nzShowLine = false;
        this.nzCheckable = false;
        this.nzAsyncData = false;
        this.nzDraggable = false;
        this.nzSelectMode = false;
        this.nzCheckStrictly = false;
        this.nzExpandAll = false;
        this.nzMultiple = false;
        this.nzData = [];
        this.nzExpandedKeys = [];
        this.nzSelectedKeys = [];
        this.nzCheckedKeys = [];
        this.nzExpandedKeysChange = new EventEmitter();
        this.nzSelectedKeysChange = new EventEmitter();
        this.nzCheckedKeysChange = new EventEmitter();
        this.nzSearchValueChange = new EventEmitter();
        this.nzClick = new EventEmitter();
        this.nzDblClick = new EventEmitter();
        this.nzContextMenu = new EventEmitter();
        this.nzCheckBoxChange = new EventEmitter();
        this.nzExpandChange = new EventEmitter();
        this.nzOnDragStart = new EventEmitter();
        this.nzOnDragEnter = new EventEmitter();
        this.nzOnDragOver = new EventEmitter();
        this.nzOnDragLeave = new EventEmitter();
        this.nzOnDrop = new EventEmitter();
        this.nzOnDragEnd = new EventEmitter();
        this.HIDDEN_STYLE = {
            width: 0,
            height: 0,
            display: 'flex',
            overflow: 'hidden',
            opacity: 0,
            border: 0,
            padding: 0,
            margin: 0
        };
        this.destroy$ = new Subject();
        this.prefixCls = 'ant-tree';
        this.classMap = {};
        this.classMapOfNodeList = {};
        this.classMapOfListContainer = {};
        this.onChange = () => null;
        this.onTouched = () => null;
    }
    get treeTemplate() {
        return this.nzTreeTemplate || this.nzTreeTemplateChild;
    }
    /**
     * To render nodes if root is changed.
     */
    get nzNodes() {
        return this.nzTreeService.rootNodes;
    }
    get nzFlattenNodes() {
        return this.nzTreeService.flattenNodes;
    }
    setClassMap() {
        this.prefixCls = this.nzSelectMode ? 'ant-select-tree' : 'ant-tree';
        this.classMapOfNodeList = {
            [this.prefixCls + '-list']: true
        };
        this.classMapOfListContainer = {
            [this.prefixCls + '-list-holder-inner']: true
        };
        this.classMap = {
            [this.prefixCls]: true,
            [this.prefixCls + '-show-line']: this.nzShowLine,
            [`${this.prefixCls}-icon-hide`]: !this.nzShowIcon,
            [`${this.prefixCls}-block-node`]: this.nzBlockNode,
            ['draggable-tree']: this.nzDraggable
        };
        this.cdr.markForCheck();
    }
    writeValue(value) {
        this.handleNzData(value);
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    /**
     * Render all properties of nzTree
     * @param changes: all changes from @Input
     */
    renderTreeProperties(changes) {
        let useDefaultExpandedKeys = false;
        let expandAll = false;
        const { nzData, nzExpandedKeys, nzSelectedKeys, nzCheckedKeys, nzCheckStrictly, nzExpandAll, nzMultiple, nzSearchValue } = changes;
        if (nzExpandAll) {
            useDefaultExpandedKeys = true;
            expandAll = this.nzExpandAll;
        }
        if (nzMultiple) {
            this.nzTreeService.isMultiple = this.nzMultiple;
        }
        if (nzCheckStrictly) {
            this.nzTreeService.isCheckStrictly = this.nzCheckStrictly;
        }
        if (nzData) {
            this.handleNzData(this.nzData);
        }
        if (nzCheckedKeys || nzCheckStrictly) {
            this.handleCheckedKeys(this.nzCheckedKeys);
        }
        if (nzExpandedKeys || nzExpandAll) {
            useDefaultExpandedKeys = true;
            this.handleExpandedKeys(expandAll || this.nzExpandedKeys);
        }
        if (nzSelectedKeys) {
            this.handleSelectedKeys(this.nzSelectedKeys, this.nzMultiple);
        }
        if (nzSearchValue) {
            if (!(nzSearchValue.firstChange && !this.nzSearchValue)) {
                useDefaultExpandedKeys = false;
                this.handleSearchValue(this.nzSearchValue, this.nzSearchFunc);
                this.nzSearchValueChange.emit(this.nzTreeService.formatEvent('search', null, null));
            }
        }
        // flatten data
        const currentExpandedKeys = this.getExpandedNodeList().map(v => v.key);
        const newExpandedKeys = useDefaultExpandedKeys ? expandAll || this.nzExpandedKeys : currentExpandedKeys;
        this.handleFlattenNodes(this.nzNodes, newExpandedKeys);
    }
    // Deal with properties
    /**
     * nzData
     * @param value
     */
    // tslint:disable-next-line:no-any
    handleNzData(value) {
        if (Array.isArray(value)) {
            const data = this.coerceTreeNodes(value);
            this.nzTreeService.initTree(data);
        }
    }
    handleFlattenNodes(data, expandKeys = []) {
        this.nzTreeService.flattenTreeData(data, expandKeys);
    }
    handleCheckedKeys(keys) {
        this.nzTreeService.conductCheck(keys, this.nzCheckStrictly);
    }
    handleExpandedKeys(keys = []) {
        this.nzTreeService.conductExpandedKeys(keys);
    }
    handleSelectedKeys(keys, isMulti) {
        this.nzTreeService.conductSelectedKeys(keys, isMulti);
    }
    handleSearchValue(value, searchFunc) {
        const dataList = flattenTreeData(this.nzNodes, true).map(v => v.data);
        const checkIfMatched = (node) => {
            if (searchFunc) {
                return searchFunc(node.origin);
            }
            return !value || !node.title.includes(value) ? false : true;
        };
        dataList.forEach(v => {
            v.isMatched = checkIfMatched(v);
            v.canHide = !v.isMatched;
            if (!v.isMatched) {
                v.setExpanded(false);
                this.nzTreeService.setExpandedNodeList(v);
            }
            else {
                // expand
                this.nzTreeService.expandNodeAllParentBySearch(v);
            }
            this.nzTreeService.setMatchedNodeList(v);
        });
    }
    /**
     * Handle emit event
     * @param event
     * handle each event
     */
    eventTriggerChanged(event) {
        const node = event.node;
        switch (event.eventName) {
            case 'expand':
                this.renderTree();
                this.nzExpandChange.emit(event);
                break;
            case 'click':
                this.nzClick.emit(event);
                break;
            case 'dblclick':
                this.nzDblClick.emit(event);
                break;
            case 'contextmenu':
                this.nzContextMenu.emit(event);
                break;
            case 'check':
                // Render checked state with nodes' property `isChecked`
                this.nzTreeService.setCheckedNodeList(node);
                if (!this.nzCheckStrictly) {
                    this.nzTreeService.conduct(node);
                }
                // Cause check method will rerender list, so we need recover it and next the new event to user
                const eventNext = this.nzTreeService.formatEvent('check', node, event.event);
                this.nzCheckBoxChange.emit(eventNext);
                break;
            case 'dragstart':
                // if node is expanded
                if (node.isExpanded) {
                    node.setExpanded(!node.isExpanded);
                    this.renderTree();
                }
                this.nzOnDragStart.emit(event);
                break;
            case 'dragenter':
                const selectedNode = this.nzTreeService.getSelectedNode();
                if (selectedNode && selectedNode.key !== node.key && !node.isExpanded && !node.isLeaf) {
                    node.setExpanded(true);
                    this.renderTree();
                }
                this.nzOnDragEnter.emit(event);
                break;
            case 'dragover':
                this.nzOnDragOver.emit(event);
                break;
            case 'dragleave':
                this.nzOnDragLeave.emit(event);
                break;
            case 'dragend':
                this.nzOnDragEnd.emit(event);
                break;
            case 'drop':
                this.renderTree();
                this.nzOnDrop.emit(event);
                break;
        }
    }
    /**
     * Click expand icon
     */
    renderTree() {
        this.handleFlattenNodes(this.nzNodes, this.getExpandedNodeList().map(v => v.key));
        this.cdr.markForCheck();
    }
    ngOnInit() { }
    ngOnChanges(changes) {
        this.setClassMap();
        this.renderTreeProperties(changes);
    }
    ngOnDestroy() {
        this.destroy$.next();
        this.destroy$.complete();
    }
}
/** @nocollapse */ NzTreeComponent.ɵfac = function NzTreeComponent_Factory(t) { return new (t || NzTreeComponent)(ɵɵdirectiveInject(NzTreeBaseService), ɵɵdirectiveInject(NzConfigService), ɵɵdirectiveInject(ChangeDetectorRef), ɵɵdirectiveInject(NzNoAnimationDirective, 9)); };
/** @nocollapse */ NzTreeComponent.ɵcmp = ɵɵdefineComponent({ type: NzTreeComponent, selectors: [["nz-tree"]], contentQueries: function NzTreeComponent_ContentQueries(rf, ctx, dirIndex) { if (rf & 1) {
        ɵɵstaticContentQuery(dirIndex, _c0$1, true);
    } if (rf & 2) {
        var _t;
        ɵɵqueryRefresh(_t = ɵɵloadQuery()) && (ctx.nzTreeTemplateChild = _t.first);
    } }, inputs: { nzShowIcon: "nzShowIcon", nzShowExpand: "nzShowExpand", nzShowLine: "nzShowLine", nzExpandedIcon: "nzExpandedIcon", nzCheckable: "nzCheckable", nzAsyncData: "nzAsyncData", nzDraggable: "nzDraggable", nzHideUnMatched: "nzHideUnMatched", nzSelectMode: "nzSelectMode", nzCheckStrictly: "nzCheckStrictly", nzBlockNode: "nzBlockNode", nzExpandAll: "nzExpandAll", nzTreeTemplate: "nzTreeTemplate", nzBeforeDrop: "nzBeforeDrop", nzMultiple: "nzMultiple", nzData: "nzData", nzExpandedKeys: "nzExpandedKeys", nzSelectedKeys: "nzSelectedKeys", nzCheckedKeys: "nzCheckedKeys", nzSearchValue: "nzSearchValue", nzSearchFunc: "nzSearchFunc" }, outputs: { nzExpandedKeysChange: "nzExpandedKeysChange", nzSelectedKeysChange: "nzSelectedKeysChange", nzCheckedKeysChange: "nzCheckedKeysChange", nzSearchValueChange: "nzSearchValueChange", nzClick: "nzClick", nzDblClick: "nzDblClick", nzContextMenu: "nzContextMenu", nzCheckBoxChange: "nzCheckBoxChange", nzExpandChange: "nzExpandChange", nzOnDragStart: "nzOnDragStart", nzOnDragEnter: "nzOnDragEnter", nzOnDragOver: "nzOnDragOver", nzOnDragLeave: "nzOnDragLeave", nzOnDrop: "nzOnDrop", nzOnDragEnd: "nzOnDragEnd" }, exportAs: ["nzTree"], features: [ɵɵProvidersFeature([
            NzTreeService,
            {
                provide: NzTreeBaseService,
                useFactory: NzTreeServiceFactory,
                deps: [[new SkipSelf(), new Optional(), NzTreeHigherOrderServiceToken], NzTreeService]
            },
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef((() => NzTreeComponent)),
                multi: true
            }
        ]), ɵɵInheritDefinitionFeature, ɵɵNgOnChangesFeature], decls: 7, vars: 5, consts: [[3, "ngClass"], ["role", "tree"], [3, "ngStyle"], [4, "ngFor", "ngForOf"], [3, "nzTreeNode", "nzSelectMode", "nzShowLine", "nzExpandedIcon", "nzDraggable", "nzCheckable", "nzShowExpand", "nzAsyncData", "nzSearchValue", "nzHideUnMatched", "nzBeforeDrop", "nzShowIcon", "nzTreeTemplate", "nzNoAnimation", "nzExpandChange", "nzClick", "nzDblClick", "nzContextMenu", "nzCheckBoxChange", "nzOnDragStart", "nzOnDragEnter", "nzOnDragOver", "nzOnDragLeave", "nzOnDragEnd", "nzOnDrop"]], template: function NzTreeComponent_Template(rf, ctx) { if (rf & 1) {
        ɵɵelementStart(0, "div", 0);
        ɵɵelementStart(1, "div", 1);
        ɵɵelement(2, "input", 2);
        ɵɵelementEnd();
        ɵɵelementStart(3, "div", 0);
        ɵɵelementStart(4, "div");
        ɵɵelementStart(5, "div", 0);
        ɵɵtemplate(6, NzTreeComponent_ng_container_6_Template, 2, 15, "ng-container", 3);
        ɵɵelementEnd();
        ɵɵelementEnd();
        ɵɵelementEnd();
        ɵɵelementEnd();
    } if (rf & 2) {
        ɵɵproperty("ngClass", ctx.classMap);
        ɵɵadvance(2);
        ɵɵproperty("ngStyle", ctx.HIDDEN_STYLE);
        ɵɵadvance(1);
        ɵɵproperty("ngClass", ctx.classMapOfNodeList);
        ɵɵadvance(2);
        ɵɵproperty("ngClass", ctx.classMapOfListContainer);
        ɵɵadvance(1);
        ɵɵproperty("ngForOf", ctx.nzFlattenNodes);
    } }, directives: [NgClass, NgStyle, NgForOf, NzTreeNodeComponent, NzNoAnimationDirective], encapsulation: 2, changeDetection: 0 });
__decorate([
    InputBoolean(), WithConfig(NZ_CONFIG_COMPONENT_NAME, false),
    __metadata("design:type", Boolean)
], NzTreeComponent.prototype, "nzShowIcon", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Boolean)
], NzTreeComponent.prototype, "nzShowExpand", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeComponent.prototype, "nzShowLine", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeComponent.prototype, "nzCheckable", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeComponent.prototype, "nzAsyncData", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Boolean)
], NzTreeComponent.prototype, "nzDraggable", void 0);
__decorate([
    InputBoolean(), WithConfig(NZ_CONFIG_COMPONENT_NAME, false),
    __metadata("design:type", Boolean)
], NzTreeComponent.prototype, "nzHideUnMatched", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeComponent.prototype, "nzSelectMode", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeComponent.prototype, "nzCheckStrictly", void 0);
__decorate([
    WithConfig(NZ_CONFIG_COMPONENT_NAME, false), InputBoolean(),
    __metadata("design:type", Boolean)
], NzTreeComponent.prototype, "nzBlockNode", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeComponent.prototype, "nzExpandAll", void 0);
__decorate([
    InputBoolean(),
    __metadata("design:type", Object)
], NzTreeComponent.prototype, "nzMultiple", void 0);
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzTreeComponent, [{
        type: Component,
        args: [{
                selector: 'nz-tree',
                exportAs: 'nzTree',
                template: `
    <div [ngClass]="classMap">
      <div role="tree">
        <input [ngStyle]="HIDDEN_STYLE" />
      </div>
      <div [ngClass]="classMapOfNodeList">
        <div>
          <div [ngClass]="classMapOfListContainer">
            <ng-container *ngFor="let node of nzFlattenNodes">
              <nz-tree-node
                [nzTreeNode]="node.data"
                [nzSelectMode]="nzSelectMode"
                [nzShowLine]="nzShowLine"
                [nzExpandedIcon]="nzExpandedIcon"
                [nzDraggable]="nzDraggable"
                [nzCheckable]="nzCheckable"
                [nzShowExpand]="nzShowExpand"
                [nzAsyncData]="nzAsyncData"
                [nzSearchValue]="nzSearchValue"
                [nzHideUnMatched]="nzHideUnMatched"
                [nzBeforeDrop]="nzBeforeDrop"
                [nzShowIcon]="nzShowIcon"
                [nzTreeTemplate]="treeTemplate"
                [@.disabled]="noAnimation?.nzNoAnimation"
                [nzNoAnimation]="noAnimation?.nzNoAnimation"
                (nzExpandChange)="eventTriggerChanged($event)"
                (nzClick)="eventTriggerChanged($event)"
                (nzDblClick)="eventTriggerChanged($event)"
                (nzContextMenu)="eventTriggerChanged($event)"
                (nzCheckBoxChange)="eventTriggerChanged($event)"
                (nzOnDragStart)="eventTriggerChanged($event)"
                (nzOnDragEnter)="eventTriggerChanged($event)"
                (nzOnDragOver)="eventTriggerChanged($event)"
                (nzOnDragLeave)="eventTriggerChanged($event)"
                (nzOnDragEnd)="eventTriggerChanged($event)"
                (nzOnDrop)="eventTriggerChanged($event)"
              >
              </nz-tree-node>
            </ng-container>
          </div>
        </div>
      </div>
    </div>
  `,
                changeDetection: ChangeDetectionStrategy.OnPush,
                providers: [
                    NzTreeService,
                    {
                        provide: NzTreeBaseService,
                        useFactory: NzTreeServiceFactory,
                        deps: [[new SkipSelf(), new Optional(), NzTreeHigherOrderServiceToken], NzTreeService]
                    },
                    {
                        provide: NG_VALUE_ACCESSOR,
                        useExisting: forwardRef((() => NzTreeComponent)),
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: NzTreeBaseService }, { type: NzConfigService }, { type: ChangeDetectorRef }, { type: NzNoAnimationDirective, decorators: [{
                type: Host
            }, {
                type: Optional
            }] }]; }, { nzShowIcon: [{
            type: Input
        }], nzShowExpand: [{
            type: Input
        }], nzShowLine: [{
            type: Input
        }], nzExpandedIcon: [{
            type: Input
        }], nzCheckable: [{
            type: Input
        }], nzAsyncData: [{
            type: Input
        }], nzDraggable: [{
            type: Input
        }], nzHideUnMatched: [{
            type: Input
        }], nzSelectMode: [{
            type: Input
        }], nzCheckStrictly: [{
            type: Input
        }], nzBlockNode: [{
            type: Input
        }], nzExpandAll: [{
            type: Input
        }], nzTreeTemplate: [{
            type: Input
        }], nzTreeTemplateChild: [{
            type: ContentChild,
            args: ['nzTreeTemplate', { static: true }]
        }], nzBeforeDrop: [{
            type: Input
        }], nzMultiple: [{
            type: Input
        }], nzData: [{
            type: Input
        }], nzExpandedKeys: [{
            type: Input
        }], nzSelectedKeys: [{
            type: Input
        }], nzCheckedKeys: [{
            type: Input
        }], nzSearchValue: [{
            type: Input
        }], nzSearchFunc: [{
            type: Input
        }], nzExpandedKeysChange: [{
            type: Output
        }], nzSelectedKeysChange: [{
            type: Output
        }], nzCheckedKeysChange: [{
            type: Output
        }], nzSearchValueChange: [{
            type: Output
        }], nzClick: [{
            type: Output
        }], nzDblClick: [{
            type: Output
        }], nzContextMenu: [{
            type: Output
        }], nzCheckBoxChange: [{
            type: Output
        }], nzExpandChange: [{
            type: Output
        }], nzOnDragStart: [{
            type: Output
        }], nzOnDragEnter: [{
            type: Output
        }], nzOnDragOver: [{
            type: Output
        }], nzOnDragLeave: [{
            type: Output
        }], nzOnDrop: [{
            type: Output
        }], nzOnDragEnd: [{
            type: Output
        }] }); })();

/**
 * @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
 */
class NzTreeModule {
}
/** @nocollapse */ NzTreeModule.ɵmod = ɵɵdefineNgModule({ type: NzTreeModule });
/** @nocollapse */ NzTreeModule.ɵinj = ɵɵdefineInjector({ factory: function NzTreeModule_Factory(t) { return new (t || NzTreeModule)(); }, imports: [[CommonModule, NzOutletModule, NzIconModule, NzNoAnimationModule, NzHighlightModule]] });
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵɵsetNgModuleScope(NzTreeModule, { declarations: [NzTreeComponent, NzTreeNodeComponent, NzTreeIndentComponent], imports: [CommonModule, NzOutletModule, NzIconModule, NzNoAnimationModule, NzHighlightModule], exports: [NzTreeComponent, NzTreeNodeComponent, NzTreeIndentComponent] }); })();
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzTreeModule, [{
        type: NgModule,
        args: [{
                imports: [CommonModule, NzOutletModule, NzIconModule, NzNoAnimationModule, NzHighlightModule],
                declarations: [NzTreeComponent, NzTreeNodeComponent, NzTreeIndentComponent],
                exports: [NzTreeComponent, NzTreeNodeComponent, NzTreeIndentComponent]
            }]
    }], null, null); })();

/**
 * @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
 */

/**
 * Generated bundle index. Do not edit.
 */

export { NzTreeComponent, NzTreeIndentComponent, NzTreeModule, NzTreeNodeComponent, NzTreeService, NzTreeServiceFactory };
//# sourceMappingURL=ng-zorro-antd-tree.js.map
