import { __extends, __decorate, __metadata } from 'tslib';
import { Component, ViewEncapsulation, NgModule, Injector, ElementRef, Optional, Inject, forwardRef, ViewChild, EventEmitter, ViewChildren, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
import { TreeModule } from 'ng2-tree';
import { OntimizeWebModule, InputConverter, Util, OSharedModule, ServiceUtils, OServiceBaseComponent, Codes, OFormComponent, FilterExpressionUtils, OSearchInputModule, OntimizeService, dataServiceFactory, OTranslateService, OSearchInputComponent } from 'ontimize-web-ngx';

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes} checked by tsc
 */
var /** @type {?} */ DEFAULT_BASIC_INPUTS_O_TREE = OServiceBaseComponent.DEFAULT_INPUTS_O_SERVICE_BASE_COMPONENT.concat([
    'sortColumns: sort-columns',
    'descriptionColumns: description-columns',
    'separator',
    'parentColumn: parent-column',
    'showRoot: show-root',
    'rootTitle: root-title',
    'recursive',
    'recursiveLevels: recursive-levels',
    'translate',
    'route'
]);
var /** @type {?} */ DEFAULT_INPUTS_O_TREE = DEFAULT_BASIC_INPUTS_O_TREE.concat([
    'oTitle: title',
    'controls',
    'refreshButton: refresh-button',
    'quickFilter: quick-filter',
    'quickFilterColumns: quick-filter-columns',
    'filterCaseSensitive: filter-case-sensitive'
]);
var /** @type {?} */ DEFAULT_OUTPUTS_O_TREE = [
    'onNodeSelected',
    'onNodeExpanded',
    'onNodeCollapsed',
    'onLoadNextLevel'
];
var ɵ0 = dataServiceFactory;
var OTreeComponent = (function (_super) {
    __extends(OTreeComponent, _super);
    function OTreeComponent(injector, elRef, form) {
        var _this = _super.call(this, injector) || this;
        _this.elRef = elRef;
        _this.form = form;
        _this.separator = Codes.HYPHEN_SEPARATOR;
        _this.showRoot = true;
        _this.recursive = false;
        _this.recursiveLevels = 1;
        _this.translate = false;
        _this.controls = true;
        // @InputConverter()
        _this.static = true;
        // @InputConverter()
        _this.rightMenu = false;
        _this.refreshButton = true;
        _this.quickFilter = false;
        _this.filterCaseSensitive = false;
        /* end of variables */
        /* parsed input variables */
        _this.sortColArray = [];
        _this.descriptionColArray = [];
        _this.dataResponseArray = [];
        _this.expandedNodesIds = [];
        _this.treeNodes = [];
        _this.onNodeSelected = new EventEmitter();
        // onNodeMoved: EventEmitter<any> = new EventEmitter();
        // onNodeCreated: EventEmitter<any> = new EventEmitter();
        // onNodeRemoved: EventEmitter<any> = new EventEmitter();
        // onNodeRenamed: EventEmitter<any> = new EventEmitter();
        _this.onNodeExpanded = new EventEmitter();
        _this.onNodeCollapsed = new EventEmitter();
        _this.onLoadNextLevel = new EventEmitter();
        _this.filteringTree = false;
        _this.resetingTree = false;
        _this.router = _this.injector.get(Router);
        _this.actRoute = _this.injector.get(ActivatedRoute);
        _this.translateService = _this.injector.get(OTranslateService);
        return _this;
    }
    /**
     * @return {?}
     */
    OTreeComponent.prototype.getComponentKey = /**
     * @return {?}
     */
    function () {
        return 'OTreeComponent_' + this.oattr;
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.getDataToStore = /**
     * @return {?}
     */
    function () {
        var /** @type {?} */ dataToStore = {};
        return dataToStore;
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.initialize();
        this.onLanguageChangeSubscription = this.translateService.onLanguageChanged.subscribe(function () {
            _this.onLanguageChangeCallback();
        });
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.ngAfterViewInit = /**
     * @return {?}
     */
    function () {
        if (this.elRef) {
            this.elRef.nativeElement.removeAttribute('title');
        }
        if (this.queryOnInit) {
            this.queryData();
        }
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        _super.prototype.destroy.call(this);
        if (this.onLanguageChangeSubscription) {
            this.onLanguageChangeSubscription.unsubscribe();
        }
    };
    /**
     * @param {?} changes
     * @return {?}
     */
    OTreeComponent.prototype.ngOnChanges = /**
     * @param {?} changes
     * @return {?}
     */
    function (changes) {
        if (Util.isDefined(this.rootTreeModel) && Util.isDefined(this.treeComponent)) {
            _super.prototype.ngOnChanges.call(this, changes);
        }
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.initialize = /**
     * @return {?}
     */
    function () {
        this.sortColArray = ServiceUtils.parseSortColumns(this.sortColumns);
        this.descriptionColArray = Util.parseArray(this.descriptionColumns, true);
        _super.prototype.initialize.call(this);
        if (this.quickFilterColumns) {
            this.quickFilterColArray = Util.parseArray(this.quickFilterColumns, true);
        }
        else {
            this.quickFilterColArray = this.colArray;
        }
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.onLanguageChangeCallback = /**
     * @return {?}
     */
    function () {
        this.translating = true;
        this.treeComponent.getController().rename(this.translateService.get(this.rootTitle));
        this.translateChildren(this.rootTreeModel);
        this.translating = false;
    };
    /**
     * @param {?} treeModel
     * @return {?}
     */
    OTreeComponent.prototype.translateChildren = /**
     * @param {?} treeModel
     * @return {?}
     */
    function (treeModel) {
        var /** @type {?} */ self = this;
        treeModel.children.forEach(function (child) {
            var /** @type {?} */ controller = self.treeComponent.getControllerByNodeId(child.id);
            if (controller) {
                var /** @type {?} */ innerTreeModel = controller.toTreeModel();
                if (innerTreeModel) {
                    var /** @type {?} */ comp = innerTreeModel["treeNodeComponent"];
                    if (comp) {
                        if (innerTreeModel.loadChildren && (comp.showRoot || comp.forcedShowRoot)) {
                            controller.rename(self.translateService.get(comp.rootTitle));
                        }
                        else if (!innerTreeModel.loadChildren && comp.translate) {
                            controller.rename(comp.getNodeDescription(innerTreeModel["data"]));
                        }
                    }
                    if (controller.isExpanded()) {
                        if (innerTreeModel.children && innerTreeModel.children.length) {
                            self.translateChildren(innerTreeModel);
                        }
                    }
                }
            }
        });
    };
    /**
     * @param {?} data
     * @return {?}
     */
    OTreeComponent.prototype.setDataArray = /**
     * @param {?} data
     * @return {?}
     */
    function (data) {
        _super.prototype.setDataArray.call(this, data);
        this.setData(this.dataArray);
    };
    /**
     * @param {?} oTreeNode
     * @return {?}
     */
    OTreeComponent.prototype.registerTreeNode = /**
     * @param {?} oTreeNode
     * @return {?}
     */
    function (oTreeNode) {
        this.treeNodes.push(oTreeNode);
    };
    /**
     * @param {?=} existingFilter
     * @return {?}
     */
    OTreeComponent.prototype.getComponentFilter = /**
     * @param {?=} existingFilter
     * @return {?}
     */
    function (existingFilter) {
        if (existingFilter === void 0) { existingFilter = {}; }
        var /** @type {?} */ filter = existingFilter;
        if (this.recursive && this.parentColumn !== undefined) {
            var /** @type {?} */ parentItemExpr = FilterExpressionUtils.buildExpressionFromObject(filter);
            var /** @type {?} */ parentNotNullExpr = FilterExpressionUtils.buildExpressionIsNull(this.parentColumn);
            var /** @type {?} */ filterExpr = FilterExpressionUtils.buildComplexExpression(parentItemExpr, parentNotNullExpr, FilterExpressionUtils.OP_AND);
            filter = {};
            filter[FilterExpressionUtils.FILTER_EXPRESSION_KEY] = filterExpr;
        }
        return filter;
    };
    /**
     * @param {?} id
     * @param {?} callback
     * @return {?}
     */
    OTreeComponent.prototype.getRecursiveChildren = /**
     * @param {?} id
     * @param {?} callback
     * @return {?}
     */
    function (id, callback) {
        // let queryMethodName = this.pageable ? this.paginatedQueryMethod : this.queryMethod;
        var /** @type {?} */ queryMethodName = this.queryMethod;
        if (!this.dataService || !(queryMethodName in this.dataService) || !this.entity) {
            return;
        }
        var /** @type {?} */ parentItem = ServiceUtils.getParentKeysFromForm(this._pKeysEquiv, this.form);
        var /** @type {?} */ filter = (parentItem !== undefined) ? parentItem : {};
        filter[this.parentColumn] = id;
        var /** @type {?} */ queryArguments = [filter, this.colArray, this.entity];
        this.doChildQuery(queryMethodName, queryArguments, callback);
    };
    /**
     * @param {?} itemdata
     * @param {?} callback
     * @return {?}
     */
    OTreeComponent.prototype.getTreeNodesChildren = /**
     * @param {?} itemdata
     * @param {?} callback
     * @return {?}
     */
    function (itemdata, callback) {
        var _this = this;
        var /** @type {?} */ children = [];
        this.treeNodes.forEach(function (childNode) {
            var /** @type {?} */ treeNode = {
                data: itemdata,
                route: _this.route,
                value: _this.translateService.get(childNode.rootTitle),
                id: childNode.oattr,
                treeNodeComponent: childNode,
                emitLoadNextLevel: false,
                loadChildren: function (childNodeCallback) {
                    var /** @type {?} */ queryMethodName = childNode.queryMethod;
                    if (!childNode.dataService || !(queryMethodName in childNode.dataService) || !childNode.entity) {
                        return;
                    }
                    var /** @type {?} */ filter = ServiceUtils.getFilterUsingParentKeys(itemdata, childNode._pKeysEquiv);
                    var /** @type {?} */ queryArguments = [filter, childNode.colArray, childNode.entity];
                    childNode.doChildQuery(queryMethodName, queryArguments, childNodeCallback);
                }
            };
            children.push(treeNode);
        });
        if (this.treeNodes.length === 1 && !this.treeNodes[0].showRoot) {
            children[0].loadChildren(callback);
        }
        else {
            this.treeNodes.forEach(function (childNode) {
                childNode.forcedShowRoot = true;
            });
            callback(children);
        }
    };
    /**
     * @param {?} queryMethodName
     * @param {?} queryArguments
     * @param {?} callback
     * @return {?}
     */
    OTreeComponent.prototype.doChildQuery = /**
     * @param {?} queryMethodName
     * @param {?} queryArguments
     * @param {?} callback
     * @return {?}
     */
    function (queryMethodName, queryArguments, callback) {
        var _this = this;
        var /** @type {?} */ self = this;
        this.dataService[queryMethodName].apply(this.dataService, queryArguments).subscribe(function (resp) {
            var /** @type {?} */ children = [];
            if (resp && resp.data && resp.data.length > 0) {
                for (var /** @type {?} */ i = 0, /** @type {?} */ len = resp.data.length; i < len; i++) {
                    var /** @type {?} */ child = _this.mapTreeNode(resp.data[i], self);
                    children.push(child);
                }
            }
            callback(children);
        });
    };
    /**
     * @param {?=} itemdata
     * @param {?=} treeNodeComponent
     * @return {?}
     */
    OTreeComponent.prototype.mapTreeNode = /**
     * @param {?=} itemdata
     * @param {?=} treeNodeComponent
     * @return {?}
     */
    function (itemdata, treeNodeComponent) {
        var _this = this;
        if (itemdata === void 0) { itemdata = {}; }
        var /** @type {?} */ treeNode = {
            data: itemdata,
            value: this.getNodeDescription(itemdata),
            id: this.getNodeId(itemdata),
            route: this.route,
            treeNodeComponent: treeNodeComponent
        };
        if (this.recursive) {
            treeNode['loadChildren'] = function (callback) { return _this.getRecursiveChildren(itemdata[_this.keysArray[0]], callback); };
        }
        else if (this.treeNodes.length > 0) {
            treeNode['loadChildren'] = function (callback) { return _this.getTreeNodesChildren(itemdata, callback); };
        }
        return treeNode;
    };
    /**
     * @param {?=} item
     * @return {?}
     */
    OTreeComponent.prototype.getNodeId = /**
     * @param {?=} item
     * @return {?}
     */
    function (item) {
        if (item === void 0) { item = {}; }
        var /** @type {?} */ id = '';
        this.keysArray.forEach(function (key) {
            id += item[key];
        });
        return this.keys + ':' + id;
    };
    /**
     * @param {?=} item
     * @return {?}
     */
    OTreeComponent.prototype.getNodeDescription = /**
     * @param {?=} item
     * @return {?}
     */
    function (item) {
        if (item === void 0) { item = {}; }
        var /** @type {?} */ descTxt = '';
        var /** @type {?} */ self = this;
        this.descriptionColArray.forEach(function (col, index) {
            var /** @type {?} */ txt = item[col];
            if (txt) {
                if (self.translate && self.translateService) {
                    txt = self.translateService.get(txt);
                }
                descTxt += txt;
            }
            if (index < self.descriptionColArray.length - 1) {
                descTxt += self.separator;
            }
        });
        return descTxt;
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.reloadData = /**
     * @return {?}
     */
    function () {
        // if (this.unstructuredData) {
        //   this.static = true;
        //   this.rightMenu = false;
        //   this.setTreefromDirtyArray(this.unstructuredData);
        // } else if (this.data) {
        //   this.setTree(this.data);
        // } else {
        this.queryData();
        if (this.searchInput.length === 1) {
            var /** @type {?} */ filter = this.searchInput.first.getValue();
            if (filter && filter.length > 1) {
                this.onSearch(filter);
            }
        }
        // }
    };
    /**
     * @param {?} treeArray
     * @return {?}
     */
    OTreeComponent.prototype.setData = /**
     * @param {?} treeArray
     * @return {?}
     */
    function (treeArray) {
        var _this = this;
        //, sqlTypes?: any) {
        this.dataResponseArray = treeArray;
        var /** @type {?} */ childrenArray = [];
        treeArray.forEach(function (el) {
            childrenArray.push(_this.mapTreeNode(el));
        });
        this.rootTreeModel = {
            value: this.translateService.get(this.rootTitle),
            id: 0,
            children: childrenArray,
            settings: {
                rightMenu: this.rightMenu,
                static: this.static,
                cssClasses: {
                    expanded: 'material-icons expanded-node',
                    collapsed: 'material-icons collapsed-node'
                }
            }
        };
        this.settings = {
            rootIsVisible: this.showRoot
        };
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.resetTree = /**
     * @return {?}
     */
    function () {
        this.resetingTree = true;
        this.setData(this.dataResponseArray);
        var /** @type {?} */ self = this;
        setTimeout(function () {
            self.expandedNodesIds.forEach(function (id, index) {
                setTimeout(function () {
                    var /** @type {?} */ controller = self.treeComponent.getControllerByNodeId(id);
                    if (controller) {
                        controller.expand();
                    }
                }, index * 75);
            });
        }, 0);
    };
    /**
     * @param {?} textValue
     * @return {?}
     */
    OTreeComponent.prototype.onSearch = /**
     * @param {?} textValue
     * @return {?}
     */
    function (textValue) {
        if (this.pageable) {
            return;
        }
        this.resetTree();
        var /** @type {?} */ self = this;
        setTimeout(function () {
            if (textValue && textValue.length > 0) {
                setTimeout(function () {
                    self.filterTreeUsingFilter(textValue);
                    self.resetingTree = false;
                }, (self.expandedNodesIds.length + 1) * 75);
            }
            else {
                self.resetingTree = false;
            }
        }, 75);
    };
    /**
     * @param {?} event
     * @return {?}
     */
    OTreeComponent.prototype.nodeSelected = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        if (event && event.node && Util.isDefined(event.node.id)) {
            var /** @type {?} */ node = event.node;
            var /** @type {?} */ controller = this.treeComponent.getControllerByNodeId(node.id);
            if (controller) {
                var /** @type {?} */ innerTreeModel = controller.toTreeModel();
                if (innerTreeModel && innerTreeModel["treeNodeComponent"]) {
                    var /** @type {?} */ nodeModel_1 = innerTreeModel["data"];
                    innerTreeModel["treeNodeComponent"].innerNodeSelected(nodeModel_1, node);
                    return;
                }
            }
            var /** @type {?} */ nodeModel = node.node ? (/** @type {?} */ (node.node)).data : node;
            this.innerNodeSelected(nodeModel, node);
        }
    };
    /**
     * @param {?} data
     * @param {?} node
     * @return {?}
     */
    OTreeComponent.prototype.innerNodeSelected = /**
     * @param {?} data
     * @param {?} node
     * @return {?}
     */
    function (data, node) {
        this.onNodeSelected.emit(data);
        this.selectedNode = node;
        if (Util.isDefined((/** @type {?} */ (node.node)).route) || (node.id === 0)) {
            var /** @type {?} */ route = undefined;
            if (node.id === 0) {
                // route = OTreeComponent.DEFAULT_ROOT_ROUTE;
            }
            else {
                var /** @type {?} */ nodeRoute = (/** @type {?} */ (node.node)).route;
                var /** @type {?} */ routeArray = nodeRoute.split(Codes.ROUTE_SEPARATOR);
                for (var /** @type {?} */ i = 0, /** @type {?} */ len = routeArray.length; i < len; i++) {
                    if (routeArray[i].startsWith(Codes.ROUTE_VARIABLE_CHAR)) {
                        routeArray[i] = data[routeArray[i].substring(1)];
                    }
                }
                route = routeArray.join(Codes.ROUTE_SEPARATOR);
            }
            if (Util.isDefined(route)) {
                var /** @type {?} */ extras = {
                    relativeTo: this.actRoute
                };
                this.router.navigate([route], extras);
            }
        }
    };
    /**
     * @param {?} event
     * @return {?}
     */
    OTreeComponent.prototype.nodeMoved = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        if (event && event.node && event.node.id) {
            // if (e.node.parent.id !== e.previousParent.id)
            // const node: Tree = event.node;
            // this.onNodeMoved(node);
        }
        // let nodeToUpdate = {}, data = {};
        // nodeToUpdate[this.valueColumn] = e.node.id;
        // data[this.parentColumn] = e.node.parent.id;
        // if (this.service && this.entity) {
        //   this.dataService.update(nodeToUpdate, data, this.entity).subscribe(resp => {
        //     if (resp && resp.code === Codes.ONTIMIZE_SUCCESSFUL_CODE) {
        //       this.dialogService.info('INFO', e.node.value + ' ha sido trasladado de ' + e.previousParent.value + ' a ' + e.node.parent.value);
        //     } else {
        //       this.dialogService.error('ERROR', 'Ha ocurrido un error a trasladar ' + e.node.value)
        //     }
        //   });
        // }
    };
    /**
     * @param {?} event
     * @return {?}
     */
    OTreeComponent.prototype.nodeCreated = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        console.log(event);
        // if (node && node.node && node.node.value.length > 0 && this.dataService) {
        //   let nodeObject: Tree = node.node;
        //   let nodeToInsert = {};
        // nodeToInsert[this.nodeDescription] = nodeObject.value;
        // if (nodeObject.parent && nodeObject.parent.id) {
        //   nodeToInsert[this.parentColumn] = nodeObject.parent.id;
        // }
        // if (this.codeColumn) {
        //   nodeToInsert[this.codeColumn] = node.node.value.toUpperCase().replace(/[&\/\\#,+()$~%.'":*?<>{} ]/g, '-');
        // }
        // if (this.parentItem) {
        //   nodeToInsert = Object.assign({}, nodeToInsert, this.parentItem);
        // }
        // this.subscriber = this.dataService.insert(nodeToInsert, this.entity).subscribe(resp => {
        //   if (resp && resp.data && resp.data[this.valueColumn]) {
        //     console.log('Element inserted successfully!', resp)
        //     node.node.id = resp.data[this.valueColumn];
        //   }
        // }, err => {
        //   this.dialogService.info('ERROR', 'Ha ocurrido un error a insertar el elemento!');
        //   nodeObject.removeItselfFromParent();
        // });
        // }
    };
    /**
     * @param {?} event
     * @return {?}
     */
    OTreeComponent.prototype.nodeRemoved = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        if (!this.filteringTree) {
            console.log(event);
        }
        // if (node && node.node && node.node.id && this.dataService) {
        // // this.dialogService.confirm('CONFIRM', 'MESSAGES.CONFIRM_DELETE_TREE_NODE').then(
        // //     res => {
        // //         if (res === true) {
        // let nodeObject: Tree = node.node;
        // let nodeToDelete = {};
        // nodeToDelete[this.valueColumn] = nodeObject.id;
        // this.subscriber = this.dataService.delete(nodeToDelete, this.entity).subscribe(resp => {
        //   if (resp) {
        //     console.log('Element deleted successfully!', resp.data)
        //   }
        // }, err => {
        //   this.dialogService.info('ERROR', 'Ha ocurrido un error a remover el elemento!');
        // });
        // //     }
        // // });
        // }
    };
    /**
     * @param {?} event
     * @return {?}
     */
    OTreeComponent.prototype.nodeRenamed = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        if (!this.translating) {
            console.log(event);
        }
        // if (node && node.node && node.node.id && node.node.value.length > 0 && this.dataService) {
        //   // let nodeObject: Tree = node.node;
        //   // let nodeToRename = {};
        //   // nodeToRename[this.valueColumn] = nodeObject.id;
        //   // let data = {};
        //   // data[this.nodeDescription] = nodeObject.value;
        //   // this.subscriber = this.dataService.update(nodeToRename, data, this.entity).subscribe(resp => {
        //   //     if (resp) {
        //   //         console.log('Element renamed successfully!', resp)
        //   //     }
        //   // }, err => {
        //   //     this.dialogService.info('ERROR', 'Ha ocurrido un error a renombrar el elemento!');
        //   // });
        // }
    };
    /**
     * @param {?} event
     * @return {?}
     */
    OTreeComponent.prototype.nodeExpanded = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        if (!this.resetingTree && event && event.node && event.node.id) {
            var /** @type {?} */ node = event.node;
            if (this.expandedNodesIds.indexOf(node.id) === -1) {
                this.expandedNodesIds.push(node.id);
            }
            this.onNodeExpanded.emit(node);
        }
    };
    /**
     * @param {?} event
     * @return {?}
     */
    OTreeComponent.prototype.nodeCollapsed = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        if (event && event.node && event.node.id) {
            var /** @type {?} */ node = event.node;
            this.expandedNodesIds.splice(this.expandedNodesIds.indexOf(node.id), 1);
            this.onNodeCollapsed.emit(node);
        }
    };
    /**
     * @param {?} event
     * @return {?}
     */
    OTreeComponent.prototype.nextLevelLoaded = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        if (event && event.node && event.node.id) {
            var /** @type {?} */ node = event.node;
            this.onLoadNextLevel.emit(node);
        }
    };
    /**
     * @param {?} id
     * @param {?} action
     * @return {?}
     */
    OTreeComponent.prototype.executeNodeActionById = /**
     * @param {?} id
     * @param {?} action
     * @return {?}
     */
    function (id, action) {
        var /** @type {?} */ treeController = this.treeComponent.getControllerByNodeId(id);
        if (treeController && typeof treeController[action] === 'function') {
            treeController[action]();
        }
        else {
            console.log('There isn`t a controller for a node with id - ' + id);
        }
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.hasTitle = /**
     * @return {?}
     */
    function () {
        return this.oTitle !== undefined;
    };
    /**
     * @return {?}
     */
    OTreeComponent.prototype.useQuickFilter = /**
     * @return {?}
     */
    function () {
        return this.quickFilter; // && !this.recursive && this.treeNodes.length === 0;
    };
    /**
     * @param {?} filter
     * @return {?}
     */
    OTreeComponent.prototype.filterTreeUsingFilter = /**
     * @param {?} filter
     * @return {?}
     */
    function (filter) {
        var _this = this;
        this.filteringTree = true;
        if (!this.filterCaseSensitive) {
            filter = filter.toLowerCase();
        }
        this.rootTreeModel.children.forEach(function (item) {
            _this.filterNodesUsingFilter(item, filter);
        });
        this.filteringTree = false;
    };
    /**
     * @param {?} item
     * @param {?} filter
     * @return {?}
     */
    OTreeComponent.prototype.filterNodesUsingFilter = /**
     * @param {?} item
     * @param {?} filter
     * @return {?}
     */
    function (item, filter) {
        var /** @type {?} */ controller = this.treeComponent.getControllerByNodeId(item.id);
        if (controller && controller.isExpanded()) {
            this.filterBranch(item, filter);
        }
        else if (controller) {
            this.filterLeaf(item, filter);
        }
    };
    /**
     * @param {?} item
     * @param {?} filter
     * @return {?}
     */
    OTreeComponent.prototype.filterBranch = /**
     * @param {?} item
     * @param {?} filter
     * @return {?}
     */
    function (item, filter) {
        var _this = this;
        var /** @type {?} */ controller = this.treeComponent.getControllerByNodeId(item.id);
        var /** @type {?} */ children = controller.toTreeModel().children;
        children.forEach(function (child) {
            _this.filterNodesUsingFilter(child, filter);
        });
        var /** @type {?} */ notNullChildren = children.filter(function (child) {
            return Util.isDefined(_this.treeComponent.getControllerByNodeId(child.id));
        });
        if (notNullChildren.length === 0) {
            this.filterLeaf(item, filter);
        }
    };
    /**
     * @param {?} item
     * @param {?} filter
     * @return {?}
     */
    OTreeComponent.prototype.filterLeaf = /**
     * @param {?} item
     * @param {?} filter
     * @return {?}
     */
    function (item, filter) {
        var /** @type {?} */ searchStr = this.getStringForSearch(item);
        if (!this.filterCaseSensitive) {
            searchStr = searchStr.toLowerCase();
        }
        var /** @type {?} */ remove = searchStr.indexOf(filter) === -1;
        if (remove) {
            var /** @type {?} */ treeController = this.treeComponent.getControllerByNodeId(item.id);
            if (treeController) {
                treeController.remove();
            }
        }
    };
    /**
     * @param {?} item
     * @return {?}
     */
    OTreeComponent.prototype.getStringForSearch = /**
     * @param {?} item
     * @return {?}
     */
    function (item) {
        var /** @type {?} */ resultArr = [];
        var /** @type {?} */ columns = item["treeNodeComponent"] ? item["treeNodeComponent"].quickFilterColArray : this.quickFilterColArray;
        resultArr = columns.map(function (col) {
            return item["data"][col];
        });
        if (Util.isDefined(item.loadChildren)) {
            resultArr.push(item.value);
        }
        return resultArr.join(' ');
    };
    OTreeComponent.DEFAULT_INPUTS_O_TREE = DEFAULT_INPUTS_O_TREE;
    OTreeComponent.DEFAULT_BASIC_INPUTS_O_TREE = DEFAULT_BASIC_INPUTS_O_TREE;
    OTreeComponent.DEFAULT_OUTPUTS_O_TREE = DEFAULT_OUTPUTS_O_TREE;
    OTreeComponent.DEFAULT_ROOT_ROUTE = 'home';
    OTreeComponent.decorators = [
        { type: Component, args: [{
                    selector: 'o-tree',
                    template: "\n    <div fxLayout=\"column\" class=\"tree-container\" fxFlex [class.has-controls]=\"controls\">\n      <mat-toolbar *ngIf=\"controls\" class=\"toolbar\" fxLayoutAlign=\"space-between center\">\n        <div class=\"mat-toolbar-tools\" fxLayout=\"row\" fxFill fxLayoutAlign=\"start center\">\n          <button type=\"button\" mat-icon-button aria-label=\"Refresh\" (click)=\"reloadData()\" *ngIf=\"refreshButton\">\n            <mat-icon>autorenew</mat-icon>\n          </button>\n          <span class=\"fill-remaining\"></span>\n          <div *ngIf=\"hasTitle()\" fxLayout=\"row\" fxLayoutAlign=\"center center\">\n            <span>{{ oTitle | oTranslate }}</span>\n          </div>\n          <span *ngIf=\"hasTitle()\" class=\"fill-remaining\"></span>\n          <!-- <button *ngIf=\"insertButton\" md-icon-button aria-label=\"Add\" md-tooltip=\"{{'ADDNEWNODE' | oTranslate}}\" (click)=\"add()\">\n              <md-icon>add</md-icon>\n          </button> -->\n          <!-- <button *ngIf=\"editButton\" md-icon-button aria-label=\"Edit\" md-tooltip=\"{{'EDITTREE' | oTranslate}}\" (click)=\"edit()\">\n                  <md-icon>wrap_text</md-icon>\n              </button> -->\n          <!-- <button md-icon-button aria-label=\"ExpandAll/CollapseAll\" (click)=\"expandCollapseTree()\">\n              <md-icon>expand_{{isExpanded ? 'less' : 'more'}}</md-icon>\n          </button> -->\n          <o-search-input #searchInput *ngIf=\"useQuickFilter()\" placeholder=\"\" (onSearch)=\"onSearch($event)\"></o-search-input>\n        </div>\n      </mat-toolbar>\n      <div class=\"tree-content o-scroll\" [class.recursive-tree]=\"recursive\" [class.filtering-tree]=\"resetingTree\">\n        <tree #treeComponent *ngIf=\"!loading\" [tree]=\"rootTreeModel\" [settings]=\"settings\"\n          (nodeSelected)=\"nodeSelected($event)\" (nodeMoved)=\"nodeMoved($event)\"\n          (nodeCreated)=\"nodeCreated($event)\" (nodeRemoved)=\"nodeRemoved($event)\"\n          (nodeRenamed)=\"nodeRenamed($event)\" (nodeExpanded)=\"nodeExpanded($event)\"\n          (nodeCollapsed)=\"nodeCollapsed($event)\">\n        </tree>\n        <div class=\"spinner-container\" fxFlex=\"100\" *ngIf=\"loading\" fxLayoutAlign=\"center center\">\n          <mat-progress-spinner mode=\"indeterminate\" strokeWidth=\"3\">\n          </mat-progress-spinner>\n        </div>\n      </div>\n    </div>\n  ",
                    styles: ["\n    .o-tree .tree-container.has-controls .tree-content{height:calc(100% - 64px)}.o-tree .tree-container .tree-content{overflow:auto}.o-tree .tree-container .folding:not(.node-leaf)+.node-value,.o-tree .tree-container .recursive-tree .node-value{cursor:pointer}.o-tree .tree-container .filtering-tree{visibility:hidden}.o-tree .tree-container tree-internal ul{padding:0 0 4px 12px}.o-tree .tree-container tree-internal li{padding:0;margin:0;list-style:none;cursor:default}.o-tree .tree-container tree-internal li div{display:inline-block;box-sizing:border-box}.o-tree .tree-container tree-internal ul.rootless{padding:0}.o-tree .tree-container tree-internal div.rootless{display:none !important}.o-tree .tree-container tree-internal .tree{box-sizing:border-box}.o-tree .tree-container tree-internal .tree .node-value{display:inline-block}.o-tree .tree-container tree-internal .tree .node-value:after{display:none;height:0}.o-tree .tree-container tree-internal .tree .node-name{vertical-align:middle}.o-tree .tree-container tree-internal .tree .value-container+tree-internal>.tree{padding-top:6px}.o-tree .tree-container tree-internal .tree .folding{width:20px;display:inline-block;line-height:1px;padding:0 5px;font-weight:bold}.o-tree .tree-container tree-internal .tree .folding.node-leaf{width:0;padding:0 8px}.o-tree .tree-container .material-icons.collapsed-node:before,.o-tree .tree-container .material-icons.expanded-node:before{vertical-align:sub;font-size:18px;cursor:pointer}.o-tree .tree-container .material-icons.expanded-node:before{content:'\\E313'}.o-tree .tree-container .material-icons.collapsed-node:before{content:'\\E315'}\n  "],
                    inputs: DEFAULT_INPUTS_O_TREE,
                    outputs: DEFAULT_OUTPUTS_O_TREE,
                    encapsulation: ViewEncapsulation.None,
                    providers: [
                        { provide: OntimizeService, useFactory: ɵ0, deps: [Injector] }
                    ],
                    host: {
                        '[class.o-tree]': 'true'
                    }
                },] },
    ];
    /** @nocollapse */
    OTreeComponent.ctorParameters = function () { return [
        { type: Injector, },
        { type: ElementRef, },
        { type: OFormComponent, decorators: [{ type: Optional }, { type: Inject, args: [forwardRef(function () { return OFormComponent; }),] },] },
    ]; };
    OTreeComponent.propDecorators = {
        "treeComponent": [{ type: ViewChild, args: ['treeComponent',] },],
        "searchInput": [{ type: ViewChildren, args: [OSearchInputComponent,] },],
    };
    __decorate([
        InputConverter(),
        __metadata("design:type", Boolean)
    ], OTreeComponent.prototype, "showRoot", void 0);
    __decorate([
        InputConverter(),
        __metadata("design:type", Boolean)
    ], OTreeComponent.prototype, "recursive", void 0);
    __decorate([
        InputConverter(),
        __metadata("design:type", Number)
    ], OTreeComponent.prototype, "recursiveLevels", void 0);
    __decorate([
        InputConverter(),
        __metadata("design:type", Boolean)
    ], OTreeComponent.prototype, "translate", void 0);
    __decorate([
        InputConverter(),
        __metadata("design:type", Boolean)
    ], OTreeComponent.prototype, "controls", void 0);
    __decorate([
        InputConverter(),
        __metadata("design:type", Boolean)
    ], OTreeComponent.prototype, "refreshButton", void 0);
    __decorate([
        InputConverter(),
        __metadata("design:type", Boolean)
    ], OTreeComponent.prototype, "quickFilter", void 0);
    __decorate([
        InputConverter(),
        __metadata("design:type", Boolean)
    ], OTreeComponent.prototype, "filterCaseSensitive", void 0);
    return OTreeComponent;
}(OServiceBaseComponent));
var OTreeComponentModule = (function () {
    function OTreeComponentModule() {
    }
    OTreeComponentModule.decorators = [
        { type: NgModule, args: [{
                    declarations: [OTreeComponent],
                    imports: [
                        OntimizeWebModule,
                        OSharedModule,
                        OSearchInputModule,
                        CommonModule,
                        TreeModule,
                        RouterModule
                    ],
                    exports: [OTreeComponent]
                },] },
    ];
    return OTreeComponentModule;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes} checked by tsc
 */
var ɵ0$1 = dataServiceFactory;
var OTreeNodeComponent = (function (_super) {
    __extends(OTreeNodeComponent, _super);
    function OTreeNodeComponent(injector, elRef, form, oTree, parentNode) {
        var _this = _super.call(this, injector, elRef, form) || this;
        _this.oTree = oTree;
        _this.parentNode = parentNode;
        _this.onNodeSelected = new EventEmitter();
        // onNodeMoved: EventEmitter<any> = new EventEmitter();
        // onNodeCreated: EventEmitter<any> = new EventEmitter();
        // onNodeRemoved: EventEmitter<any> = new EventEmitter();
        // onNodeRenamed: EventEmitter<any> = new EventEmitter();
        _this.onNodeExpanded = new EventEmitter();
        _this.onNodeCollapsed = new EventEmitter();
        _this.onLoadNextLevel = new EventEmitter();
        _this.forcedShowRoot = false;
        return _this;
    }
    /**
     * @return {?}
     */
    OTreeNodeComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        _super.prototype.initialize.call(this);
        this.queryOnBind = true;
        this.queryOnInit = false;
        if (Util.isDefined(this.parentNode)) {
            this.parentNode.registerChildNode(this);
        }
        else if (Util.isDefined(this.oTree)) {
            this.oTree.registerTreeNode(this);
        }
    };
    /**
     * @param {?} child
     * @return {?}
     */
    OTreeNodeComponent.prototype.registerChildNode = /**
     * @param {?} child
     * @return {?}
     */
    function (child) {
        this.treeNodes.push(child);
    };
    /**
     * @return {?}
     */
    OTreeNodeComponent.prototype.onLanguageChangeCallback = /**
     * @return {?}
     */
    function () {
        // empty
    };
    OTreeNodeComponent.DEFAULT_INPUTS_O_TREE_NODE = OTreeComponent.DEFAULT_BASIC_INPUTS_O_TREE;
    OTreeNodeComponent.DEFAULT_OUTPUTS_O_TREE_NODE = OTreeComponent.DEFAULT_OUTPUTS_O_TREE;
    OTreeNodeComponent.decorators = [
        { type: Component, args: [{
                    selector: 'o-tree-node',
                    template: ' ',
                    inputs: OTreeComponent.DEFAULT_BASIC_INPUTS_O_TREE,
                    outputs: OTreeComponent.DEFAULT_OUTPUTS_O_TREE,
                    providers: [
                        { provide: OntimizeService, useFactory: ɵ0$1, deps: [Injector] }
                    ],
                },] },
    ];
    /** @nocollapse */
    OTreeNodeComponent.ctorParameters = function () { return [
        { type: Injector, },
        { type: ElementRef, },
        { type: OFormComponent, decorators: [{ type: Optional }, { type: Inject, args: [forwardRef(function () { return OFormComponent; }),] },] },
        { type: OTreeComponent, decorators: [{ type: Optional }, { type: Inject, args: [forwardRef(function () { return OTreeComponent; }),] },] },
        { type: OTreeNodeComponent, decorators: [{ type: SkipSelf }, { type: Optional },] },
    ]; };
    return OTreeNodeComponent;
}(OTreeComponent));
var OTreeNodeComponentModule = (function () {
    function OTreeNodeComponentModule() {
    }
    OTreeNodeComponentModule.decorators = [
        { type: NgModule, args: [{
                    declarations: [OTreeNodeComponent],
                    imports: [OntimizeWebModule, OSharedModule, CommonModule],
                    exports: [OTreeNodeComponent]
                },] },
    ];
    return OTreeNodeComponentModule;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes} checked by tsc
 */
var /** @type {?} */ OTREE_MODULES = [
    OTreeComponentModule,
    OTreeNodeComponentModule
];

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes} checked by tsc
 */
var OTreeModule = (function () {
    function OTreeModule() {
    }
    OTreeModule.decorators = [
        { type: NgModule, args: [{
                    imports: OTREE_MODULES,
                    exports: OTREE_MODULES
                },] },
    ];
    return OTreeModule;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes} checked by tsc
 */
// This file only reexports content of the `src` folder. Keep it that way.

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes} checked by tsc
 */

export { OTreeModule, OTREE_MODULES, DEFAULT_BASIC_INPUTS_O_TREE, DEFAULT_INPUTS_O_TREE, DEFAULT_OUTPUTS_O_TREE, OTreeComponent, OTreeComponentModule, OTreeNodeComponent, OTreeNodeComponentModule };
//# sourceMappingURL=ontimize-web-ngx-tree.es5.js.map
