import { Component, Input, Output } from '@angular/core';
import { Subject } from 'rxjs';
import { HierarchyBase } from '../hierarchy-base';
import * as i0 from "@angular/core";
import * as i1 from "../../../core/scroll.service";
import * as i2 from "@angular/common";
import * as i3 from "@angular/router";
import * as i4 from "../../../controls/navigation/nav-item-active.directive";
import * as i5 from "../../../controls/collapsible-toggle/collapsible-toggle.component";
export class HierarchyTreeComponent extends HierarchyBase {
    constructor(scrollService, injector) {
        super(injector);
        this.scrollService = scrollService;
        /** The value of the id attribute of the tree's root HTMLUListElement, suffixed with '_root' */
        this.id = 'HierarchyTree';
        /** Emits a HierarchyItem whenever one is selected by clicking */
        this.itemSelected = new Subject();
        /** The width of the spacing before a tree node, multipled by a HierarchyItem's level. Value is in pixels */
        this.indent = 16;
        /** The value of the id attribute of the tree's scroll container element, used to scroll a selected item into view.  */
        this.scrollContainerId = '';
    }
    ngOnInit() {
        this.scrollContainerId = `${this.id}_root`;
    }
    /**
     * Scroll to the item currently marked as is-selected. Wait a tick for the
     * NavItemActiveDirective to update the selected class.
     */
    scrollToSelectedItem() {
        window.setTimeout(() => {
            const linkSelector = `.item-wrapper.is-selected`;
            this.scrollService.scrollToItem(`#${this.scrollContainerId}`, linkSelector);
        });
    }
    /**
     * When a HierarchyItem is selected, update the value of the activeUrl property with the value
     * of that item's url property and emit the item to any subscribers.
     */
    selectItem(item) {
        this.itemSelected.next(item);
        if (item.display === 'heading' && !item.hideToggle) {
            this.toggleItemClicked(item, !item.expanded);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: HierarchyTreeComponent, deps: [{ token: i1.ScrollService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: HierarchyTreeComponent, selector: "ec-hierarchy-tree", inputs: { id: "id", hideRootNode: "hideRootNode", customItemTemplate: "customItemTemplate" }, outputs: { itemSelected: "itemSelected" }, usesInheritance: true, ngImport: i0, template: "<ul id=\"{{scrollContainerId}}\"\r\n    class=\"flex-grow scroll-y py-1\">\r\n\r\n  <li *ngIf=\"!hideRootNode && rootNode\">\r\n    <div class=\"item-wrapper\"\r\n         title=\"{{rootNode?.tooltip ?? rootNode?.label}}\"\r\n         [ngClass]=\"{'is-heading': rootNode?.display === 'heading'}\"\r\n         ecNavItemActive=\"is-selected\"\r\n         [ecNavItemActiveUrl]=\"rootNode?.url\"\r\n         [ecNavItemActiveExactMatch]='rootNode?.isActiveExactMatch'>\r\n      <a id=\"rootNode_{{rootNode?.id}}_link\"\r\n         class=\"item flex-grow d-flex align-items-center\"\r\n         routerLink=\"{{rootNode?.url}}\"\r\n         [queryParams]=\"rootNode?.queryParams\">\r\n        <ng-container *ngTemplateOutlet=\"customItemTemplate || defaultItemTemplate; context: { $implicit: rootNode }\"></ng-container>\r\n      </a>\r\n    </div>\r\n  </li>\r\n\r\n  <ng-template #hierarchyView\r\n               let-items>\r\n    <li *ngFor=\"let item of items; index as index; first as isFirst\"\r\n        [ngClass]=\"{'divider': item.display === 'divider'}\"\r\n        id=\"treeItem_{{item.id}}\">\r\n      <div class=\"item-wrapper\"\r\n           title=\"{{item.tooltip ?? item.label}}\"\r\n           [ngClass]=\"{'is-heading': item.display === 'heading'}\"\r\n           ecNavItemActive=\"is-selected\"\r\n           [ecNavItemActiveUrl]=\"item.url\"\r\n           [ecNavItemActiveExactMatch]=\"item.isActiveExactMatch\"\r\n           [ecNavItemActiveQueryParams]=\"item.queryParams\">\r\n\r\n        <!-- This element provides the indentation for each level -->\r\n        <span id=\"indent_{{item.id}}\"\r\n              *ngIf=\"!item.noIndent\"\r\n              class=\"d-block h-100\"\r\n              [style.width.px]=\"(indent) * (item.level - 1) + (item.level * 4) + (item.hasChildren ? 0 : indent)\">\r\n        </span>\r\n\r\n        <!-- Toggle the button icon to be a spinner when item.status is pending -->\r\n        <ec-collapsible-toggle id=\"toggle_{{item.id}}\"\r\n                               class=\"flex-shrink\"\r\n                               [style.width.px]=\"indent\"\r\n                               *ngIf=\"item.hasChildren && !item.hideToggle\"\r\n                               [hidden]=\"item.status === 'pending'\"\r\n                               [expanded]=\"item.expanded\"\r\n                               (expandedChange)=\"toggleItemClicked(item, $event)\">\r\n        </ec-collapsible-toggle>\r\n\r\n        <i class=\"ec-icon icon-loading my-1\"\r\n           [hidden]=\"item.status !== 'pending'\"></i>\r\n\r\n        <a id=\"treeItem_{{item.id}}_link\"\r\n           class=\"item\"\r\n           *ngIf=\"item.url\"\r\n           (click)=\"selectItem(item)\"\r\n           [routerLink]=\"item.url\"\r\n           [queryParams]=\"item.queryParams\"\r\n           [queryParamsHandling]=\"item.queryParamsHandling || ''\">\r\n           <ng-container *ngTemplateOutlet=\"customItemTemplate || defaultItemTemplate; context: { $implicit: item }\"></ng-container>\r\n        </a>\r\n        <div id=\"treeItem_{{item.id}}_heading\"\r\n             class=\"item\"\r\n             *ngIf=\"!item.url\"\r\n             (click)=\"selectItem(item)\">\r\n             <ng-container *ngTemplateOutlet=\"customItemTemplate || defaultItemTemplate; context: { $implicit: item }\"></ng-container>\r\n        </div>\r\n      </div>\r\n\r\n\r\n      <ul *ngIf=\"item.children.length > 0 && item.expanded\">\r\n        <ng-container *ngTemplateOutlet=\"hierarchyView; context:{ $implicit: item.children }\"></ng-container>\r\n      </ul>\r\n    </li>\r\n  </ng-template>\r\n\r\n  <ng-container *ngTemplateOutlet=\"hierarchyView; context:{ $implicit: rootNode?.children }\"></ng-container>\r\n</ul>\r\n\r\n<ng-template #defaultItemTemplate\r\n             let-item>\r\n  <i class=\"ec-icon {{item.icon}} mx-1 flex-shrink\"\r\n     [attr.title]=\"item.iconTooltip\"\r\n     *ngIf=\"item.icon\"></i>\r\n  <span class=\"mx-1 text-truncate\">{{item.label}}</span>\r\n</ng-template>", styles: [":host{display:block;font-size:var(--ec-menu-font-size, var(--ec-font-size-action));background-color:var(--ec-menu-background-color, var(--ec-background-color))}ul{padding:0;margin:0;list-style:none;overflow-x:hidden}ul li{white-space:nowrap;padding:0}ul li.divider{border-bottom:1px solid var(--ec-border-color);padding-bottom:.25rem;margin-bottom:.25rem}ul .item-wrapper{display:flex;align-items:center;padding:0 .25rem;margin:0 .25rem;height:1.75rem;border-radius:var(--ec-border-radius)}ul .item-wrapper.is-heading{cursor:pointer;color:var(--ec-color-hint-dark);text-transform:uppercase;font-weight:var(--ec-font-weight-bold);font-size:var(--ec-font-size-label)}ul .item-wrapper:hover{background-color:var(--ec-background-color-hover)}ul .item-wrapper.is-selected{font-weight:700}ul .item-wrapper a{text-decoration:none}ul .item{color:inherit;display:flex;align-items:center;flex:1 1;min-height:0;min-width:0}\n"], dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i3.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "directive", type: i4.NavItemActiveDirective, selector: "[ecNavItemActive]", inputs: ["ecNavItemActive", "ecNavItemActiveExactMatch", "ecNavItemActiveQueryParams", "ecNavItemActiveUrl"], outputs: ["routerLinkActivated"] }, { kind: "component", type: i5.CollapsibleToggleComponent, selector: "ec-collapsible-toggle", inputs: ["id", "expanded", "tabindex"], outputs: ["expandedChange"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: HierarchyTreeComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ec-hierarchy-tree', template: "<ul id=\"{{scrollContainerId}}\"\r\n    class=\"flex-grow scroll-y py-1\">\r\n\r\n  <li *ngIf=\"!hideRootNode && rootNode\">\r\n    <div class=\"item-wrapper\"\r\n         title=\"{{rootNode?.tooltip ?? rootNode?.label}}\"\r\n         [ngClass]=\"{'is-heading': rootNode?.display === 'heading'}\"\r\n         ecNavItemActive=\"is-selected\"\r\n         [ecNavItemActiveUrl]=\"rootNode?.url\"\r\n         [ecNavItemActiveExactMatch]='rootNode?.isActiveExactMatch'>\r\n      <a id=\"rootNode_{{rootNode?.id}}_link\"\r\n         class=\"item flex-grow d-flex align-items-center\"\r\n         routerLink=\"{{rootNode?.url}}\"\r\n         [queryParams]=\"rootNode?.queryParams\">\r\n        <ng-container *ngTemplateOutlet=\"customItemTemplate || defaultItemTemplate; context: { $implicit: rootNode }\"></ng-container>\r\n      </a>\r\n    </div>\r\n  </li>\r\n\r\n  <ng-template #hierarchyView\r\n               let-items>\r\n    <li *ngFor=\"let item of items; index as index; first as isFirst\"\r\n        [ngClass]=\"{'divider': item.display === 'divider'}\"\r\n        id=\"treeItem_{{item.id}}\">\r\n      <div class=\"item-wrapper\"\r\n           title=\"{{item.tooltip ?? item.label}}\"\r\n           [ngClass]=\"{'is-heading': item.display === 'heading'}\"\r\n           ecNavItemActive=\"is-selected\"\r\n           [ecNavItemActiveUrl]=\"item.url\"\r\n           [ecNavItemActiveExactMatch]=\"item.isActiveExactMatch\"\r\n           [ecNavItemActiveQueryParams]=\"item.queryParams\">\r\n\r\n        <!-- This element provides the indentation for each level -->\r\n        <span id=\"indent_{{item.id}}\"\r\n              *ngIf=\"!item.noIndent\"\r\n              class=\"d-block h-100\"\r\n              [style.width.px]=\"(indent) * (item.level - 1) + (item.level * 4) + (item.hasChildren ? 0 : indent)\">\r\n        </span>\r\n\r\n        <!-- Toggle the button icon to be a spinner when item.status is pending -->\r\n        <ec-collapsible-toggle id=\"toggle_{{item.id}}\"\r\n                               class=\"flex-shrink\"\r\n                               [style.width.px]=\"indent\"\r\n                               *ngIf=\"item.hasChildren && !item.hideToggle\"\r\n                               [hidden]=\"item.status === 'pending'\"\r\n                               [expanded]=\"item.expanded\"\r\n                               (expandedChange)=\"toggleItemClicked(item, $event)\">\r\n        </ec-collapsible-toggle>\r\n\r\n        <i class=\"ec-icon icon-loading my-1\"\r\n           [hidden]=\"item.status !== 'pending'\"></i>\r\n\r\n        <a id=\"treeItem_{{item.id}}_link\"\r\n           class=\"item\"\r\n           *ngIf=\"item.url\"\r\n           (click)=\"selectItem(item)\"\r\n           [routerLink]=\"item.url\"\r\n           [queryParams]=\"item.queryParams\"\r\n           [queryParamsHandling]=\"item.queryParamsHandling || ''\">\r\n           <ng-container *ngTemplateOutlet=\"customItemTemplate || defaultItemTemplate; context: { $implicit: item }\"></ng-container>\r\n        </a>\r\n        <div id=\"treeItem_{{item.id}}_heading\"\r\n             class=\"item\"\r\n             *ngIf=\"!item.url\"\r\n             (click)=\"selectItem(item)\">\r\n             <ng-container *ngTemplateOutlet=\"customItemTemplate || defaultItemTemplate; context: { $implicit: item }\"></ng-container>\r\n        </div>\r\n      </div>\r\n\r\n\r\n      <ul *ngIf=\"item.children.length > 0 && item.expanded\">\r\n        <ng-container *ngTemplateOutlet=\"hierarchyView; context:{ $implicit: item.children }\"></ng-container>\r\n      </ul>\r\n    </li>\r\n  </ng-template>\r\n\r\n  <ng-container *ngTemplateOutlet=\"hierarchyView; context:{ $implicit: rootNode?.children }\"></ng-container>\r\n</ul>\r\n\r\n<ng-template #defaultItemTemplate\r\n             let-item>\r\n  <i class=\"ec-icon {{item.icon}} mx-1 flex-shrink\"\r\n     [attr.title]=\"item.iconTooltip\"\r\n     *ngIf=\"item.icon\"></i>\r\n  <span class=\"mx-1 text-truncate\">{{item.label}}</span>\r\n</ng-template>", styles: [":host{display:block;font-size:var(--ec-menu-font-size, var(--ec-font-size-action));background-color:var(--ec-menu-background-color, var(--ec-background-color))}ul{padding:0;margin:0;list-style:none;overflow-x:hidden}ul li{white-space:nowrap;padding:0}ul li.divider{border-bottom:1px solid var(--ec-border-color);padding-bottom:.25rem;margin-bottom:.25rem}ul .item-wrapper{display:flex;align-items:center;padding:0 .25rem;margin:0 .25rem;height:1.75rem;border-radius:var(--ec-border-radius)}ul .item-wrapper.is-heading{cursor:pointer;color:var(--ec-color-hint-dark);text-transform:uppercase;font-weight:var(--ec-font-weight-bold);font-size:var(--ec-font-size-label)}ul .item-wrapper:hover{background-color:var(--ec-background-color-hover)}ul .item-wrapper.is-selected{font-weight:700}ul .item-wrapper a{text-decoration:none}ul .item{color:inherit;display:flex;align-items:center;flex:1 1;min-height:0;min-width:0}\n"] }]
        }], ctorParameters: () => [{ type: i1.ScrollService }, { type: i0.Injector }], propDecorators: { id: [{
                type: Input
            }], hideRootNode: [{
                type: Input
            }], customItemTemplate: [{
                type: Input
            }], itemSelected: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 