(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@wm/core'), require('@wm/components/base'), require('ngx-bootstrap/modal'), require('@wm/components/page'), require('@wm/mobile/core'), require('lodash-es'), require('@angular/common')) :
    typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@wm/core', '@wm/components/base', 'ngx-bootstrap/modal', '@wm/components/page', '@wm/mobile/core', 'lodash-es', '@angular/common'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.wm = global.wm || {}, global.wm.mobile = global.wm.mobile || {}, global.wm.mobile.components = global.wm.mobile.components || {}, global.wm.mobile.components.page = {}), global.ng.core, global.wm.core, global.wm.components.base, global.modal, global.wm.components.page, global.wm.mobile.core, global._, global.ng.common));
})(this, (function (exports, i0, i1, base, i2, i4, i3, lodashEs, common) { '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 i1__namespace = /*#__PURE__*/_interopNamespaceDefault(i1);
    var i2__namespace = /*#__PURE__*/_interopNamespaceDefault(i2);
    var i4__namespace = /*#__PURE__*/_interopNamespaceDefault(i4);
    var i3__namespace = /*#__PURE__*/_interopNamespaceDefault(i3);

    const _c0 = ["wmPageContentLoader", ""];
    class PageContentLoaderComponent {
        constructor(el) {
            i1.addClass(el.nativeElement, 'app-page-content-loader');
        }
        static { this.ɵfac = function PageContentLoaderComponent_Factory(t) { return new (t || PageContentLoaderComponent)(i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef)); }; }
        static { this.ɵcmp = /*@__PURE__*/ i0__namespace.ɵɵdefineComponent({ type: PageContentLoaderComponent, selectors: [["", "wmPageContentLoader", ""]], features: [i0__namespace.ɵɵProvidersFeature([
                    base.provideAsWidgetRef(PageContentLoaderComponent)
                ])], attrs: _c0, decls: 2, vars: 0, consts: [[1, "loader", "bg-primary"], [1, "load-info"]], template: function PageContentLoaderComponent_Template(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵelement(0, "div", 0)(1, "div", 1);
            } }, encapsulation: 2 }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(PageContentLoaderComponent, [{
            type: i0.Component,
            args: [{ selector: '[wmPageContentLoader]', providers: [
                        base.provideAsWidgetRef(PageContentLoaderComponent)
                    ], template: "<div class=\"loader bg-primary\"></div>\n<div class=\"load-info\"></div>" }]
        }], () => [{ type: i0__namespace.ElementRef }], null); })();
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassDebugInfo(PageContentLoaderComponent, { className: "PageContentLoaderComponent", filePath: "page-content-loader/page-content-loader.component.ts", lineNumber: 13 }); })();

    class MobilePageDirective {
        constructor(app, elRef, modalService, deviceService, page, navigationService) {
            this.modalService = modalService;
            this.deviceService = deviceService;
            this.page = page;
            this.navigationService = navigationService;
            this.subscriptions = [];
            i1.addClass(elRef.nativeElement, 'mobile-app-page');
            this._$ele = $(elRef.nativeElement);
            page.subscribe('wmMobileTabbar:ready', () => this._$ele.addClass('has-tabbar'));
            let modalsOpened = [];
            this.subscriptions = [
                modalService.onShown.subscribe(({ id }) => {
                    id && modalsOpened.push(id);
                }),
                modalService.onHidden.subscribe(({ id }) => {
                    id && lodashEs.remove(modalsOpened, id);
                })
            ];
            // add backbutton listener on every page.
            this._backBtnListenerDestroyer = deviceService.onBackButtonTap($event => {
                if (modalsOpened.length > 0) {
                    modalService.hide(modalsOpened.pop());
                }
                else if (app.landingPageName === app.activePageName) {
                    window.navigator['app'].exitApp();
                }
                else {
                    this.navigationService.goToPrevious();
                }
                return false;
            });
        }
        ngOnDestroy() {
            this.subscriptions.map((s) => s.unsubscribe());
            this._backBtnListenerDestroyer();
        }
        static { this.ɵfac = function MobilePageDirective_Factory(t) { return new (t || MobilePageDirective)(i0__namespace.ɵɵdirectiveInject(i1__namespace.App), i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(i2__namespace.BsModalService), i0__namespace.ɵɵdirectiveInject(i3__namespace.DeviceService), i0__namespace.ɵɵdirectiveInject(i4__namespace.PageDirective), i0__namespace.ɵɵdirectiveInject(i1__namespace.AbstractNavigationService)); }; }
        static { this.ɵdir = /*@__PURE__*/ i0__namespace.ɵɵdefineDirective({ type: MobilePageDirective, selectors: [["", "wmPage", ""]] }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(MobilePageDirective, [{
            type: i0.Directive,
            args: [{
                    selector: '[wmPage]'
                }]
        }], () => [{ type: i1__namespace.App }, { type: i0__namespace.ElementRef }, { type: i2__namespace.BsModalService }, { type: i3__namespace.DeviceService }, { type: i4__namespace.PageDirective }, { type: i1__namespace.AbstractNavigationService }], null); })();

    const components = [
        MobilePageDirective,
        PageContentLoaderComponent
    ];
    class PageModule {
        static { this.ɵfac = function PageModule_Factory(t) { return new (t || PageModule)(); }; }
        static { this.ɵmod = /*@__PURE__*/ i0__namespace.ɵɵdefineNgModule({ type: PageModule }); }
        static { this.ɵinj = /*@__PURE__*/ i0__namespace.ɵɵdefineInjector({ imports: [common.CommonModule,
                base.WmComponentsModule] }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(PageModule, [{
            type: i0.NgModule,
            args: [{
                    imports: [
                        common.CommonModule,
                        base.WmComponentsModule
                    ],
                    declarations: [...components],
                    exports: [...components]
                }]
        }], null, null); })();
    (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(PageModule, { declarations: [MobilePageDirective,
            PageContentLoaderComponent], imports: [common.CommonModule,
            base.WmComponentsModule], exports: [MobilePageDirective,
            PageContentLoaderComponent] }); })();

    exports.MobilePageDirective = MobilePageDirective;
    exports.PageContentLoaderComponent = PageContentLoaderComponent;
    exports.PageModule = PageModule;

}));
