import * as i0 from '@angular/core';
import { Directive, Inject, Optional, Component, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PROP_BOOLEAN, PROP_STRING, register, StylableComponent, updateDeviceView, provideAsWidgetRef, styler, PROP_NUMBER, APPLY_STYLES_TYPE, PullToRefresh, WmComponentsModule } from '@wm/components/base';
import * as i1 from '@angular/platform-browser';
import * as i2 from '@wm/core';
import { EventNotifier, isMobileApp, switchClass } from '@wm/core';

const registerProps$5 = () => {
    register('wm-page', new Map([
        ['cache', { value: false, ...PROP_BOOLEAN }],
        ['refreshdataonattach', { value: true, ...PROP_BOOLEAN }],
        ['pagetitle', PROP_STRING],
        ['hint', PROP_STRING],
        ['arialabel', PROP_STRING]
    ]));
};

const DEFAULT_CLS$5 = 'app-page container';
const WIDGET_CONFIG$5 = { widgetType: 'wm-page', hostClass: DEFAULT_CLS$5 };
class PageDirective extends StylableComponent {
    static { this.initializeProps = registerProps$5(); }
    onPropertyChange(key, nv, ov) {
        if (key === 'pagetitle') {
            this.titleService.setTitle(nv);
        }
        else {
            super.onPropertyChange(key, nv, ov);
        }
    }
    constructor(inj, titleService, viewport, explicitContext) {
        super(inj, WIDGET_CONFIG$5, explicitContext);
        this.titleService = titleService;
        this.viewport = viewport;
        this._eventNotifier = new EventNotifier(false);
        this.refreshdataonattach = true;
    }
    /**
     * A child component can notify page using this method. Notified event will be passed to
     * subscribed children only after page initialization.
     *
     * @param {string} eventName
     * @param data
     */
    notify(eventName, ...data) {
        this._eventNotifier.notify.apply(this._eventNotifier, arguments);
    }
    /**
     * The main purpose of this function is to provide communication between page children objects.
     * Child component can subscribe for an event that will be emitted by another child component.
     *
     * @param eventName
     * @param {(data: any) => void} callback
     * @returns {any}
     */
    subscribe(eventName, callback) {
        return this._eventNotifier.subscribe(eventName, callback);
    }
    ngAfterViewInit() {
        setTimeout(() => {
            this._eventNotifier.start();
            updateDeviceView(this.nativeElement, this.getAppInstance().isTabletApplicationType);
        }, 1);
        this.registerDestroyListener(this.viewport.subscribe("resize" /* ViewportEvent.RESIZE */, args => {
            this.invokeEventCallback('resize', { $event: args.$event, widget: this, data: args.data });
        }));
        this.registerDestroyListener(this.viewport.subscribe("orientationchange" /* ViewportEvent.ORIENTATION_CHANGE */, args => {
            this.invokeEventCallback('orientationchange', { $event: args.$event, widget: this, data: args.data });
        }));
    }
    ngOnAttach() {
        this.titleService.setTitle(this.pagetitle);
        this.invokeEventCallback('attach', { widget: this });
        this.notify('attach', {
            refreshData: this.refreshdataonattach
        });
    }
    ngOnDetach() {
        this.invokeEventCallback('detach', { widget: this });
        this.notify('detach');
    }
    ngOnDestroy() {
        this.invokeEventCallback('destroy', { widget: this });
        this._eventNotifier.destroy();
    }
    static { this.ɵfac = function PageDirective_Factory(t) { return new (t || PageDirective)(i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i1.Title), i0.ɵɵdirectiveInject(i2.Viewport), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: PageDirective, selectors: [["", "wmPage", ""]], exportAs: ["wmPage"], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(PageDirective)
            ]), i0.ɵɵInheritDefinitionFeature] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PageDirective, [{
        type: Directive,
        args: [{
                selector: '[wmPage]',
                providers: [
                    provideAsWidgetRef(PageDirective)
                ],
                exportAs: 'wmPage'
            }]
    }], () => [{ type: i0.Injector }, { type: i1.Title }, { type: i2.Viewport }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], null); })();

const registerProps$4 = () => {
    register('wm-content', new Map([
        ['name', PROP_STRING],
        ['class', PROP_STRING]
    ]));
};

