/**
 * SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
 * Copyright (C) 2021 SalesAgility Ltd.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Supercharged by SuiteCRM".
 */
import { Component, Input } from '@angular/core';
import { take } from 'rxjs/operators';
import { AsyncActionService } from '../../../services/process/processes/async-action/async-action';
import { AppStateStore } from '../../../store/app-state/app-state.store';
import { SystemConfigStore } from "../../../store/system-config/system-config.store";
import * as i0 from "@angular/core";
import * as i1 from "../../../services/process/processes/async-action/async-action";
import * as i2 from "../../../store/system-config/system-config.store";
import * as i3 from "../../../store/app-state/app-state.store";
import * as i4 from "@angular/common";
import * as i5 from "@angular/router";
import * as i6 from "../../image/image.component";
import * as i7 from "../../../pipes/truncate/truncate.pipe";
function BaseMenuItemLinkComponent_ng_container_0_scrm_image_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "scrm-image", 3);
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext(2);
    i0.ɵɵpropertyInterpolate("image", ctx_r3.icon);
} }
function BaseMenuItemLinkComponent_ng_container_0_span_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "truncate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r4 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind2(2, 1, ctx_r4.link.label, ctx_r4.charSize.mediumLength));
} }
function BaseMenuItemLinkComponent_ng_container_0_span_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "truncate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r5 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind2(2, 1, ctx_r5.link.label, ctx_r5.charSize.maxLength));
} }
function BaseMenuItemLinkComponent_ng_container_0_Template(rf, ctx) { if (rf & 1) {
    const _r7 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "a", 1);
    i0.ɵɵlistener("click", function BaseMenuItemLinkComponent_ng_container_0_Template_a_click_1_listener($event) { i0.ɵɵrestoreView(_r7); const ctx_r6 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r6.config.onClick($event)); })("touchstart", function BaseMenuItemLinkComponent_ng_container_0_Template_a_touchstart_1_listener($event) { i0.ɵɵrestoreView(_r7); const ctx_r8 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r8.config.onTouchStart($event)); });
    i0.ɵɵtemplate(2, BaseMenuItemLinkComponent_ng_container_0_scrm_image_2_Template, 1, 1, "scrm-image", 2);
    i0.ɵɵtemplate(3, BaseMenuItemLinkComponent_ng_container_0_span_3_Template, 3, 4, "span", 0);
    i0.ɵɵtemplate(4, BaseMenuItemLinkComponent_ng_container_0_span_4_Template, 3, 4, "span", 0);
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngClass", ctx_r0.class);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r0.icon);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r0.link.params);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r0.link.params);
} }
function BaseMenuItemLinkComponent_ng_container_1_a_1_scrm_image_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "scrm-image", 3);
} if (rf & 2) {
    const ctx_r12 = i0.ɵɵnextContext(3);
    i0.ɵɵpropertyInterpolate("image", ctx_r12.icon);
} }
function BaseMenuItemLinkComponent_ng_container_1_a_1_span_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "truncate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r13 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind2(2, 1, ctx_r13.link.label, ctx_r13.charSize.mediumLength));
} }
function BaseMenuItemLinkComponent_ng_container_1_a_1_span_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "truncate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r14 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind2(2, 1, ctx_r14.link.label, ctx_r14.charSize.maxLength));
} }
function BaseMenuItemLinkComponent_ng_container_1_a_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "a", 7);
    i0.ɵɵtemplate(1, BaseMenuItemLinkComponent_ng_container_1_a_1_scrm_image_1_Template, 1, 1, "scrm-image", 2);
    i0.ɵɵtemplate(2, BaseMenuItemLinkComponent_ng_container_1_a_1_span_2_Template, 3, 4, "span", 0);
    i0.ɵɵtemplate(3, BaseMenuItemLinkComponent_ng_container_1_a_1_span_3_Template, 3, 4, "span", 0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r9 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("ngClass", ctx_r9.class)("queryParams", ctx_r9.link.params)("routerLink", ctx_r9.link.route);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r9.icon);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r9.link.params);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r9.link.params);
} }
function BaseMenuItemLinkComponent_ng_container_1_a_2_scrm_image_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "scrm-image", 3);
} if (rf & 2) {
    const ctx_r15 = i0.ɵɵnextContext(3);
    i0.ɵɵpropertyInterpolate("image", ctx_r15.icon);
} }
function BaseMenuItemLinkComponent_ng_container_1_a_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "a", 8);
    i0.ɵɵtemplate(1, BaseMenuItemLinkComponent_ng_container_1_a_2_scrm_image_1_Template, 1, 1, "scrm-image", 2);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r10 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("href", ctx_r10.link.url, i0.ɵɵsanitizeUrl)("ngClass", ctx_r10.class);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r10.icon);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", ctx_r10.link.label, " ");
} }
function BaseMenuItemLinkComponent_ng_container_1_a_3_scrm_image_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "scrm-image", 3);
} if (rf & 2) {
    const ctx_r16 = i0.ɵɵnextContext(3);
    i0.ɵɵpropertyInterpolate("image", ctx_r16.icon);
} }
function BaseMenuItemLinkComponent_ng_container_1_a_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "a", 9);
    i0.ɵɵtemplate(1, BaseMenuItemLinkComponent_ng_container_1_a_3_scrm_image_1_Template, 1, 1, "scrm-image", 2);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r11 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("ngClass", ctx_r11.class);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r11.icon);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", ctx_r11.link.label, " ");
} }
function BaseMenuItemLinkComponent_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, BaseMenuItemLinkComponent_ng_container_1_a_1_Template, 4, 6, "a", 4);
    i0.ɵɵtemplate(2, BaseMenuItemLinkComponent_ng_container_1_a_2_Template, 3, 4, "a", 5);
    i0.ɵɵtemplate(3, BaseMenuItemLinkComponent_ng_container_1_a_3_Template, 3, 3, "a", 6);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1.link.route);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r1.link.route && ctx_r1.link.url);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r1.link.route && !ctx_r1.link.url);
} }
function BaseMenuItemLinkComponent_ng_container_2_scrm_image_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "scrm-image", 3);
} if (rf & 2) {
    const ctx_r17 = i0.ɵɵnextContext(2);
    i0.ɵɵpropertyInterpolate("image", ctx_r17.icon);
} }
function BaseMenuItemLinkComponent_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    const _r19 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "a", 10);
    i0.ɵɵlistener("click", function BaseMenuItemLinkComponent_ng_container_2_Template_a_click_1_listener() { i0.ɵɵrestoreView(_r19); const ctx_r18 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r18.handleProcess(ctx_r18.link.process)); });
    i0.ɵɵtemplate(2, BaseMenuItemLinkComponent_ng_container_2_scrm_image_2_Template, 1, 1, "scrm-image", 2);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngClass", ctx_r2.class);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r2.icon);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", ctx_r2.link.label, " ");
} }
class BaseMenuItemLinkComponent {
    constructor(asyncActionService, systemConfigStore, appState) {
        this.asyncActionService = asyncActionService;
        this.systemConfigStore = systemConfigStore;
        this.appState = appState;
        this.charSize = {
            minLength: 20,
            mediumLength: 20,
            maxLength: 20
        };
    }
    ngOnInit() {
        const characterSizes = this.systemConfigStore.getUi('navbar_truncate_character_sizes');
        this.charSize = { ...characterSizes };
    }
    handleProcess(process) {
        if (!process) {
            return;
        }
        const processType = process;
        const options = {
            action: processType,
            module: this.appState.getModule(),
        };
        this.asyncActionService.run(processType, options).pipe(take(1)).subscribe();
    }
    static { this.ɵfac = function BaseMenuItemLinkComponent_Factory(t) { return new (t || BaseMenuItemLinkComponent)(i0.ɵɵdirectiveInject(i1.AsyncActionService), i0.ɵɵdirectiveInject(i2.SystemConfigStore), i0.ɵɵdirectiveInject(i3.AppStateStore)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: BaseMenuItemLinkComponent, selectors: [["scrm-base-menu-item-link"]], inputs: { link: "link", icon: "icon", class: "class", config: "config" }, decls: 3, vars: 3, consts: [[4, "ngIf"], [3, "ngClass", "click", "touchstart"], [3, "image", 4, "ngIf"], [3, "image"], [3, "ngClass", "queryParams", "routerLink", 4, "ngIf"], [3, "href", "ngClass", 4, "ngIf"], [3, "ngClass", 4, "ngIf"], [3, "ngClass", "queryParams", "routerLink"], [3, "href", "ngClass"], [3, "ngClass"], [3, "ngClass", "click"]], template: function BaseMenuItemLinkComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵtemplate(0, BaseMenuItemLinkComponent_ng_container_0_Template, 5, 4, "ng-container", 0);
            i0.ɵɵtemplate(1, BaseMenuItemLinkComponent_ng_container_1_Template, 4, 3, "ng-container", 0);
            i0.ɵɵtemplate(2, BaseMenuItemLinkComponent_ng_container_2_Template, 4, 3, "ng-container", 0);
        } if (rf & 2) {
            i0.ɵɵproperty("ngIf", !ctx.link.process && (ctx.config == null ? null : ctx.config.onClick));
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", !ctx.link.process && !(ctx.config == null ? null : ctx.config.onClick));
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.link.process);
        } }, dependencies: [i4.NgClass, i4.NgIf, i5.RouterLink, i6.ImageComponent, i7.TruncatePipe], encapsulation: 2 }); }
}
export { BaseMenuItemLinkComponent };
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BaseMenuItemLinkComponent, [{
        type: Component,
        args: [{ selector: 'scrm-base-menu-item-link', template: "<! --\n/**\n* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.\n* Copyright (C) 2021 SalesAgility Ltd.\n*\n* This program is free software; you can redistribute it and/or modify it under\n* the terms of the GNU Affero General Public License version 3 as published by the\n* Free Software Foundation with the addition of the following permission added\n* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK\n* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE\n* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.\n*\n* This program is distributed in the hope that it will be useful, but WITHOUT\n* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n* details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program.  If not, see http://www.gnu.org/licenses.\n*\n* In accordance with Section 7(b) of the GNU Affero General Public License\n* version 3, these Appropriate Legal Notices must retain the display of the\n* \"Supercharged by SuiteCRM\" logo. If the display of the logos is not reasonably\n* feasible for technical reasons, the Appropriate Legal Notices must display\n* the words \"Supercharged by SuiteCRM\".\n*/\n-->\n<ng-container *ngIf=\"!link.process && config?.onClick\">\n    <a (click)=\"config.onClick($event)\"\n       (touchstart)=\"config.onTouchStart($event)\"\n       [ngClass]=\"class\"\n    >\n        <scrm-image *ngIf=\"icon\" image=\"{{ icon }}\"></scrm-image>\n        <span *ngIf=\"!link.params\">{{ link.label | truncate: charSize.mediumLength }}</span>\n        <span *ngIf=\"link.params\">{{ link.label | truncate: charSize.maxLength }}</span>\n    </a>\n</ng-container>\n<ng-container *ngIf=\"!link.process && !config?.onClick\">\n    <a *ngIf=\"link.route\"\n       [ngClass]=\"class\"\n       [queryParams]=\"link.params\"\n       [routerLink]=\"link.route\"\n    >\n        <scrm-image *ngIf=\"icon\" image=\"{{ icon }}\"></scrm-image>\n        <span *ngIf=\"!link.params\">{{ link.label | truncate: charSize.mediumLength  }}</span>\n        <span *ngIf=\"link.params\">{{ link.label | truncate: charSize.maxLength  }}</span>\n    </a>\n    <a *ngIf=\"!link.route && link.url\"\n       [href]=\"link.url\"\n       [ngClass]=\"class\"\n    >\n        <scrm-image *ngIf=\"icon\" image=\"{{ icon }}\"></scrm-image>\n        {{ link.label }}\n    </a>\n    <a *ngIf=\"!link.route && !link.url\"\n       [ngClass]=\"class\"\n    >\n        <scrm-image *ngIf=\"icon\" image=\"{{ icon }}\"></scrm-image>\n        {{ link.label }}\n    </a>\n</ng-container>\n<ng-container *ngIf=\"link.process\">\n    <a [ngClass]=\"class\" (click)=\"handleProcess(link.process)\">\n        <scrm-image *ngIf=\"icon\" image=\"{{ icon }}\"></scrm-image>\n        {{ link.label }}\n    </a>\n</ng-container>\n\n\n" }]
    }], function () { return [{ type: i1.AsyncActionService }, { type: i2.SystemConfigStore }, { type: i3.AppStateStore }]; }, { link: [{
            type: Input
        }], icon: [{
            type: Input
        }], class: [{
            type: Input
        }], config: [{
            type: Input
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 