import { __decorate } from "tslib";
import { ChangeDetectionStrategy, Component, ContentChildren, Input, ViewEncapsulation } from '@angular/core';
import { Select } from '@ngxs/store';
import { UntilDestroy } from '@ngneat/until-destroy';
import { PrimeTemplate } from 'primeng/api';
import { LayoutUiSelectors } from '../../../../../../state/ui/layout/layout.selectors';
import { MenuType } from '../../../../core/models/menu-types';
import { UiAthenaSelectors } from '../../state/ui-layout.selectors';
import { RouterState } from '@ngxs/router-plugin';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "../../../../../../common/menu-item-actions/menu-item-actions.directive";
import * as i3 from "./components/menu-node.component";
import * as i4 from "../../../../../../common/is-visible-pipe/is-visible.pipe";
import * as i5 from "../../../../../../common/url-checker/url-checker.pipe";
import * as i6 from "./pipes/has-child.pipe";
let AthenaHorizontalMenuComponent = class AthenaHorizontalMenuComponent {
    constructor(_eref) {
        this._eref = _eref;
        this.isAnyMenuExpanded = false;
        this.menuType = MenuType;
    }
    ngAfterContentInit() {
        this.templates.forEach((item) => {
            switch (item.getType()) {
                case 'headerExtras':
                    this.headerExtrasTemplate = item.template;
                    break;
            }
        });
    }
    ngOnChanges(changes) {
        if (changes.menu != null) {
            const data = changes.menu.currentValue;
            if (data == null) {
                document.documentElement.style.setProperty('--layout-menu-height', '0em');
            }
            else {
                document.documentElement.style.setProperty('--layout-menu-height', '4em');
            }
        }
    }
    toogleOnly(item, menu) {
        this.collapseAll(menu);
        item.expanded = !item.expanded;
        this.isAnyMenuExpanded = item.expanded;
    }
    collapseAll(menu) {
        menu?.forEach(x => {
            x.expanded = false;
            if (x.items != null && x.items.length > 0) {
                this.collapseAll(x.items);
            }
        });
        this.isAnyMenuExpanded = false;
    }
    collapseFromOutside(event) {
        const target = event.target;
        if (target.className === 'layout-menu' || !this._eref.nativeElement.contains(target)) {
            this.collapseAll(this.menu);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: AthenaHorizontalMenuComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.5", type: AthenaHorizontalMenuComponent, selector: "smz-ui-athena-horizontal-menu", inputs: { menu: "menu" }, host: { listeners: { "document:click": "collapseFromOutside($event)" } }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], usesOnChanges: true, ngImport: i0, template: " <ng-container *ngIf=\"menu != null\">\r\n    <ng-container *ngIf=\"layout$ | async as layout\">\r\n        <ng-container *ngIf=\"appName$ | async as appName\">\r\n            <ng-container *ngIf=\"(currentRoute$ | async) as route\">\r\n\r\n                <div class=\"layout-menu-container\">\r\n                    <div class=\"layout-menu-content\">\r\n\r\n                        <ul id=\"menu-ul\" class=\"layout-menu\">\r\n\r\n                            <!-- N\u00CDVEL 1 -->\r\n                            <ng-container *ngFor=\"let item of menu | isVisible; let last = last; let itemIndex = index;\">\r\n\r\n                                <ng-container [ngSwitch]=\"item | hasChild\">\r\n\r\n                                    <ng-container *ngSwitchCase=\"false\">\r\n                                        <li class=\"layout-root-menuitem\" [ngClass]=\"{ 'active-menuitem' : item.expanded }\">\r\n                                            <div class=\"layout-menuitem-root-text clickable\" menuItemAction [item]=\"item\" [parent]=\"null\" [breadcrumbs]=\"true\" (collapse)=\"collapseAll(menu)\">{{ item.label }}</div>\r\n\r\n                                            <a class=\"p-ripple\" menuItemAction [item]=\"item\" [parent]=\"null\" [breadcrumbs]=\"true\" (collapse)=\"collapseAll(menu)\" [tabindex]=\"itemIndex\" [ngClass]=\"{ 'active-first-route': route.url | urlChecker : item.routerLink }\">\r\n                                                <i *ngIf=\"item.icon\" class=\"layout-menuitem-icon\" [ngClass]=\"item.icon\"></i>\r\n                                                <span>{{ item.label }}</span>\r\n                                                <span class=\"p-ink\"></span>\r\n                                            </a>\r\n\r\n                                        </li>\r\n                                    </ng-container>\r\n\r\n                                    <ng-container *ngSwitchCase=\"true\">\r\n                                        <li class=\"layout-root-menuitem\" [ngClass]=\"{ 'active-menuitem' : item.expanded }\">\r\n                                            <div class=\"layout-menuitem-root-text\">{{ item.label }}</div>\r\n\r\n                                            <a class=\"p-ripple\" [tabindex]=\"itemIndex\" (click)=\"toogleOnly(item, menu)\">\r\n                                                <i *ngIf=\"item.icon\" class=\"layout-menuitem-icon\" [ngClass]=\"item.icon\"></i>\r\n                                                <span>{{ item.label }}</span>\r\n                                                <i class=\"pi pi-fw pi-angle-down layout-menuitem-toggler\"></i>\r\n\r\n                                                <span class=\"p-ink\"></span>\r\n                                            </a>\r\n\r\n                                            <ul smz-ui-athena-horizontal-menu-node [item]=\"item\" [currentUrl]=\"route.url\" role=\"menu\" style=\"z-index: 100;\" (collapse)=\"collapseAll(menu)\"></ul>\r\n\r\n                                        </li>\r\n                                    </ng-container>\r\n\r\n                                </ng-container>\r\n\r\n                            </ng-container>\r\n\r\n                        </ul>\r\n\r\n                    </div>\r\n                </div>\r\n\r\n            </ng-container>\r\n        </ng-container>\r\n    </ng-container>\r\n</ng-container>", styles: ["smz-ui-athena-horizontal-menu .active-first-route{border-bottom-color:var(--primary-color-menu-active)!important;color:var(--primary-color-menu-active)!important}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i2.MenuItemActionsDirective, selector: "[menuItemAction]", inputs: ["item", "parent", "breadcrumbs"], outputs: ["collapse"] }, { kind: "component", type: i3.AthenaHorizontalMenuNodeComponent, selector: "[smz-ui-athena-horizontal-menu-node]", inputs: ["item", "index", "currentUrl"], outputs: ["collapse"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }, { kind: "pipe", type: i4.IsVisiblePipe, name: "isVisible" }, { kind: "pipe", type: i5.UrlCheckerPipe, name: "urlChecker" }, { kind: "pipe", type: i6.HasChildPipe, name: "hasChild" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
};
__decorate([
    Select(LayoutUiSelectors.topbarTitle)
], AthenaHorizontalMenuComponent.prototype, "topbarTitle$", void 0);
__decorate([
    Select(LayoutUiSelectors.appContentLogo)
], AthenaHorizontalMenuComponent.prototype, "appLogo$", void 0);
__decorate([
    Select(UiAthenaSelectors.layout)
], AthenaHorizontalMenuComponent.prototype, "layout$", void 0);
__decorate([
    Select(LayoutUiSelectors.appName)
], AthenaHorizontalMenuComponent.prototype, "appName$", void 0);
__decorate([
    Select(RouterState.state)
], AthenaHorizontalMenuComponent.prototype, "currentRoute$", void 0);
AthenaHorizontalMenuComponent = __decorate([
    UntilDestroy()
], AthenaHorizontalMenuComponent);
export { AthenaHorizontalMenuComponent };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: AthenaHorizontalMenuComponent, decorators: [{
            type: Component,
            args: [{ selector: 'smz-ui-athena-horizontal-menu', host: { "(document:click)": "collapseFromOutside($event)" }, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: " <ng-container *ngIf=\"menu != null\">\r\n    <ng-container *ngIf=\"layout$ | async as layout\">\r\n        <ng-container *ngIf=\"appName$ | async as appName\">\r\n            <ng-container *ngIf=\"(currentRoute$ | async) as route\">\r\n\r\n                <div class=\"layout-menu-container\">\r\n                    <div class=\"layout-menu-content\">\r\n\r\n                        <ul id=\"menu-ul\" class=\"layout-menu\">\r\n\r\n                            <!-- N\u00CDVEL 1 -->\r\n                            <ng-container *ngFor=\"let item of menu | isVisible; let last = last; let itemIndex = index;\">\r\n\r\n                                <ng-container [ngSwitch]=\"item | hasChild\">\r\n\r\n                                    <ng-container *ngSwitchCase=\"false\">\r\n                                        <li class=\"layout-root-menuitem\" [ngClass]=\"{ 'active-menuitem' : item.expanded }\">\r\n                                            <div class=\"layout-menuitem-root-text clickable\" menuItemAction [item]=\"item\" [parent]=\"null\" [breadcrumbs]=\"true\" (collapse)=\"collapseAll(menu)\">{{ item.label }}</div>\r\n\r\n                                            <a class=\"p-ripple\" menuItemAction [item]=\"item\" [parent]=\"null\" [breadcrumbs]=\"true\" (collapse)=\"collapseAll(menu)\" [tabindex]=\"itemIndex\" [ngClass]=\"{ 'active-first-route': route.url | urlChecker : item.routerLink }\">\r\n                                                <i *ngIf=\"item.icon\" class=\"layout-menuitem-icon\" [ngClass]=\"item.icon\"></i>\r\n                                                <span>{{ item.label }}</span>\r\n                                                <span class=\"p-ink\"></span>\r\n                                            </a>\r\n\r\n                                        </li>\r\n                                    </ng-container>\r\n\r\n                                    <ng-container *ngSwitchCase=\"true\">\r\n                                        <li class=\"layout-root-menuitem\" [ngClass]=\"{ 'active-menuitem' : item.expanded }\">\r\n                                            <div class=\"layout-menuitem-root-text\">{{ item.label }}</div>\r\n\r\n                                            <a class=\"p-ripple\" [tabindex]=\"itemIndex\" (click)=\"toogleOnly(item, menu)\">\r\n                                                <i *ngIf=\"item.icon\" class=\"layout-menuitem-icon\" [ngClass]=\"item.icon\"></i>\r\n                                                <span>{{ item.label }}</span>\r\n                                                <i class=\"pi pi-fw pi-angle-down layout-menuitem-toggler\"></i>\r\n\r\n                                                <span class=\"p-ink\"></span>\r\n                                            </a>\r\n\r\n                                            <ul smz-ui-athena-horizontal-menu-node [item]=\"item\" [currentUrl]=\"route.url\" role=\"menu\" style=\"z-index: 100;\" (collapse)=\"collapseAll(menu)\"></ul>\r\n\r\n                                        </li>\r\n                                    </ng-container>\r\n\r\n                                </ng-container>\r\n\r\n                            </ng-container>\r\n\r\n                        </ul>\r\n\r\n                    </div>\r\n                </div>\r\n\r\n            </ng-container>\r\n        </ng-container>\r\n    </ng-container>\r\n</ng-container>", styles: ["smz-ui-athena-horizontal-menu .active-first-route{border-bottom-color:var(--primary-color-menu-active)!important;color:var(--primary-color-menu-active)!important}\n"] }]
        }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { templates: [{
                type: ContentChildren,
                args: [PrimeTemplate]
            }], topbarTitle$: [], appLogo$: [], layout$: [], appName$: [], currentRoute$: [], menu: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 