const _c0$1 = ["wmContent", ""];
const _c1$1 = ["*"];
const DEFAULT_CLS$4 = 'app-content clearfix';
const WIDGET_CONFIG$4 = { widgetType: 'wm-content', hostClass: DEFAULT_CLS$4 };
class ContentComponent extends StylableComponent {
    static { this.initializeProps = registerProps$4(); }
    constructor(inj, explicitContext) {
        super(inj, WIDGET_CONFIG$4, explicitContext);
        styler(this.nativeElement, this);
    }
    static { this.ɵfac = function ContentComponent_Factory(t) { return new (t || ContentComponent)(i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ContentComponent, selectors: [["", "wmContent", ""]], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(ContentComponent)
            ]), i0.ɵɵInheritDefinitionFeature], attrs: _c0$1, ngContentSelectors: _c1$1, decls: 2, vars: 0, consts: [[1, "row", "app-content-row", "clearfix"]], template: function ContentComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵprojectionDef();
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵprojection(1);
            i0.ɵɵelementEnd();
        } }, encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ContentComponent, [{
        type: Component,
        args: [{ selector: '[wmContent]', providers: [
                    provideAsWidgetRef(ContentComponent)
                ], template: "<div class=\"row app-content-row clearfix\">\n    <ng-content></ng-content>\n</div>" }]
    }], () => [{ type: i0.Injector }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ContentComponent, { className: "ContentComponent", filePath: "content/content.component.ts", lineNumber: 17 }); })();

const registerProps$3 = () => {
    register('wm-page-content', new Map([
        ['class', PROP_STRING],
        ['columnwidth', PROP_NUMBER],
        ['content', PROP_STRING],
        ['name', PROP_STRING],
        ['pulltorefresh', { value: isMobileApp(), ...PROP_BOOLEAN }]
    ]));
};

const _c0 = ["wmPageContent", ""];
const _c1 = ["*"];
const DEFAULT_CLS$3 = 'app-page-content app-content-column';
const WIDGET_CONFIG$3 = { widgetType: 'wm-page-content', hostClass: DEFAULT_CLS$3 };
class PageContentComponent extends StylableComponent {
    static { this.initializeProps = registerProps$3(); }
    constructor(inj, app, explicitContext) {
        super(inj, WIDGET_CONFIG$3, explicitContext);
        this.app = app;
        styler(this.nativeElement, this, APPLY_STYLES_TYPE.CONTAINER);
        this.registerDestroyListener(this.app.subscribe('pullToRefresh:enable', () => {
            this.childPullToRefresh = true;
            this.initPullToRefresh();
        }));
    }
    onPropertyChange(key, nv, ov) {
        if (key === 'columnwidth') {
            switchClass(this.nativeElement, `col-md-${nv} col-sm-${nv}`, `col-md-${ov} col-sm-${ov}`);
        }
        else if (key === 'pulltorefresh' && nv) {
            // creating instance after timeout as the smoothscroll styles where getting added on pull refresh-container
            setTimeout(() => {
                this.initPullToRefresh();
            });
        }
        else {
            super.onPropertyChange(key, nv, ov);
        }
    }
    // when list component is ready, pulltorefresh instance is created and this appends pullToRefresh element on the page content.
    initPullToRefresh() {
        const hasPullToRefreshEvent = this.hasEventCallback('pulltorefresh');
        if (!this.pullToRefreshIns && (this.childPullToRefresh || hasPullToRefreshEvent) && this.pulltorefresh) {
            this.pullToRefreshIns = new PullToRefresh($(this.nativeElement), this.app, () => {
                if (hasPullToRefreshEvent) {
                    this.invokeEventCallback('pulltorefresh');
                }
                else {
                    this.app.notify('pulltorefresh');
                }
            });
            this.registerDestroyListener(() => {
                if (this.pullToRefreshIns.cancelSubscription) {
                    this.pullToRefreshIns.cancelSubscription();
                }
            });
        }
    }
    static { this.ɵfac = function PageContentComponent_Factory(t) { return new (t || PageContentComponent)(i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i2.App), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: PageContentComponent, selectors: [["", "wmPageContent", ""]], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(PageContentComponent)
            ]), i0.ɵɵInheritDefinitionFeature], attrs: _c0, ngContentSelectors: _c1, decls: 1, vars: 0, template: function PageContentComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵprojectionDef();
            i0.ɵɵprojection(0);
        } }, encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PageContentComponent, [{
        type: Component,
        args: [{ selector: '[wmPageContent]', providers: [
                    provideAsWidgetRef(PageContentComponent)
                ], template: "<ng-content></ng-content>" }]
    }], () => [{ type: i0.Injector }, { type: i2.App }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(PageContentComponent, { className: "PageContentComponent", filePath: "page-content/page-content.component.ts", lineNumber: 18 }); })();

