(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/cdk/scrolling'), require('@angular/common'), require('primeng/api'), require('primeng/utils'), require('primeng/dom'), require('primeng/ripple')) :
    typeof define === 'function' && define.amd ? define('primeng/tree', ['exports', '@angular/core', '@angular/cdk/scrolling', '@angular/common', 'primeng/api', 'primeng/utils', 'primeng/dom', 'primeng/ripple'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.primeng = global.primeng || {}, global.primeng.tree = {}), global.ng.core, global.ng.cdk.scrolling, global.ng.common, global.primeng.api, global.primeng.utils, global.primeng.dom, global.primeng.ripple));
}(this, (function (exports, core, scrolling, common, api, utils, dom, ripple) { 'use strict';

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */
    /* global Reflect, Promise */
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b)
                if (Object.prototype.hasOwnProperty.call(b, p))
                    d[p] = b[p]; };
        return extendStatics(d, b);
    };
    function __extends(d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }
    var __assign = function () {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s)
                    if (Object.prototype.hasOwnProperty.call(s, p))
                        t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };
    function __rest(s, e) {
        var t = {};
        for (var p in s)
            if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
                t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }
    function __decorate(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;
    }
    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); };
    }
    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
            return Reflect.metadata(metadataKey, metadataValue);
    }
    function __awaiter(thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try {
                step(generator.next(value));
            }
            catch (e) {
                reject(e);
            } }
            function rejected(value) { try {
                step(generator["throw"](value));
            }
            catch (e) {
                reject(e);
            } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }
    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function () { if (t[0] & 1)
                throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f)
                throw new TypeError("Generator is already executing.");
            while (_)
                try {
                    if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
                        return t;
                    if (y = 0, t)
                        op = [op[0] & 2, t.value];
                    switch (op[0]) {
                        case 0:
                        case 1:
                            t = op;
                            break;
                        case 4:
                            _.label++;
                            return { value: op[1], done: false };
                        case 5:
                            _.label++;
                            y = op[1];
                            op = [0];
                            continue;
                        case 7:
                            op = _.ops.pop();
                            _.trys.pop();
                            continue;
                        default:
                            if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                                _ = 0;
                                continue;
                            }
                            if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
                                _.label = op[1];
                                break;
                            }
                            if (op[0] === 6 && _.label < t[1]) {
                                _.label = t[1];
                                t = op;
                                break;
                            }
                            if (t && _.label < t[2]) {
                                _.label = t[2];
                                _.ops.push(op);
                                break;
                            }
                            if (t[2])
                                _.ops.pop();
                            _.trys.pop();
                            continue;
                    }
                    op = body.call(thisArg, _);
                }
                catch (e) {
                    op = [6, e];
                    y = 0;
                }
                finally {
                    f = t = 0;
                }
            if (op[0] & 5)
                throw op[1];
            return { value: op[0] ? op[1] : void 0, done: true };
        }
    }
    var __createBinding = Object.create ? (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
    }) : (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        o[k2] = m[k];
    });
    function __exportStar(m, o) {
        for (var p in m)
            if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
                __createBinding(o, m, p);
    }
    function __values(o) {
        var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
        if (m)
            return m.call(o);
        if (o && typeof o.length === "number")
            return {
                next: function () {
                    if (o && i >= o.length)
                        o = void 0;
                    return { value: o && o[i++], done: !o };
                }
            };
        throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
    }
    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m)
            return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
                ar.push(r.value);
        }
        catch (error) {
            e = { error: error };
        }
        finally {
            try {
                if (r && !r.done && (m = i["return"]))
                    m.call(i);
            }
            finally {
                if (e)
                    throw e.error;
            }
        }
        return ar;
    }
    /** @deprecated */
    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }
    /** @deprecated */
    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++)
            s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    }
    function __spreadArray(to, from) {
        for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
            to[j] = from[i];
        return to;
    }
    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }
    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n])
            i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try {
            step(g[n](v));
        }
        catch (e) {
            settle(q[0][3], e);
        } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length)
            resume(q[0][0], q[0][1]); }
    }
    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }
    function __asyncValues(o) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
    }
    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) {
            Object.defineProperty(cooked, "raw", { value: raw });
        }
        else {
            cooked.raw = raw;
        }
        return cooked;
    }
    ;
    var __setModuleDefault = Object.create ? (function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v });
    }) : function (o, v) {
        o["default"] = v;
    };
    function __importStar(mod) {
        if (mod && mod.__esModule)
            return mod;
        var result = {};
        if (mod != null)
            for (var k in mod)
                if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
                    __createBinding(result, mod, k);
        __setModuleDefault(result, mod);
        return result;
    }
    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }
    function __classPrivateFieldGet(receiver, privateMap) {
        if (!privateMap.has(receiver)) {
            throw new TypeError("attempted to get private field on non-instance");
        }
        return privateMap.get(receiver);
    }
    function __classPrivateFieldSet(receiver, privateMap, value) {
        if (!privateMap.has(receiver)) {
            throw new TypeError("attempted to set private field on non-instance");
        }
        privateMap.set(receiver, value);
        return value;
    }

    var UITreeNode = /** @class */ (function () {
        function UITreeNode(tree) {
            this.tree = tree;
        }
        UITreeNode.prototype.ngOnInit = function () {
            this.node.parent = this.parentNode;
            if (this.parentNode) {
                this.tree.syncNodeOption(this.node, this.tree.value, 'parent', this.tree.getNodeWithKey(this.parentNode.key, this.tree.value));
            }
        };
        UITreeNode.prototype.getIcon = function () {
            var icon;
            if (this.node.icon)
                icon = this.node.icon;
            else
                icon = this.node.expanded && this.node.children && this.node.children.length ? this.node.expandedIcon : this.node.collapsedIcon;
            return UITreeNode.ICON_CLASS + ' ' + icon;
        };
        UITreeNode.prototype.isLeaf = function () {
            return this.tree.isNodeLeaf(this.node);
        };
        UITreeNode.prototype.toggle = function (event) {
            if (this.node.expanded)
                this.collapse(event);
            else
                this.expand(event);
        };
        UITreeNode.prototype.expand = function (event) {
            this.node.expanded = true;
            if (this.tree.virtualScroll) {
                this.tree.updateSerializedValue();
            }
            this.tree.onNodeExpand.emit({ originalEvent: event, node: this.node });
        };
        UITreeNode.prototype.collapse = function (event) {
            this.node.expanded = false;
            if (this.tree.virtualScroll) {
                this.tree.updateSerializedValue();
            }
            this.tree.onNodeCollapse.emit({ originalEvent: event, node: this.node });
        };
        UITreeNode.prototype.onNodeClick = function (event) {
            this.tree.onNodeClick(event, this.node);
        };
        UITreeNode.prototype.onNodeKeydown = function (event) {
            if (event.which === 13) {
                this.tree.onNodeClick(event, this.node);
            }
        };
        UITreeNode.prototype.onNodeTouchEnd = function () {
            this.tree.onNodeTouchEnd();
        };
        UITreeNode.prototype.onNodeRightClick = function (event) {
            this.tree.onNodeRightClick(event, this.node);
        };
        UITreeNode.prototype.isSelected = function () {
            return this.tree.isSelected(this.node);
        };
        UITreeNode.prototype.onDropPoint = function (event, position) {
            var _this = this;
            event.preventDefault();
            var dragNode = this.tree.dragNode;
            var dragNodeIndex = this.tree.dragNodeIndex;
            var dragNodeScope = this.tree.dragNodeScope;
            var isValidDropPointIndex = this.tree.dragNodeTree === this.tree ? (position === 1 || dragNodeIndex !== this.index - 1) : true;
            if (this.tree.allowDrop(dragNode, this.node, dragNodeScope) && isValidDropPointIndex) {
                var dropParams_1 = Object.assign({}, this.createDropPointEventMetadata(position));
                if (this.tree.validateDrop) {
                    this.tree.onNodeDrop.emit({
                        originalEvent: event,
                        dragNode: dragNode,
                        dropNode: this.node,
                        index: this.index,
                        accept: function () {
                            _this.processPointDrop(dropParams_1);
                        }
                    });
                }
                else {
                    this.processPointDrop(dropParams_1);
                    this.tree.onNodeDrop.emit({
                        originalEvent: event,
                        dragNode: dragNode,
                        dropNode: this.node,
                        index: this.index
                    });
                }
            }
            this.draghoverPrev = false;
            this.draghoverNext = false;
        };
        UITreeNode.prototype.processPointDrop = function (event) {
            var newNodeList = event.dropNode.parent ? event.dropNode.parent.children : this.tree.value;
            event.dragNodeSubNodes.splice(event.dragNodeIndex, 1);
            var dropIndex = this.index;
            if (event.position < 0) {
                dropIndex = (event.dragNodeSubNodes === newNodeList) ? ((event.dragNodeIndex > event.index) ? event.index : event.index - 1) : event.index;
                newNodeList.splice(dropIndex, 0, event.dragNode);
            }
            else {
                dropIndex = newNodeList.length;
                newNodeList.push(event.dragNode);
            }
            this.tree.dragDropService.stopDrag({
                node: event.dragNode,
                subNodes: event.dropNode.parent ? event.dropNode.parent.children : this.tree.value,
                index: event.dragNodeIndex
            });
        };
        UITreeNode.prototype.createDropPointEventMetadata = function (position) {
            return {
                dragNode: this.tree.dragNode,
                dragNodeIndex: this.tree.dragNodeIndex,
                dragNodeSubNodes: this.tree.dragNodeSubNodes,
                dropNode: this.node,
                index: this.index,
                position: position
            };
        };
        UITreeNode.prototype.onDropPointDragOver = function (event) {
            event.dataTransfer.dropEffect = 'move';
            event.preventDefault();
        };
        UITreeNode.prototype.onDropPointDragEnter = function (event, position) {
            if (this.tree.allowDrop(this.tree.dragNode, this.node, this.tree.dragNodeScope)) {
                if (position < 0)
                    this.draghoverPrev = true;
                else
                    this.draghoverNext = true;
            }
        };
        UITreeNode.prototype.onDropPointDragLeave = function (event) {
            this.draghoverPrev = false;
            this.draghoverNext = false;
        };
        UITreeNode.prototype.onDragStart = function (event) {
            if (this.tree.draggableNodes && this.node.draggable !== false) {
                event.dataTransfer.setData("text", "data");
                this.tree.dragDropService.startDrag({
                    tree: this,
                    node: this.node,
                    subNodes: this.node.parent ? this.node.parent.children : this.tree.value,
                    index: this.index,
                    scope: this.tree.draggableScope
                });
            }
            else {
                event.preventDefault();
            }
        };
        UITreeNode.prototype.onDragStop = function (event) {
            this.tree.dragDropService.stopDrag({
                node: this.node,
                subNodes: this.node.parent ? this.node.parent.children : this.tree.value,
                index: this.index
            });
        };
        UITreeNode.prototype.onDropNodeDragOver = function (event) {
            event.dataTransfer.dropEffect = 'move';
            if (this.tree.droppableNodes) {
                event.preventDefault();
                event.stopPropagation();
            }
        };
        UITreeNode.prototype.onDropNode = function (event) {
            var _this = this;
            if (this.tree.droppableNodes && this.node.droppable !== false) {
                var dragNode = this.tree.dragNode;
                if (this.tree.allowDrop(dragNode, this.node, this.tree.dragNodeScope)) {
                    var dropParams_2 = Object.assign({}, this.createDropNodeEventMetadata());
                    if (this.tree.validateDrop) {
                        this.tree.onNodeDrop.emit({
                            originalEvent: event,
                            dragNode: dragNode,
                            dropNode: this.node,
                            index: this.index,
                            accept: function () {
                                _this.processNodeDrop(dropParams_2);
                            }
                        });
                    }
                    else {
                        this.processNodeDrop(dropParams_2);
                        this.tree.onNodeDrop.emit({
                            originalEvent: event,
                            dragNode: dragNode,
                            dropNode: this.node,
                            index: this.index
                        });
                    }
                }
            }
            event.preventDefault();
            event.stopPropagation();
            this.draghoverNode = false;
        };
        UITreeNode.prototype.createDropNodeEventMetadata = function () {
            return {
                dragNode: this.tree.dragNode,
                dragNodeIndex: this.tree.dragNodeIndex,
                dragNodeSubNodes: this.tree.dragNodeSubNodes,
                dropNode: this.node
            };
        };
        UITreeNode.prototype.processNodeDrop = function (event) {
            var dragNodeIndex = event.dragNodeIndex;
            event.dragNodeSubNodes.splice(dragNodeIndex, 1);
            if (event.dropNode.children)
                event.dropNode.children.push(event.dragNode);
            else
                event.dropNode.children = [event.dragNode];
            this.tree.dragDropService.stopDrag({
                node: event.dragNode,
                subNodes: event.dropNode.parent ? event.dropNode.parent.children : this.tree.value,
                index: dragNodeIndex
            });
        };
        UITreeNode.prototype.onDropNodeDragEnter = function (event) {
            if (this.tree.droppableNodes && this.node.droppable !== false && this.tree.allowDrop(this.tree.dragNode, this.node, this.tree.dragNodeScope)) {
                this.draghoverNode = true;
            }
        };
        UITreeNode.prototype.onDropNodeDragLeave = function (event) {
            if (this.tree.droppableNodes) {
                var rect = event.currentTarget.getBoundingClientRect();
                if (event.x > rect.left + rect.width || event.x < rect.left || event.y >= Math.floor(rect.top + rect.height) || event.y < rect.top) {
                    this.draghoverNode = false;
                }
            }
        };
        UITreeNode.prototype.onKeyDown = function (event) {
            var nodeElement = event.target.parentElement.parentElement;
            if (nodeElement.nodeName !== 'P-TREENODE' || (this.tree.contextMenu && this.tree.contextMenu.containerViewChild.nativeElement.style.display === 'block')) {
                return;
            }
            switch (event.which) {
                //down arrow
                case 40:
                    var listElement = (this.tree.droppableNodes) ? nodeElement.children[1].children[1] : nodeElement.children[0].children[1];
                    if (listElement && listElement.children.length > 0) {
                        this.focusNode(listElement.children[0]);
                    }
                    else {
                        var nextNodeElement = nodeElement.nextElementSibling;
                        if (nextNodeElement) {
                            this.focusNode(nextNodeElement);
                        }
                        else {
                            var nextSiblingAncestor = this.findNextSiblingOfAncestor(nodeElement);
                            if (nextSiblingAncestor) {
                                this.focusNode(nextSiblingAncestor);
                            }
                        }
                    }
                    event.preventDefault();
                    break;
                //up arrow
                case 38:
                    if (nodeElement.previousElementSibling) {
                        this.focusNode(this.findLastVisibleDescendant(nodeElement.previousElementSibling));
                    }
                    else {
                        var parentNodeElement = this.getParentNodeElement(nodeElement);
                        if (parentNodeElement) {
                            this.focusNode(parentNodeElement);
                        }
                    }
                    event.preventDefault();
                    break;
                //right arrow
                case 39:
                    if (!this.node.expanded && !this.tree.isNodeLeaf(this.node)) {
                        this.expand(event);
                    }
                    event.preventDefault();
                    break;
                //left arrow
                case 37:
                    if (this.node.expanded) {
                        this.collapse(event);
                    }
                    else {
                        var parentNodeElement = this.getParentNodeElement(nodeElement);
                        if (parentNodeElement) {
                            this.focusNode(parentNodeElement);
                        }
                    }
                    event.preventDefault();
                    break;
                //enter
                case 13:
                    this.tree.onNodeClick(event, this.node);
                    event.preventDefault();
                    break;
                default:
                    //no op
                    break;
            }
        };
        UITreeNode.prototype.findNextSiblingOfAncestor = function (nodeElement) {
            var parentNodeElement = this.getParentNodeElement(nodeElement);
            if (parentNodeElement) {
                if (parentNodeElement.nextElementSibling)
                    return parentNodeElement.nextElementSibling;
                else
                    return this.findNextSiblingOfAncestor(parentNodeElement);
            }
            else {
                return null;
            }
        };
        UITreeNode.prototype.findLastVisibleDescendant = function (nodeElement) {
            var listElement = Array.from(nodeElement.children).find(function (el) { return dom.DomHandler.hasClass(el, 'p-treenode'); });
            var childrenListElement = listElement.children[1];
            if (childrenListElement && childrenListElement.children.length > 0) {
                var lastChildElement = childrenListElement.children[childrenListElement.children.length - 1];
                return this.findLastVisibleDescendant(lastChildElement);
            }
            else {
                return nodeElement;
            }
        };
        UITreeNode.prototype.getParentNodeElement = function (nodeElement) {
            var parentNodeElement = nodeElement.parentElement.parentElement.parentElement;
            return parentNodeElement.tagName === 'P-TREENODE' ? parentNodeElement : null;
        };
        UITreeNode.prototype.focusNode = function (element) {
            if (this.tree.droppableNodes)
                element.children[1].children[0].focus();
            else
                element.children[0].children[0].focus();
        };
        return UITreeNode;
    }());
    UITreeNode.ICON_CLASS = 'p-treenode-icon ';
    UITreeNode.decorators = [
        { type: core.Component, args: [{
                    selector: 'p-treeNode',
                    template: "\n        <ng-template [ngIf]=\"node\">\n            <li *ngIf=\"tree.droppableNodes\" class=\"p-treenode-droppoint\" [ngClass]=\"{'p-treenode-droppoint-active':draghoverPrev}\"\n            (drop)=\"onDropPoint($event,-1)\" (dragover)=\"onDropPointDragOver($event)\" (dragenter)=\"onDropPointDragEnter($event,-1)\" (dragleave)=\"onDropPointDragLeave($event)\"></li>\n            <li *ngIf=\"!tree.horizontal\" [ngClass]=\"['p-treenode',node.styleClass||'', isLeaf() ? 'p-treenode-leaf': '']\">\n                <div class=\"p-treenode-content\" [style.paddingLeft]=\"(level * indentation)  + 'rem'\" (click)=\"onNodeClick($event)\" (contextmenu)=\"onNodeRightClick($event)\" (touchend)=\"onNodeTouchEnd()\"\n                    (drop)=\"onDropNode($event)\" (dragover)=\"onDropNodeDragOver($event)\" (dragenter)=\"onDropNodeDragEnter($event)\" (dragleave)=\"onDropNodeDragLeave($event)\"\n                    [draggable]=\"tree.draggableNodes\" (dragstart)=\"onDragStart($event)\" (dragend)=\"onDragStop($event)\" [attr.tabindex]=\"0\"\n                    [ngClass]=\"{'p-treenode-selectable':tree.selectionMode && node.selectable !== false,'p-treenode-dragover':draghoverNode, 'p-highlight':isSelected()}\" role=\"treeitem\"\n                    (keydown)=\"onKeyDown($event)\" [attr.aria-posinset]=\"this.index + 1\" [attr.aria-expanded]=\"this.node.expanded\" [attr.aria-selected]=\"isSelected()\" [attr.aria-label]=\"node.label\">\n                    <button type=\"button\" class=\"p-tree-toggler p-link\" (click)=\"toggle($event)\" pRipple tabindex=\"-1\">\n                        <span class=\"p-tree-toggler-icon pi pi-fw\" [ngClass]=\"{'pi-chevron-right':!node.expanded,'pi-chevron-down':node.expanded}\"></span>\n                    </button>\n                    <div class=\"p-checkbox p-component\" [ngClass]=\"{'p-checkbox-disabled': node.selectable === false}\" *ngIf=\"tree.selectionMode == 'checkbox'\" [attr.aria-checked]=\"isSelected()\">\n                        <div class=\"p-checkbox-box\" [ngClass]=\"{'p-highlight': isSelected(), 'p-indeterminate': node.partialSelected}\">\n                            <span class=\"p-checkbox-icon pi\" [ngClass]=\"{'pi-check':isSelected(),'pi-minus':node.partialSelected}\"></span>\n                        </div>\n                    </div>\n                    <span [class]=\"getIcon()\" *ngIf=\"node.icon||node.expandedIcon||node.collapsedIcon\"></span>\n                    <span class=\"p-treenode-label\">\n                            <span *ngIf=\"!tree.getTemplateForNode(node)\">{{node.label}}</span>\n                            <span *ngIf=\"tree.getTemplateForNode(node)\">\n                                <ng-container *ngTemplateOutlet=\"tree.getTemplateForNode(node); context: {$implicit: node}\"></ng-container>\n                            </span>\n                    </span>\n                </div>\n                <ul class=\"p-treenode-children\" style=\"display: none;\" *ngIf=\"!tree.virtualScroll && node.children && node.expanded\" [style.display]=\"node.expanded ? 'block' : 'none'\" role=\"group\">\n                    <p-treeNode *ngFor=\"let childNode of node.children;let firstChild=first;let lastChild=last; let index=index; trackBy: tree.trackBy\" [node]=\"childNode\" [parentNode]=\"node\"\n                        [firstChild]=\"firstChild\" [lastChild]=\"lastChild\" [index]=\"index\" [style.height.px]=\"tree.virtualNodeHeight\" [level]=\"level + 1\"></p-treeNode>\n                </ul>\n            </li>\n            <li *ngIf=\"tree.droppableNodes&&lastChild\" class=\"p-treenode-droppoint\" [ngClass]=\"{'p-treenode-droppoint-active':draghoverNext}\"\n            (drop)=\"onDropPoint($event,1)\" (dragover)=\"onDropPointDragOver($event)\" (dragenter)=\"onDropPointDragEnter($event,1)\" (dragleave)=\"onDropPointDragLeave($event)\"></li>\n            <table *ngIf=\"tree.horizontal\" [class]=\"node.styleClass\">\n                <tbody>\n                    <tr>\n                        <td class=\"p-treenode-connector\" *ngIf=\"!root\">\n                            <table class=\"p-treenode-connector-table\">\n                                <tbody>\n                                    <tr>\n                                        <td [ngClass]=\"{'p-treenode-connector-line':!firstChild}\"></td>\n                                    </tr>\n                                    <tr>\n                                        <td [ngClass]=\"{'p-treenode-connector-line':!lastChild}\"></td>\n                                    </tr>\n                                </tbody>\n                            </table>\n                        </td>\n                        <td class=\"p-treenode\" [ngClass]=\"{'p-treenode-collapsed':!node.expanded}\">\n                            <div class=\"p-treenode-content\" tabindex=\"0\" [ngClass]=\"{'p-treenode-selectable':tree.selectionMode,'p-highlight':isSelected()}\" (click)=\"onNodeClick($event)\" (contextmenu)=\"onNodeRightClick($event)\"\n                                (touchend)=\"onNodeTouchEnd()\" (keydown)=\"onNodeKeydown($event)\">\n                                <span class=\"p-tree-toggler pi pi-fw\" [ngClass]=\"{'pi-plus':!node.expanded,'pi-minus':node.expanded}\" *ngIf=\"!isLeaf()\" (click)=\"toggle($event)\"></span>\n                                <span [class]=\"getIcon()\" *ngIf=\"node.icon||node.expandedIcon||node.collapsedIcon\"></span>\n                                <span class=\"p-treenode-label\">\n                                    <span *ngIf=\"!tree.getTemplateForNode(node)\">{{node.label}}</span>\n                                    <span *ngIf=\"tree.getTemplateForNode(node)\">\n                                        <ng-container *ngTemplateOutlet=\"tree.getTemplateForNode(node); context: {$implicit: node}\"></ng-container>\n                                    </span>\n                                </span>\n                            </div>\n                        </td>\n                        <td class=\"p-treenode-children-container\" *ngIf=\"node.children && node.expanded\" [style.display]=\"node.expanded ? 'table-cell' : 'none'\">\n                            <div class=\"p-treenode-children\">\n                                <p-treeNode *ngFor=\"let childNode of node.children;let firstChild=first;let lastChild=last; trackBy: tree.trackBy\" [node]=\"childNode\"\n                                        [firstChild]=\"firstChild\" [lastChild]=\"lastChild\"></p-treeNode>\n                            </div>\n                        </td>\n                    </tr>\n                </tbody>\n            </table>\n        </ng-template>\n    ",
                    encapsulation: core.ViewEncapsulation.None
                },] }
    ];
    UITreeNode.ctorParameters = function () { return [
        { type: undefined, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return Tree; }),] }] }
    ]; };
    UITreeNode.propDecorators = {
        rowNode: [{ type: core.Input }],
        node: [{ type: core.Input }],
        parentNode: [{ type: core.Input }],
        root: [{ type: core.Input }],
        index: [{ type: core.Input }],
        firstChild: [{ type: core.Input }],
        lastChild: [{ type: core.Input }],
        level: [{ type: core.Input }],
        indentation: [{ type: core.Input }]
    };
    var Tree = /** @class */ (function () {
        function Tree(el, dragDropService) {
            this.el = el;
            this.dragDropService = dragDropService;
            this.selectionChange = new core.EventEmitter();
            this.onNodeSelect = new core.EventEmitter();
            this.onNodeUnselect = new core.EventEmitter();
            this.onNodeExpand = new core.EventEmitter();
            this.onNodeCollapse = new core.EventEmitter();
            this.onNodeContextMenuSelect = new core.EventEmitter();
            this.onNodeDrop = new core.EventEmitter();
            this.layout = 'vertical';
            this.metaKeySelection = true;
            this.propagateSelectionUp = true;
            this.propagateSelectionDown = true;
            this.loadingIcon = 'pi pi-spinner';
            this.emptyMessage = 'No records found';
            this.filterBy = 'label';
            this.filterMode = 'lenient';
            this.indentation = 1.5;
            this.trackBy = function (index, item) { return item; };
            this.onFilter = new core.EventEmitter();
        }
        Tree.prototype.ngOnInit = function () {
            var _this = this;
            if (this.droppableNodes) {
                this.dragStartSubscription = this.dragDropService.dragStart$.subscribe(function (event) {
                    _this.dragNodeTree = event.tree;
                    _this.dragNode = event.node;
                    _this.dragNodeSubNodes = event.subNodes;
                    _this.dragNodeIndex = event.index;
                    _this.dragNodeScope = event.scope;
                });
                this.dragStopSubscription = this.dragDropService.dragStop$.subscribe(function (event) {
                    _this.dragNodeTree = null;
                    _this.dragNode = null;
                    _this.dragNodeSubNodes = null;
                    _this.dragNodeIndex = null;
                    _this.dragNodeScope = null;
                    _this.dragHover = false;
                });
            }
        };
        Tree.prototype.ngOnChanges = function (simpleChange) {
            if (simpleChange.value) {
                this.updateSerializedValue();
            }
            if (simpleChange.scrollHeight && this.virtualScrollBody) {
                this.virtualScrollBody.ngOnInit();
            }
        };
        Object.defineProperty(Tree.prototype, "horizontal", {
            get: function () {
                return this.layout == 'horizontal';
            },
            enumerable: false,
            configurable: true
        });
        Tree.prototype.ngAfterContentInit = function () {
            var _this = this;
            if (this.templates.length) {
                this.templateMap = {};
            }
            this.templates.forEach(function (item) {
                _this.templateMap[item.name] = item.template;
            });
        };
        Tree.prototype.updateSerializedValue = function () {
            this.serializedValue = [];
            this.serializeNodes(null, this.getRootNode(), 0, true);
        };
        Tree.prototype.serializeNodes = function (parent, nodes, level, visible) {
            var e_1, _a;
            if (nodes && nodes.length) {
                try {
                    for (var nodes_1 = __values(nodes), nodes_1_1 = nodes_1.next(); !nodes_1_1.done; nodes_1_1 = nodes_1.next()) {
                        var node = nodes_1_1.value;
                        node.parent = parent;
                        var rowNode = {
                            node: node,
                            parent: parent,
                            level: level,
                            visible: visible && (parent ? parent.expanded : true)
                        };
                        this.serializedValue.push(rowNode);
                        if (rowNode.visible && node.expanded) {
                            this.serializeNodes(node, node.children, level + 1, rowNode.visible);
                        }
                    }
                }
                catch (e_1_1) { e_1 = { error: e_1_1 }; }
                finally {
                    try {
                        if (nodes_1_1 && !nodes_1_1.done && (_a = nodes_1.return)) _a.call(nodes_1);
                    }
                    finally { if (e_1) throw e_1.error; }
                }
            }
        };
        Tree.prototype.onNodeClick = function (event, node) {
            var eventTarget = event.target;
            if (dom.DomHandler.hasClass(eventTarget, 'p-tree-toggler') || dom.DomHandler.hasClass(eventTarget, 'p-tree-toggler-icon')) {
                return;
            }
            else if (this.selectionMode) {
                if (node.selectable === false) {
                    return;
                }
                if (this.hasFilteredNodes()) {
                    node = this.getNodeWithKey(node.key, this.value);
                    if (!node) {
                        return;
                    }
                }
                var index_1 = this.findIndexInSelection(node);
                var selected = (index_1 >= 0);
                if (this.isCheckboxSelectionMode()) {
                    if (selected) {
                        if (this.propagateSelectionDown)
                            this.propagateDown(node, false);
                        else
                            this.selection = this.selection.filter(function (val, i) { return i != index_1; });
                        if (this.propagateSelectionUp && node.parent) {
                            this.propagateUp(node.parent, false);
                        }
                        this.selectionChange.emit(this.selection);
                        this.onNodeUnselect.emit({ originalEvent: event, node: node });
                    }
                    else {
                        if (this.propagateSelectionDown)
                            this.propagateDown(node, true);
                        else
                            this.selection = __spread(this.selection || [], [node]);
                        if (this.propagateSelectionUp && node.parent) {
                            this.propagateUp(node.parent, true);
                        }
                        this.selectionChange.emit(this.selection);
                        this.onNodeSelect.emit({ originalEvent: event, node: node });
                    }
                }
                else {
                    var metaSelection = this.nodeTouched ? false : this.metaKeySelection;
                    if (metaSelection) {
                        var metaKey = (event.metaKey || event.ctrlKey);
                        if (selected && metaKey) {
                            if (this.isSingleSelectionMode()) {
                                this.selectionChange.emit(null);
                            }
                            else {
                                this.selection = this.selection.filter(function (val, i) { return i != index_1; });
                                this.selectionChange.emit(this.selection);
                            }
                            this.onNodeUnselect.emit({ originalEvent: event, node: node });
                        }
                        else {
                            if (this.isSingleSelectionMode()) {
                                this.selectionChange.emit(node);
                            }
                            else if (this.isMultipleSelectionMode()) {
                                this.selection = (!metaKey) ? [] : this.selection || [];
                                this.selection = __spread(this.selection, [node]);
                                this.selectionChange.emit(this.selection);
                            }
                            this.onNodeSelect.emit({ originalEvent: event, node: node });
                        }
                    }
                    else {
                        if (this.isSingleSelectionMode()) {
                            if (selected) {
                                this.selection = null;
                                this.onNodeUnselect.emit({ originalEvent: event, node: node });
                            }
                            else {
                                this.selection = node;
                                this.onNodeSelect.emit({ originalEvent: event, node: node });
                            }
                        }
                        else {
                            if (selected) {
                                this.selection = this.selection.filter(function (val, i) { return i != index_1; });
                                this.onNodeUnselect.emit({ originalEvent: event, node: node });
                            }
                            else {
                                this.selection = __spread(this.selection || [], [node]);
                                this.onNodeSelect.emit({ originalEvent: event, node: node });
                            }
                        }
                        this.selectionChange.emit(this.selection);
                    }
                }
            }
            this.nodeTouched = false;
        };
        Tree.prototype.onNodeTouchEnd = function () {
            this.nodeTouched = true;
        };
        Tree.prototype.onNodeRightClick = function (event, node) {
            if (this.contextMenu) {
                var eventTarget = event.target;
                if (eventTarget.className && eventTarget.className.indexOf('p-tree-toggler') === 0) {
                    return;
                }
                else {
                    var index = this.findIndexInSelection(node);
                    var selected = (index >= 0);
                    if (!selected) {
                        if (this.isSingleSelectionMode())
                            this.selectionChange.emit(node);
                        else
                            this.selectionChange.emit([node]);
                    }
                    this.contextMenu.show(event);
                    this.onNodeContextMenuSelect.emit({ originalEvent: event, node: node });
                }
            }
        };
        Tree.prototype.findIndexInSelection = function (node) {
            var index = -1;
            if (this.selectionMode && this.selection) {
                if (this.isSingleSelectionMode()) {
                    var areNodesEqual = (this.selection.key && this.selection.key === node.key) || this.selection == node;
                    index = areNodesEqual ? 0 : -1;
                }
                else {
                    for (var i = 0; i < this.selection.length; i++) {
                        var selectedNode = this.selection[i];
                        var areNodesEqual = (selectedNode.key && selectedNode.key === node.key) || selectedNode == node;
                        if (areNodesEqual) {
                            index = i;
                            break;
                        }
                    }
                }
            }
            return index;
        };
        Tree.prototype.syncNodeOption = function (node, parentNodes, option, value) {
            // to synchronize the node option between the filtered nodes and the original nodes(this.value)
            var _node = this.hasFilteredNodes() ? this.getNodeWithKey(node.key, parentNodes) : null;
            if (_node) {
                _node[option] = value || node[option];
            }
        };
        Tree.prototype.hasFilteredNodes = function () {
            return this.filter && this.filteredNodes && this.filteredNodes.length;
        };
        Tree.prototype.getNodeWithKey = function (key, nodes) {
            var e_2, _a;
            try {
                for (var nodes_2 = __values(nodes), nodes_2_1 = nodes_2.next(); !nodes_2_1.done; nodes_2_1 = nodes_2.next()) {
                    var node = nodes_2_1.value;
                    if (node.key === key) {
                        return node;
                    }
                    if (node.children) {
                        var matchedNode = this.getNodeWithKey(key, node.children);
                        if (matchedNode) {
                            return matchedNode;
                        }
                    }
                }
            }
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
            finally {
                try {
                    if (nodes_2_1 && !nodes_2_1.done && (_a = nodes_2.return)) _a.call(nodes_2);
                }
                finally { if (e_2) throw e_2.error; }
            }
        };
        Tree.prototype.propagateUp = function (node, select) {
            var e_3, _a;
            if (node.children && node.children.length) {
                var selectedCount = 0;
                var childPartialSelected = false;
                try {
                    for (var _b = __values(node.children), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var child = _c.value;
                        if (this.isSelected(child)) {
                            selectedCount++;
                        }
                        else if (child.partialSelected) {
                            childPartialSelected = true;
                        }
                    }
                }
                catch (e_3_1) { e_3 = { error: e_3_1 }; }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                    }
                    finally { if (e_3) throw e_3.error; }
                }
                if (select && selectedCount == node.children.length) {
                    this.selection = __spread(this.selection || [], [node]);
                    node.partialSelected = false;
                }
                else {
                    if (!select) {
                        var index_2 = this.findIndexInSelection(node);
                        if (index_2 >= 0) {
                            this.selection = this.selection.filter(function (val, i) { return i != index_2; });
                        }
                    }
                    if (childPartialSelected || selectedCount > 0 && selectedCount != node.children.length)
                        node.partialSelected = true;
                    else
                        node.partialSelected = false;
                }
                this.syncNodeOption(node, this.filteredNodes, 'partialSelected');
            }
            var parent = node.parent;
            if (parent) {
                this.propagateUp(parent, select);
            }
        };
        Tree.prototype.propagateDown = function (node, select) {
            var e_4, _a;
            var index = this.findIndexInSelection(node);
            if (select && index == -1) {
                this.selection = __spread(this.selection || [], [node]);
            }
            else if (!select && index > -1) {
                this.selection = this.selection.filter(function (val, i) { return i != index; });
            }
            node.partialSelected = false;
            this.syncNodeOption(node, this.filteredNodes, 'partialSelected');
            if (node.children && node.children.length) {
                try {
                    for (var _b = __values(node.children), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var child = _c.value;
                        this.propagateDown(child, select);
                    }
                }
                catch (e_4_1) { e_4 = { error: e_4_1 }; }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                    }
                    finally { if (e_4) throw e_4.error; }
                }
            }
        };
        Tree.prototype.isSelected = function (node) {
            return this.findIndexInSelection(node) != -1;
        };
        Tree.prototype.isSingleSelectionMode = function () {
            return this.selectionMode && this.selectionMode == 'single';
        };
        Tree.prototype.isMultipleSelectionMode = function () {
            return this.selectionMode && this.selectionMode == 'multiple';
        };
        Tree.prototype.isCheckboxSelectionMode = function () {
            return this.selectionMode && this.selectionMode == 'checkbox';
        };
        Tree.prototype.isNodeLeaf = function (node) {
            return node.leaf == false ? false : !(node.children && node.children.length);
        };
        Tree.prototype.getRootNode = function () {
            return this.filteredNodes ? this.filteredNodes : this.value;
        };
        Tree.prototype.getTemplateForNode = function (node) {
            if (this.templateMap)
                return node.type ? this.templateMap[node.type] : this.templateMap['default'];
            else
                return null;
        };
        Tree.prototype.onDragOver = function (event) {
            if (this.droppableNodes && (!this.value || this.value.length === 0)) {
                event.dataTransfer.dropEffect = 'move';
                event.preventDefault();
            }
        };
        Tree.prototype.onDrop = function (event) {
            if (this.droppableNodes && (!this.value || this.value.length === 0)) {
                event.preventDefault();
                var dragNode = this.dragNode;
                if (this.allowDrop(dragNode, null, this.dragNodeScope)) {
                    var dragNodeIndex = this.dragNodeIndex;
                    this.dragNodeSubNodes.splice(dragNodeIndex, 1);
                    this.value = this.value || [];
                    if (this.value.length === 0) {
                        this.onNodeDrop.emit({
                            originalEvent: event,
                            dragNode: dragNode,
                            dropNode: null,
                            index: dragNodeIndex
                        });
                    }
                    this.value.push(dragNode);
                    this.dragDropService.stopDrag({
                        node: dragNode
                    });
                }
            }
        };
        Tree.prototype.onDragEnter = function (event) {
            if (this.droppableNodes && this.allowDrop(this.dragNode, null, this.dragNodeScope)) {
                this.dragHover = true;
            }
        };
        Tree.prototype.onDragLeave = function (event) {
            if (this.droppableNodes) {
                var rect = event.currentTarget.getBoundingClientRect();
                if (event.x > rect.left + rect.width || event.x < rect.left || event.y > rect.top + rect.height || event.y < rect.top) {
                    this.dragHover = false;
                }
            }
        };
        Tree.prototype.allowDrop = function (dragNode, dropNode, dragNodeScope) {
            if (!dragNode) {
                //prevent random html elements to be dragged
                return false;
            }
            else if (this.isValidDragScope(dragNodeScope)) {
                var allow = true;
                if (dropNode) {
                    if (dragNode === dropNode) {
                        allow = false;
                    }
                    else {
                        var parent = dropNode.parent;
                        while (parent != null) {
                            if (parent === dragNode) {
                                allow = false;
                                break;
                            }
                            parent = parent.parent;
                        }
                    }
                }
                return allow;
            }
            else {
                return false;
            }
        };
        Tree.prototype.isValidDragScope = function (dragScope) {
            var e_5, _a, e_6, _b;
            var dropScope = this.droppableScope;
            if (dropScope) {
                if (typeof dropScope === 'string') {
                    if (typeof dragScope === 'string')
                        return dropScope === dragScope;
                    else if (dragScope instanceof Array)
                        return dragScope.indexOf(dropScope) != -1;
                }
                else if (dropScope instanceof Array) {
                    if (typeof dragScope === 'string') {
                        return dropScope.indexOf(dragScope) != -1;
                    }
                    else if (dragScope instanceof Array) {
                        try {
                            for (var dropScope_1 = __values(dropScope), dropScope_1_1 = dropScope_1.next(); !dropScope_1_1.done; dropScope_1_1 = dropScope_1.next()) {
                                var s = dropScope_1_1.value;
                                try {
                                    for (var dragScope_1 = (e_6 = void 0, __values(dragScope)), dragScope_1_1 = dragScope_1.next(); !dragScope_1_1.done; dragScope_1_1 = dragScope_1.next()) {
                                        var ds = dragScope_1_1.value;
                                        if (s === ds) {
                                            return true;
                                        }
                                    }
                                }
                                catch (e_6_1) { e_6 = { error: e_6_1 }; }
                                finally {
                                    try {
                                        if (dragScope_1_1 && !dragScope_1_1.done && (_b = dragScope_1.return)) _b.call(dragScope_1);
                                    }
                                    finally { if (e_6) throw e_6.error; }
                                }
                            }
                        }
                        catch (e_5_1) { e_5 = { error: e_5_1 }; }
                        finally {
                            try {
                                if (dropScope_1_1 && !dropScope_1_1.done && (_a = dropScope_1.return)) _a.call(dropScope_1);
                            }
                            finally { if (e_5) throw e_5.error; }
                        }
                    }
                }
                return false;
            }
            else {
                return true;
            }
        };
        Tree.prototype._filter = function (event) {
            var e_7, _a;
            var filterValue = event.target.value;
            if (filterValue === '') {
                this.filteredNodes = null;
            }
            else {
                this.filteredNodes = [];
                var searchFields = this.filterBy.split(',');
                var filterText = utils.ObjectUtils.removeAccents(filterValue).toLocaleLowerCase(this.filterLocale);
                var isStrictMode = this.filterMode === 'strict';
                try {
                    for (var _b = __values(this.value), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var node = _c.value;
                        var copyNode = Object.assign({}, node);
                        var paramsWithoutNode = { searchFields: searchFields, filterText: filterText, isStrictMode: isStrictMode };
                        if ((isStrictMode && (this.findFilteredNodes(copyNode, paramsWithoutNode) || this.isFilterMatched(copyNode, paramsWithoutNode))) ||
                            (!isStrictMode && (this.isFilterMatched(copyNode, paramsWithoutNode) || this.findFilteredNodes(copyNode, paramsWithoutNode)))) {
                            this.filteredNodes.push(copyNode);
                        }
                    }
                }
                catch (e_7_1) { e_7 = { error: e_7_1 }; }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                    }
                    finally { if (e_7) throw e_7.error; }
                }
            }
            this.updateSerializedValue();
            this.onFilter.emit({
                filter: filterValue,
                filteredValue: this.filteredNodes
            });
        };
        Tree.prototype.findFilteredNodes = function (node, paramsWithoutNode) {
            var e_8, _a;
            if (node) {
                var matched = false;
                if (node.children) {
                    var childNodes = __spread(node.children);
                    node.children = [];
                    try {
                        for (var childNodes_1 = __values(childNodes), childNodes_1_1 = childNodes_1.next(); !childNodes_1_1.done; childNodes_1_1 = childNodes_1.next()) {
                            var childNode = childNodes_1_1.value;
                            var copyChildNode = Object.assign({}, childNode);
                            if (this.isFilterMatched(copyChildNode, paramsWithoutNode)) {
                                matched = true;
                                node.children.push(copyChildNode);
                            }
                        }
                    }
                    catch (e_8_1) { e_8 = { error: e_8_1 }; }
                    finally {
                        try {
                            if (childNodes_1_1 && !childNodes_1_1.done && (_a = childNodes_1.return)) _a.call(childNodes_1);
                        }
                        finally { if (e_8) throw e_8.error; }
                    }
                }
                if (matched) {
                    node.expanded = true;
                    return true;
                }
            }
        };
        Tree.prototype.isFilterMatched = function (node, _a) {
            var e_9, _b;
            var searchFields = _a.searchFields, filterText = _a.filterText, isStrictMode = _a.isStrictMode;
            var matched = false;
            try {
                for (var searchFields_1 = __values(searchFields), searchFields_1_1 = searchFields_1.next(); !searchFields_1_1.done; searchFields_1_1 = searchFields_1.next()) {
                    var field = searchFields_1_1.value;
                    var fieldValue = utils.ObjectUtils.removeAccents(String(utils.ObjectUtils.resolveFieldData(node, field))).toLocaleLowerCase(this.filterLocale);
                    if (fieldValue.indexOf(filterText) > -1) {
                        matched = true;
                    }
                }
            }
            catch (e_9_1) { e_9 = { error: e_9_1 }; }
            finally {
                try {
                    if (searchFields_1_1 && !searchFields_1_1.done && (_b = searchFields_1.return)) _b.call(searchFields_1);
                }
                finally { if (e_9) throw e_9.error; }
            }
            if (!matched || (isStrictMode && !this.isNodeLeaf(node))) {
                matched = this.findFilteredNodes(node, { searchFields: searchFields, filterText: filterText, isStrictMode: isStrictMode }) || matched;
            }
            return matched;
        };
        Tree.prototype.getBlockableElement = function () {
            return this.el.nativeElement.children[0];
        };
        Tree.prototype.ngOnDestroy = function () {
            if (this.dragStartSubscription) {
                this.dragStartSubscription.unsubscribe();
            }
            if (this.dragStopSubscription) {
                this.dragStopSubscription.unsubscribe();
            }
        };
        return Tree;
    }());
    Tree.decorators = [
        { type: core.Component, args: [{
                    selector: 'p-tree',
                    template: "\n        <div [ngClass]=\"{'p-tree p-component':true,'p-tree-selectable':selectionMode,\n                'p-treenode-dragover':dragHover,'p-tree-loading': loading, 'p-tree-flex-scrollable': scrollHeight === 'flex'}\" \n            [ngStyle]=\"style\" [class]=\"styleClass\" *ngIf=\"!horizontal\"\n            (drop)=\"onDrop($event)\" (dragover)=\"onDragOver($event)\" (dragenter)=\"onDragEnter($event)\" (dragleave)=\"onDragLeave($event)\">\n            <div class=\"p-tree-loading-overlay p-component-overlay\" *ngIf=\"loading\">\n                <i [class]=\"'p-tree-loading-icon pi-spin ' + loadingIcon\"></i>\n            </div>\n            <div *ngIf=\"filter\" class=\"p-tree-filter-container\">\n                <input #filter type=\"text\" autocomplete=\"off\" class=\"p-tree-filter p-inputtext p-component\" [attr.placeholder]=\"filterPlaceholder\"\n                    (keydown.enter)=\"$event.preventDefault()\" (input)=\"_filter($event)\">\n                    <span class=\"p-tree-filter-icon pi pi-search\"></span>\n            </div>\n            <ng-container *ngIf=\"!virtualScroll; else virtualScrollList\">\n                <div class=\"p-tree-wrapper\" [style.max-height]=\"scrollHeight\">\n                    <ul class=\"p-tree-container\" *ngIf=\"getRootNode()\" role=\"tree\" [attr.aria-label]=\"ariaLabel\" [attr.aria-labelledby]=\"ariaLabelledBy\">\n                        <p-treeNode *ngFor=\"let node of getRootNode(); let firstChild=first;let lastChild=last; let index=index; trackBy: trackBy\" [node]=\"node\"\n                                    [firstChild]=\"firstChild\" [lastChild]=\"lastChild\" [index]=\"index\" [level]=\"0\"></p-treeNode>\n                    </ul>\n                </div>\n            </ng-container>\n            <ng-template #virtualScrollList>\n                <cdk-virtual-scroll-viewport class=\"p-tree-wrapper\" [style.height]=\"scrollHeight\" [itemSize]=\"virtualNodeHeight\" [minBufferPx]=\"minBufferPx\" [maxBufferPx]=\"maxBufferPx\">\n                    <ul class=\"p-tree-container\" *ngIf=\"getRootNode()\" role=\"tree\" [attr.aria-label]=\"ariaLabel\" [attr.aria-labelledby]=\"ariaLabelledBy\">\n                        <p-treeNode *cdkVirtualFor=\"let rowNode of serializedValue; let firstChild=first; let lastChild=last; let index=index; trackBy: trackBy; templateCacheSize: 0\"  [level]=\"rowNode.level\"\n                                    [rowNode]=\"rowNode\" [node]=\"rowNode.node\" [firstChild]=\"firstChild\" [lastChild]=\"lastChild\" [index]=\"index\" [style.height.px]=\"virtualNodeHeight\" [indentation]=\"indentation\"></p-treeNode>\n                    </ul>\n                </cdk-virtual-scroll-viewport>\n            </ng-template>\n            <div class=\"p-tree-empty-message\" *ngIf=\"!loading && (value == null || value.length === 0)\">{{emptyMessage}}</div>\n        </div>\n        <div [ngClass]=\"{'p-tree p-tree-horizontal p-component':true,'p-tree-selectable':selectionMode}\"  [ngStyle]=\"style\" [class]=\"styleClass\" *ngIf=\"horizontal\">\n            <div class=\"p-tree-loading-mask p-component-overlay\" *ngIf=\"loading\">\n                <i [class]=\"'p-tree-loading-icon pi-spin ' + loadingIcon\"></i>\n            </div>\n            <table *ngIf=\"value&&value[0]\">\n                <p-treeNode [node]=\"value[0]\" [root]=\"true\"></p-treeNode>\n            </table>\n            <div class=\"p-tree-empty-message\" *ngIf=\"!loading && (value == null || value.length === 0)\">{{emptyMessage}}</div>\n        </div>\n    ",
                    changeDetection: core.ChangeDetectionStrategy.Default,
                    encapsulation: core.ViewEncapsulation.None,
                    styles: [".p-tree-container{overflow:auto}.p-tree-container,.p-treenode-children{list-style-type:none;margin:0;padding:0}.p-tree-wrapper{overflow:auto}.p-tree-toggler,.p-treenode-selectable{-ms-user-select:none;-webkit-user-select:none;cursor:pointer;user-select:none}.p-tree-toggler{align-items:center;display:inline-flex;justify-content:center;overflow:hidden;position:relative}.p-treenode-leaf>.p-treenode-content .p-tree-toggler{visibility:hidden}.p-treenode-content{align-items:center;display:flex}.p-tree-filter{width:100%}.p-tree-filter-container{display:block;position:relative;width:100%}.p-tree-filter-icon{margin-top:-.5rem;position:absolute;top:50%}.p-tree-loading{min-height:4rem;position:relative}.p-tree .p-tree-loading-overlay{align-items:center;display:flex;justify-content:center;position:absolute;z-index:2}.p-tree-flex-scrollable{display:flex;flex:1;flex-direction:column;height:100%}.p-tree-flex-scrollable .p-tree-wrapper{flex:1}.p-tree .p-treenode-droppoint{height:4px;list-style-type:none}.p-tree .p-treenode-droppoint-active{border:0}.p-tree-horizontal{overflow:auto;padding-left:0;padding-right:0;width:auto}.p-tree.p-tree-horizontal table,.p-tree.p-tree-horizontal td,.p-tree.p-tree-horizontal tr{border-collapse:collapse;margin:0;padding:0;vertical-align:middle}.p-tree-horizontal .p-treenode-content{align-items:center;display:flex;font-weight:400;padding:.4em 1em .4em .2em}.p-tree-horizontal .p-treenode-parent .p-treenode-content{font-weight:400;white-space:nowrap}.p-tree.p-tree-horizontal .p-treenode{background:url(\"data:image/gif;base64, \") repeat-x scroll 50% transparent;padding:.25rem 2.5rem}.p-tree.p-tree-horizontal .p-treenode.p-treenode-collapsed,.p-tree.p-tree-horizontal .p-treenode.p-treenode-leaf{padding-right:0}.p-tree.p-tree-horizontal .p-treenode-children{margin:0;padding:0}.p-tree.p-tree-horizontal .p-treenode-connector{width:1px}.p-tree.p-tree-horizontal .p-treenode-connector-table{height:100%;width:1px}.p-tree.p-tree-horizontal .p-treenode-connector-line{background:url(\"data:image/gif;base64, \") repeat-y scroll 0 0 transparent;width:1px}.p-tree.p-tree-horizontal table{height:0}"]
                },] }
    ];
    Tree.ctorParameters = function () { return [
        { type: core.ElementRef },
        { type: api.TreeDragDropService, decorators: [{ type: core.Optional }] }
    ]; };
    Tree.propDecorators = {
        value: [{ type: core.Input }],
        selectionMode: [{ type: core.Input }],
        selection: [{ type: core.Input }],
        selectionChange: [{ type: core.Output }],
        onNodeSelect: [{ type: core.Output }],
        onNodeUnselect: [{ type: core.Output }],
        onNodeExpand: [{ type: core.Output }],
        onNodeCollapse: [{ type: core.Output }],
        onNodeContextMenuSelect: [{ type: core.Output }],
        onNodeDrop: [{ type: core.Output }],
        style: [{ type: core.Input }],
        styleClass: [{ type: core.Input }],
        contextMenu: [{ type: core.Input }],
        layout: [{ type: core.Input }],
        draggableScope: [{ type: core.Input }],
        droppableScope: [{ type: core.Input }],
        draggableNodes: [{ type: core.Input }],
        droppableNodes: [{ type: core.Input }],
        metaKeySelection: [{ type: core.Input }],
        propagateSelectionUp: [{ type: core.Input }],
        propagateSelectionDown: [{ type: core.Input }],
        loading: [{ type: core.Input }],
        loadingIcon: [{ type: core.Input }],
        emptyMessage: [{ type: core.Input }],
        ariaLabel: [{ type: core.Input }],
        ariaLabelledBy: [{ type: core.Input }],
        validateDrop: [{ type: core.Input }],
        filter: [{ type: core.Input }],
        filterBy: [{ type: core.Input }],
        filterMode: [{ type: core.Input }],
        filterPlaceholder: [{ type: core.Input }],
        filterLocale: [{ type: core.Input }],
        scrollHeight: [{ type: core.Input }],
        virtualScroll: [{ type: core.Input }],
        virtualNodeHeight: [{ type: core.Input }],
        minBufferPx: [{ type: core.Input }],
        maxBufferPx: [{ type: core.Input }],
        indentation: [{ type: core.Input }],
        trackBy: [{ type: core.Input }],
        onFilter: [{ type: core.Output }],
        templates: [{ type: core.ContentChildren, args: [api.PrimeTemplate,] }],
        virtualScrollBody: [{ type: core.ViewChild, args: [scrolling.CdkVirtualScrollViewport,] }]
    };
    var TreeModule = /** @class */ (function () {
        function TreeModule() {
        }
        return TreeModule;
    }());
    TreeModule.decorators = [
        { type: core.NgModule, args: [{
                    imports: [common.CommonModule, scrolling.ScrollingModule, ripple.RippleModule],
                    exports: [Tree, api.SharedModule, scrolling.ScrollingModule],
                    declarations: [Tree, UITreeNode]
                },] }
    ];

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

    exports.Tree = Tree;
    exports.TreeModule = TreeModule;
    exports.UITreeNode = UITreeNode;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=primeng-tree.umd.js.map
