import * as i0 from '@angular/core';
import { Component, Directive, NgModule } from '@angular/core';
import * as i1 from '@wm/core';
import { addClass } from '@wm/core';
import { provideAsWidgetRef, WmComponentsModule } from '@wm/components/base';
import * as i2 from 'ngx-bootstrap/modal';
import * as i4 from '@wm/components/page';
import * as i3 from '@wm/mobile/core';
import { remove } from 'lodash-es';
import { CommonModule } from '@angular/common';

const _c0 = ["wmPageContentLoader", ""];
class PageContentLoaderComponent {
    constructor(el) {
        addClass(el.nativeElement, 'app-page-content-loader');
    }
    static { this.ɵfac = function PageContentLoaderComponent_Factory(t) { return new (t || PageContentLoaderComponent)(i0.ɵɵdirectiveInject(i0.ElementRef)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: PageContentLoaderComponent, selectors: [["", "wmPageContentLoader", ""]], features: [i0.ɵɵProvidersFeature([
                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.ɵɵelement(0, "div", 0)(1, "div", 1);
        } }, encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PageContentLoaderComponent, [{
        type: Component,
        args: [{ selector: '[wmPageContentLoader]', providers: [
                    provideAsWidgetRef(PageContentLoaderComponent)
                ], template: "<div class=\"loader bg-primary\"></div>\n<div class=\"load-info\"></div>" }]
    }], () => [{ type: i0.ElementRef }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵ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 = [];
        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 && 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.ɵɵdirectiveInject(i1.App), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i2.BsModalService), i0.ɵɵdirectiveInject(i3.DeviceService), i0.ɵɵdirectiveInject(i4.PageDirective), i0.ɵɵdirectiveInject(i1.AbstractNavigationService)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: MobilePageDirective, selectors: [["", "wmPage", ""]] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MobilePageDirective, [{
        type: Directive,
        args: [{
                selector: '[wmPage]'
            }]
    }], () => [{ type: i1.App }, { type: i0.ElementRef }, { type: i2.BsModalService }, { type: i3.DeviceService }, { type: i4.PageDirective }, { type: i1.AbstractNavigationService }], null); })();

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

/**
 * Generated bundle index. Do not edit.
 */

export { MobilePageDirective, PageContentLoaderComponent, PageModule };
//# sourceMappingURL=index.mjs.map