const registerProps$2 = () => {
    register('wm-spa-page', new Map([
        ['cache', { value: false, ...PROP_BOOLEAN }],
        ['refreshdataonattach', { value: true, ...PROP_BOOLEAN }],
        ['pagetitle', PROP_STRING],
        ['hint', PROP_STRING]
    ]));
};

const DEFAULT_CLS$2 = 'app-spa-page';
const WIDGET_CONFIG$2 = { widgetType: 'wm-spa-page', hostClass: DEFAULT_CLS$2 };
class SpaPageDirective extends StylableComponent {
    static { this.initializeProps = registerProps$2(); }
    onPropertyChange(key, nv, ov) {
        if (key === 'pagetitle') {
            this.titleService.setTitle(nv);
        }
        else {
            super.onPropertyChange(key, nv, ov);
        }
    }
    constructor(inj, titleService, viewport, explicitContext) {
        super(inj, WIDGET_CONFIG$2, explicitContext);
        this.titleService = titleService;
        this.viewport = viewport;
        this._eventNotifier = new EventNotifier(false);
        this.refreshdataonattach = true;
    }
    /**
     * A child component can notify page using this method. Notified event will be passed to
     * subscribed children only after page initialization.
     *
     * @param {string} eventName
     * @param data
     */
    notify(eventName, ...data) {
        this._eventNotifier.notify.apply(this._eventNotifier, arguments);
    }
    /**
     * The main purpose of this function is to provide communication between page children objects.
     * Child component can subscribe for an event that will be emitted by another child component.
     *
     * @param eventName
     * @param {(data: any) => void} callback
     * @returns {any}
     */
    subscribe(eventName, callback) {
        return this._eventNotifier.subscribe(eventName, callback);
    }
    ngAfterViewInit() {
        setTimeout(() => {
            this._eventNotifier.start();
            updateDeviceView(this.nativeElement, this.getAppInstance().isTabletApplicationType);
        }, 1);
        this.registerDestroyListener(this.viewport.subscribe("resize" /* ViewportEvent.RESIZE */, args => {
            this.invokeEventCallback('resize', { $event: args.$event, widget: this, data: args.data });
        }));
        this.registerDestroyListener(this.viewport.subscribe("orientationchange" /* ViewportEvent.ORIENTATION_CHANGE */, args => {
            this.invokeEventCallback('orientationchange', { $event: args.$event, widget: this, data: args.data });
        }));
    }
    ngOnAttach() {
        this.titleService.setTitle(this.pagetitle);
        this.invokeEventCallback('attach', { widget: this });
        this.notify('attach', {
            refreshData: this.refreshdataonattach
        });
    }
    ngOnDetach() {
        this.invokeEventCallback('detach', { widget: this });
        this.notify('detach');
    }
    ngOnDestroy() {
        this.invokeEventCallback('destroy', { widget: this });
        this._eventNotifier.destroy();
    }
    static { this.ɵfac = function SpaPageDirective_Factory(t) { return new (t || SpaPageDirective)(i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i1.Title), i0.ɵɵdirectiveInject(i2.Viewport), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: SpaPageDirective, selectors: [["", "wmSpaPage", ""]], exportAs: ["wmSpaPage"], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(SpaPageDirective)
            ]), i0.ɵɵInheritDefinitionFeature] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SpaPageDirective, [{
        type: Directive,
        args: [{
                selector: '[wmSpaPage]',
                providers: [
                    provideAsWidgetRef(SpaPageDirective)
                ],
                exportAs: 'wmSpaPage'
            }]
    }], () => [{ type: i0.Injector }, { type: i1.Title }, { type: i2.Viewport }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], null); })();

