(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@wm/components/base'), require('@wm/components/navigation/menu'), require('@angular/router'), require('@wm/core')) :
    typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common', '@wm/components/base', '@wm/components/navigation/menu', '@angular/router', '@wm/core'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.wm = global.wm || {}, global.wm.components = global.wm.components || {}, global.wm.components.navigation = global.wm.components.navigation || {}, global.wm.components.navigation.breadcrumb = {}), global.ng.core, global.ng.common, global.wm.components.base, global.wm.components.navigation.menu, global.ng.router, global.wm.core));
})(this, (function (exports, i0, i2, i4, i3, i1, core) { 'use strict';

    function _interopNamespaceDefault(e) {
        var n = Object.create(null);
        if (e) {
            Object.keys(e).forEach(function (k) {
                if (k !== 'default') {
                    var d = Object.getOwnPropertyDescriptor(e, k);
                    Object.defineProperty(n, k, d.get ? d : {
                        enumerable: true,
                        get: function () { return e[k]; }
                    });
                }
            });
        }
        n.default = e;
        return Object.freeze(n);
    }

    var i0__namespace = /*#__PURE__*/_interopNamespaceDefault(i0);
    var i2__namespace = /*#__PURE__*/_interopNamespaceDefault(i2);
    var i4__namespace = /*#__PURE__*/_interopNamespaceDefault(i4);
    var i3__namespace = /*#__PURE__*/_interopNamespaceDefault(i3);
    var i1__namespace = /*#__PURE__*/_interopNamespaceDefault(i1);

    const registerProps = () => {
        i4.register('wm-breadcrumb', new Map([
            ['class', i4.PROP_STRING],
            ['dataset', i4.PROP_ANY],
            ['itemlabel', i4.PROP_STRING],
            ['itemid', i4.PROP_STRING],
            ['itemlink', i4.PROP_STRING],
            ['itemicon', i4.PROP_STRING],
            ['itemchildren', i4.PROP_STRING],
            ['itemclass', i4.PROP_STRING],
            ['itemtarget', i4.PROP_STRING],
            ['name', i4.PROP_STRING],
            ['show', { value: true, ...i4.PROP_BOOLEAN }]
        ]));
    };

    const _c0 = ["wmBreadcrumb", ""];
    const _c1 = a0 => ({ active: a0 });
    function BreadcrumbComponent_li_0_a_2_Template(rf, ctx) { if (rf & 1) {
        const _r1 = i0__namespace.ɵɵgetCurrentView();
        i0__namespace.ɵɵelementStart(0, "a", 4);
        i0__namespace.ɵɵlistener("click", function BreadcrumbComponent_li_0_a_2_Template_a_click_0_listener($event) { i0__namespace.ɵɵrestoreView(_r1); const item_r2 = i0__namespace.ɵɵnextContext().$implicit; const ctx_r2 = i0__namespace.ɵɵnextContext(); return i0__namespace.ɵɵresetView(ctx_r2.onItemClick($event, item_r2)); });
        i0__namespace.ɵɵelementEnd();
    } if (rf & 2) {
        const item_r2 = i0__namespace.ɵɵnextContext().$implicit;
        const ctx_r2 = i0__namespace.ɵɵnextContext();
        i0__namespace.ɵɵproperty("title", item_r2.label)("wmNavigationControl", item_r2.link)("disableMenuContext", ctx_r2.disableMenuContext || !!item_r2.action)("textContent", item_r2.label);
    } }
    function BreadcrumbComponent_li_0_a_3_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelement(0, "a", 5);
    } if (rf & 2) {
        const item_r2 = i0__namespace.ɵɵnextContext().$implicit;
        i0__namespace.ɵɵproperty("title", item_r2.label)("textContent", item_r2.label);
    } }
    function BreadcrumbComponent_li_0_Template(rf, ctx) { if (rf & 1) {
        i0__namespace.ɵɵelementStart(0, "li", 1);
        i0__namespace.ɵɵelement(1, "i");
        i0__namespace.ɵɵtemplate(2, BreadcrumbComponent_li_0_a_2_Template, 1, 4, "a", 2)(3, BreadcrumbComponent_li_0_a_3_Template, 1, 2, "a", 3);
        i0__namespace.ɵɵelementEnd();
    } if (rf & 2) {
        const item_r2 = ctx.$implicit;
        const last_r4 = ctx.last;
        i0__namespace.ɵɵclassMap(item_r2.class);
        i0__namespace.ɵɵproperty("ngClass", i0__namespace.ɵɵpureFunction1(9, _c1, last_r4));
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵclassMap(item_r2.icon);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngIf", !last_r4);
        i0__namespace.ɵɵadvance();
        i0__namespace.ɵɵproperty("ngIf", last_r4);
    } }
    const DEFAULT_CLS = 'breadcrumb app-breadcrumb';
    const WIDGET_CONFIG = { widgetType: 'wm-breadcrumb', hostClass: DEFAULT_CLS };
    class BreadcrumbComponent extends i4.DatasetAwareNavComponent {
        static { this.initializeProps = registerProps(); }
        constructor(inj, route, location, beforeNavigateCB, explicitContext) {
            super(inj, WIDGET_CONFIG, explicitContext);
            this.route = route;
            this.location = location;
            i4.styler(this.nativeElement, this, i4.APPLY_STYLES_TYPE.CONTAINER);
            this.disableMenuContext = !!beforeNavigateCB;
        }
        /**
         * Gets the first path found based on the key provided inside info Object.
         * @param info - Info object which has properties key(Active Page Name) and isPathFound[boolean] is set true if path found.
         * @param children - a child Object form children Array.
         * @param path - final path.
         * @returns {*|Array}: returns array of objects which represents the final path.
         */
        getPath(info, children, path = []) {
            children.forEach((child) => {
                // return if path already found.
                if (info.isPathFound) {
                    return path;
                }
                // if key is matched set path found to true and return the path.
                if (child.id === info.key) {
                    info.isPathFound = true;
                    // only push the child object by omiting the children within it.
                    path.push(child);
                    return path;
                }
                // if the node has children make a recursive call.
                if (child.children.length) {
                    path.push(child);
                    this.getPath(info, child.children, path);
                    // if path is not found in that node pop the node.
                    if (!info.isPathFound) {
                        path.pop();
                    }
                }
            });
            // return the path.
            return path;
        }
        getCurrentRoute() {
            return this.location.path().substr(1).split('?')[0];
        }
        // over rides resetNode function, generating path for the breadcrumb.
        resetNodes() {
            super.resetNodes();
            // get path only if the widget have id property.
            if (this.itemid || this.binditemid) {
                this.nodes = this.getPath({ key: this.getCurrentRoute(), isPathFound: false }, this.nodes);
            }
        }
        onItemClick($event, $item) {
            $event.preventDefault();
            const locals = { $item: $item.value, $event };
            const canNavigate = !(this.invokeEventCallback('beforenavigate', locals) === false);
            const linkTarget = $item.target;
            let itemLink = $item.link;
            if (itemLink && canNavigate) {
                if (itemLink.startsWith('#/') && (!linkTarget || linkTarget === '_self')) {
                    const queryParams = core.getUrlParams(itemLink);
                    itemLink = core.getRouteNameFromLink(itemLink);
                    this.route.navigate([itemLink], { queryParams });
                }
                else {
                    core.openLink(itemLink, linkTarget);
                }
            }
        }
        static { this.ɵfac = function BreadcrumbComponent_Factory(t) { return new (t || BreadcrumbComponent)(i0__namespace.ɵɵdirectiveInject(i0__namespace.Injector), i0__namespace.ɵɵdirectiveInject(i1__namespace.Router), i0__namespace.ɵɵdirectiveInject(i2__namespace.Location), i0__namespace.ɵɵinjectAttribute('beforenavigate.event'), i0__namespace.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
        static { this.ɵcmp = /*@__PURE__*/ i0__namespace.ɵɵdefineComponent({ type: BreadcrumbComponent, selectors: [["", "wmBreadcrumb", ""]], features: [i0__namespace.ɵɵProvidersFeature([
                    i4.provideAsWidgetRef(BreadcrumbComponent)
                ]), i0__namespace.ɵɵInheritDefinitionFeature], attrs: _c0, decls: 1, vars: 1, consts: [[3, "ngClass", "class", 4, "ngFor", "ngForOf"], [3, "ngClass"], ["href", "javascript:void(0)", 3, "title", "wmNavigationControl", "disableMenuContext", "textContent", "click", 4, "ngIf"], ["href", "javascript:void(0)", "class", "text-muted", "tabindex", "0", "aria-current", "page", 3, "title", "textContent", 4, "ngIf"], ["href", "javascript:void(0)", 3, "click", "title", "wmNavigationControl", "disableMenuContext", "textContent"], ["href", "javascript:void(0)", "tabindex", "0", "aria-current", "page", 1, "text-muted", 3, "title", "textContent"]], template: function BreadcrumbComponent_Template(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵtemplate(0, BreadcrumbComponent_li_0_Template, 4, 11, "li", 0);
            } if (rf & 2) {
                i0__namespace.ɵɵproperty("ngForOf", ctx.nodes);
            } }, dependencies: [i2__namespace.NgClass, i2__namespace.NgForOf, i2__namespace.NgIf, i3__namespace.NavigationControlDirective, i4__namespace.TextContentDirective], encapsulation: 2 }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(BreadcrumbComponent, [{
            type: i0.Component,
            args: [{ selector: '[wmBreadcrumb]', providers: [
                        i4.provideAsWidgetRef(BreadcrumbComponent)
                    ], template: "<li *ngFor=\"let item of nodes; let last = last; let index = index\" [ngClass]=\"{active: last}\" class=\"{{item.class}}\">\n    <i class=\"{{item.icon}}\"></i>\n    <a [title]=\"item.label\" href=\"javascript:void(0)\" [wmNavigationControl]=\"item.link\" [disableMenuContext]=\"disableMenuContext || !!item.action\" (click)=\"onItemClick($event, item)\" *ngIf=\"!last\" [textContent]=\"item.label\"></a>\n    <a *ngIf=\"last\" [title]=\"item.label\" [textContent]=\"item.label\" href=\"javascript:void(0)\" class=\"text-muted\"\n       tabindex=\"0\" aria-current=\"page\"></a>\n</li>\n" }]
        }], () => [{ type: i0__namespace.Injector }, { type: i1__namespace.Router }, { type: i2__namespace.Location }, { type: undefined, decorators: [{
                    type: i0.Attribute,
                    args: ['beforenavigate.event']
                }] }, { type: undefined, decorators: [{
                    type: i0.Inject,
                    args: ['EXPLICIT_CONTEXT']
                }, {
                    type: i0.Optional
                }] }], null); })();
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassDebugInfo(BreadcrumbComponent, { className: "BreadcrumbComponent", filePath: "breadcrumb.component.ts", lineNumber: 20 }); })();

    const components = [
        BreadcrumbComponent
    ];
    class BreadcrumbModule {
        static { this.ɵfac = function BreadcrumbModule_Factory(t) { return new (t || BreadcrumbModule)(); }; }
        static { this.ɵmod = /*@__PURE__*/ i0__namespace.ɵɵdefineNgModule({ type: BreadcrumbModule }); }
        static { this.ɵinj = /*@__PURE__*/ i0__namespace.ɵɵdefineInjector({ imports: [i2.CommonModule,
                i3.MenuModule,
                i4.WmComponentsModule] }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(BreadcrumbModule, [{
            type: i0.NgModule,
            args: [{
                    imports: [
                        i2.CommonModule,
                        i3.MenuModule,
                        i4.WmComponentsModule
                    ],
                    declarations: [...components],
                    exports: [...components]
                }]
        }], null, null); })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(BreadcrumbModule, { declarations: [BreadcrumbComponent], imports: [i2.CommonModule,
            i3.MenuModule,
            i4.WmComponentsModule], exports: [BreadcrumbComponent] }); })();

    exports.BreadcrumbComponent = BreadcrumbComponent;
    exports.BreadcrumbModule = BreadcrumbModule;

}));
