import { Component } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "../../services/login/login.service";
import * as i2 from "../../services/util/util.service";
import * as i3 from "@angular/router";
import * as i4 from "@ionic/angular";
import * as i5 from "@angular/common";
import * as i6 from "primeng/tooltip";
import * as i7 from "@angular/material/form-field";
import * as i8 from "primeng/tabview";
import * as i9 from "@ngx-translate/core";
function FavMenuComponent_ion_item_3_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "ion-item", 6);
    i0.ɵɵlistener("click", function FavMenuComponent_ion_item_3_Template_ion_item_click_0_listener() { const restoredCtx = i0.ɵɵrestoreView(_r5); const item_r3 = restoredCtx.$implicit; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.openPage(item_r3)); });
    i0.ɵɵelementStart(1, "ion-label", 7);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "ion-button", 8);
    i0.ɵɵlistener("click", function FavMenuComponent_ion_item_3_Template_ion_button_click_3_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r5); const item_r3 = restoredCtx.$implicit; const ctx_r6 = i0.ɵɵnextContext(); ctx_r6.removeFav(item_r3); return i0.ɵɵresetView($event.stopPropagation()); });
    i0.ɵɵelement(4, "ion-icon", 9);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const item_r3 = ctx.$implicit;
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(item_r3.label);
} }
function FavMenuComponent_div_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 10)(1, "mat-hint")(2, "small");
    i0.ɵɵtext(3);
    i0.ɵɵpipe(4, "translate");
    i0.ɵɵelementEnd()();
    i0.ɵɵelement(5, "ion-menu-button", 11);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(4, 1, "No Favorite Menu selected. Click below to select Favorite Menu."));
} }
function FavMenuComponent_p_tabPanel_5_ion_item_2_Template(rf, ctx) { if (rf & 1) {
    const _r11 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "ion-item", 15);
    i0.ɵɵlistener("click", function FavMenuComponent_p_tabPanel_5_ion_item_2_Template_ion_item_click_0_listener() { const restoredCtx = i0.ɵɵrestoreView(_r11); const link_r9 = restoredCtx.$implicit; const ctx_r10 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r10.openPage(link_r9)); });
    i0.ɵɵelementStart(1, "ion-button", 16);
    i0.ɵɵelement(2, "ion-icon", 17);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "ion-label", 7)(4, "b");
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const link_r9 = ctx.$implicit;
    i0.ɵɵstyleMapInterpolate1("--border-width: 0 0 2px 0; --border-color: ", link_r9.state.color, "; font-size: small; padding: 1px;");
    i0.ɵɵadvance(1);
    i0.ɵɵstyleMapInterpolate1("--background: ", link_r9.state.color, ";");
    i0.ɵɵadvance(2);
    i0.ɵɵstyleMapInterpolate1("--color: ", link_r9.state.color, ";");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(link_r9.label);
} }
function FavMenuComponent_p_tabPanel_5_div_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 10)(1, "mat-hint")(2, "small");
    i0.ɵɵtext(3);
    i0.ɵɵpipe(4, "translate");
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(4, 1, "No Trending Menu set at this time."));
} }
function FavMenuComponent_p_tabPanel_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "p-tabPanel", 12)(1, "ion-list", 13);
    i0.ɵɵtemplate(2, FavMenuComponent_p_tabPanel_5_ion_item_2_Template, 6, 10, "ion-item", 14);
    i0.ɵɵelementEnd();
    i0.ɵɵtemplate(3, FavMenuComponent_p_tabPanel_5_div_3_Template, 5, 3, "div", 4);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngForOf", ctx_r2.trendingLinks);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r2.trendingLinks || ctx_r2.trendingLinks.length < 1);
} }
export class FavMenuComponent {
    constructor(ls, util, r) {
        this.ls = ls;
        this.util = util;
        this.r = r;
        this.favs = [];
        this.trendingLinks = [];
        this.activeIndex = 1;
    }
    ngOnInit() {
        this.ls.getMenuBs().subscribe(menus => {
            this.favs = [];
            if (menus) {
                menus.forEach(menu => {
                    menu.items.forEach(item => {
                        if (item.state.isFav) {
                            this.favs.push(item);
                            this.activeIndex = 0;
                        }
                    });
                });
            }
        });
        this.ls.getUserBs().subscribe(user => {
            if (user && !user.is2FARequired) {
                this.ls.getTrendingMenu().subscribe(res => {
                    this.trendingLinks = res;
                }, err => {
                    this.trendingLinks = [];
                });
            }
        });
    }
    removeFav(item) {
        this.ls
            .removeFav(item.state.id)
            .subscribe(res => {
            this.ls.getMenuBs().next(res);
            this.util.toast("Removed Favourite.");
        });
    }
    openPage(menu) {
        if (!menu) {
            return;
        }
        let currentContextRoot = this.getContextRoot();
        let menuContextRoot = `/${menu.state.context}`;
        let pageToNavigate = menu.state.routerLink;
        if (currentContextRoot == menuContextRoot) {
            this.r.navigateByUrl(`/${pageToNavigate}`);
        }
        else {
            window.open(location.origin + `${menuContextRoot}/${menu.state.routerLink}`, '_self');
        }
    }
    getContextRoot() {
        return window.location.pathname.substring(0, window.location.pathname.indexOf("/", 2));
    }
    static { this.ɵfac = function FavMenuComponent_Factory(t) { return new (t || FavMenuComponent)(i0.ɵɵdirectiveInject(i1.LoginService), i0.ɵɵdirectiveInject(i2.UtilService), i0.ɵɵdirectiveInject(i3.Router)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: FavMenuComponent, selectors: [["app-fav-menu"]], decls: 6, vars: 4, consts: [[3, "activeIndex", "activeIndexChange"], ["header", "Fav", "leftIcon", "pi pi-star"], ["lines", "none"], ["button", "true", "style", " font-size: small; padding: 1px", 3, "click", 4, "ngFor", "ngForOf"], ["class", "ion-text-center", 4, "ngIf"], ["header", "Trending", "leftIcon", "pi pi-chart-line", 4, "ngIf"], ["button", "true", 2, "font-size", "small", "padding", "1px", 3, "click"], [1, "ion-text-wrap"], ["slot", "end", "color", "danger", 3, "click"], ["name", "remove-circle-outline"], [1, "ion-text-center"], ["autoHide", "false", "pTooltip", "Menu", "tooltipPosition", "bottom"], ["header", "Trending", "leftIcon", "pi pi-chart-line"], ["lines", "full"], ["button", "true", 3, "style", "click", 4, "ngFor", "ngForOf"], ["button", "true", 3, "click"], ["slot", "start"], ["name", "link-outline"]], template: function FavMenuComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "p-tabView", 0);
            i0.ɵɵlistener("activeIndexChange", function FavMenuComponent_Template_p_tabView_activeIndexChange_0_listener($event) { return ctx.activeIndex = $event; });
            i0.ɵɵelementStart(1, "p-tabPanel", 1)(2, "ion-list", 2);
            i0.ɵɵtemplate(3, FavMenuComponent_ion_item_3_Template, 5, 1, "ion-item", 3)(4, FavMenuComponent_div_4_Template, 6, 3, "div", 4);
            i0.ɵɵelementEnd()();
            i0.ɵɵtemplate(5, FavMenuComponent_p_tabPanel_5_Template, 4, 2, "p-tabPanel", 5);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵproperty("activeIndex", ctx.activeIndex);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("ngForOf", ctx.favs);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.favs.length < 1);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.trendingLinks && ctx.trendingLinks.length > 1);
        } }, dependencies: [i4.IonButton, i4.IonIcon, i4.IonItem, i4.IonLabel, i4.IonList, i4.IonMenuButton, i5.NgForOf, i5.NgIf, i6.Tooltip, i7.MatHint, i8.TabView, i8.TabPanel, i9.TranslatePipe] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(FavMenuComponent, [{
        type: Component,
        args: [{ selector: 'app-fav-menu', template: "<p-tabView [(activeIndex)]=\"activeIndex\">\r\n    <p-tabPanel header=\"Fav\" leftIcon=\"pi pi-star\">\r\n        <ion-list lines=\"none\">\r\n            <ion-item button='true' style=\" font-size: small; padding: 1px\" *ngFor=\"let item of favs\"\r\n                (click)=\"openPage(item)\">\r\n                <ion-label class=\"ion-text-wrap\">{{item.label}}</ion-label>\r\n                <ion-button slot=\"end\" color=\"danger\" (click)=\"removeFav(item); $event.stopPropagation();\">\r\n                    <ion-icon name=\"remove-circle-outline\"></ion-icon>\r\n                </ion-button>\r\n            </ion-item>\r\n            <div *ngIf=\"favs.length < 1\" class=\"ion-text-center\">\r\n                <mat-hint><small>{{'No Favorite Menu selected. Click below to select Favorite Menu.' | translate}}</small></mat-hint>\r\n                <ion-menu-button autoHide=\"false\" pTooltip=\"Menu\" tooltipPosition=\"bottom\"></ion-menu-button>\r\n            </div>\r\n        </ion-list>\r\n    </p-tabPanel>\r\n    <p-tabPanel header=\"Trending\" leftIcon=\"pi pi-chart-line\" *ngIf=\"trendingLinks && trendingLinks.length > 1\">\r\n        <ion-list lines=\"full\">\r\n            <ion-item button='true'\r\n                style=\"--border-width: 0 0 2px 0; --border-color: {{link.state.color}}; font-size: small; padding: 1px;\"\r\n                *ngFor=\"let link of trendingLinks\" (click)=\"openPage(link)\">\r\n                <ion-button slot=\"start\" style=\"--background: {{link.state.color}};\">\r\n                    <ion-icon name=\"link-outline\"></ion-icon>\r\n                </ion-button>\r\n                <ion-label style=\"--color: {{link.state.color}};\" class=\"ion-text-wrap\"><b>{{link.label}}</b></ion-label>\r\n            </ion-item>\r\n        </ion-list>\r\n        <div *ngIf=\"!trendingLinks || trendingLinks.length < 1\" class=\"ion-text-center\">\r\n            <mat-hint><small>{{'No Trending Menu set at this time.' | translate}}</small></mat-hint>\r\n        </div>\r\n    </p-tabPanel>\r\n</p-tabView>" }]
    }], () => [{ type: i1.LoginService }, { type: i2.UtilService }, { type: i3.Router }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(FavMenuComponent, { className: "FavMenuComponent", filePath: "lib\\components\\fav-menu\\fav-menu.component.ts", lineNumber: 12 }); })();
//# sourceMappingURL=data:application/json;base64, 