const registerProps$1 = () => {
    register('wm-layout', new Map([]));
};

const DEFAULT_CLS$1 = 'app-page container';
const WIDGET_CONFIG$1 = { widgetType: 'wm-layout', hostClass: DEFAULT_CLS$1 };
class LayoutDirective extends StylableComponent {
    static { this.initializeProps = registerProps$1(); }
    constructor(inj, explicitContext) {
        super(inj, WIDGET_CONFIG$1, explicitContext);
        this._eventNotifier = new EventNotifier(false);
    }
    /**
     * A child component can notify page using this method. Notified event will be passed to
     * subscribed children only after page initialization.
     *
     * @param {string} eventName
     * @param data
     */
    notify(eventName, ...data) {
        this._eventNotifier.notify.apply(this._eventNotifier, arguments);
    }
    ngAfterViewInit() {
        setTimeout(() => {
            updateDeviceView(this.nativeElement, this.getAppInstance().isTabletApplicationType);
        }, 1);
    }
    static { this.ɵfac = function LayoutDirective_Factory(t) { return new (t || LayoutDirective)(i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: LayoutDirective, selectors: [["", "wmLayout", ""]], exportAs: ["wmLayout"], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(LayoutDirective)
            ]), i0.ɵɵInheritDefinitionFeature] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(LayoutDirective, [{
        type: Directive,
        args: [{
                selector: '[wmLayout]',
                providers: [
                    provideAsWidgetRef(LayoutDirective)
                ],
                exportAs: 'wmLayout'
            }]
    }], () => [{ type: i0.Injector }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], null); })();

const registerProps = () => {
    register('wm-router-outlet', new Map([
        ['columnwidth', PROP_NUMBER],
        ['name', PROP_STRING]
    ]));
};

const DEFAULT_CLS = 'app-content-column-wrapper';
const WIDGET_CONFIG = {
    widgetType: 'wm-router-outlet',
    hostClass: DEFAULT_CLS
};
class RouterOutletDirective extends StylableComponent {
    static { this.initializeProps = registerProps(); }
    constructor(inj, explicitContext) {
        super(inj, WIDGET_CONFIG, explicitContext);
    }
    onPropertyChange(key, nv, ov) {
        if (key === 'columnwidth') {
            switchClass(this.nativeElement, `col-md-${nv} col-sm-${nv}`, `col-md-${ov} col-sm-${ov}`);
        }
        else {
            super.onPropertyChange(key, nv, ov);
        }
    }
    static { this.ɵfac = function RouterOutletDirective_Factory(t) { return new (t || RouterOutletDirective)(i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: RouterOutletDirective, selectors: [["", "wmRouterOutlet", ""]], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(RouterOutletDirective)
            ]), i0.ɵɵInheritDefinitionFeature] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(RouterOutletDirective, [{
        type: Directive,
        args: [{
                selector: '[wmRouterOutlet]',
                providers: [
                    provideAsWidgetRef(RouterOutletDirective)
                ]
            }]
    }], () => [{ type: i0.Injector }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], null); })();

const components = [
    PageDirective,
    LayoutDirective,
    ContentComponent,
    PageContentComponent,
    SpaPageDirective,
    RouterOutletDirective
];
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({ providers: [
            PageDirective,
            SpaPageDirective
        ], imports: [CommonModule,
            WmComponentsModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PageModule, [{
        type: NgModule,
        args: [{
                imports: [
                    CommonModule,
                    WmComponentsModule
                ],
                declarations: [...components],
                exports: [...components],
                providers: [
                    PageDirective,
                    SpaPageDirective
                ]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(PageModule, { declarations: [PageDirective,
        LayoutDirective,
        ContentComponent,
        PageContentComponent,
        SpaPageDirective,
        RouterOutletDirective], imports: [CommonModule,
        WmComponentsModule], exports: [PageDirective,
        LayoutDirective,
        ContentComponent,
        PageContentComponent,
        SpaPageDirective,
        RouterOutletDirective] }); })();

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

export { ContentComponent, LayoutDirective, PageContentComponent, PageDirective, PageModule, RouterOutletDirective, SpaPageDirective };
//# sourceMappingURL=index.mjs.map
