import * as i0 from '@angular/core';
import { TemplateRef, Component, Attribute, Inject, Optional, ViewChild, ContentChild, NgModule } from '@angular/core';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import { PROP_STRING, PROP_BOOLEAN, PROP_NUMBER, register, provideAsWidgetRef, provideAsDialogRef, WmComponentsModule } from '@wm/components/base';
import * as i3 from '@wm/components/dialogs';
import { BaseDialog, DialogModule } from '@wm/components/dialogs';
import * as i4 from '@wm/components/input';
import { InputModule } from '@wm/components/input';
import * as i1 from '@wm/core';
import { toBoolean } from '@wm/core';

const registerProps = () => {
    register('wm-partialdialog', new Map([
        ['animation', PROP_STRING],
        ['class', PROP_STRING],
        ['closable', { value: true, PROP_BOOLEAN }],
        ['content', PROP_STRING],
        ['iconclass', { value: 'wi wi-file', PROP_STRING }],
        ['iconheight', PROP_STRING],
        ['iconmargin', PROP_STRING],
        ['iconurl', PROP_STRING],
        ['iconwidth', PROP_STRING],
        ['modal', { value: false, ...PROP_BOOLEAN }],
        ['name', PROP_STRING],
        ['oktext', { value: 'OK', ...PROP_STRING }],
        ['showactions', { value: true, ...PROP_BOOLEAN }],
        ['tabindex', { value: 0, ...PROP_NUMBER }],
        ['headinglevel', { value: 'h4', ...PROP_STRING }],
        ['title', { value: 'Page Content', ...PROP_STRING }]
    ]));
};

const _c0 = ["partial"];
const _c1 = ["dialogTemplate"];
const _c2 = ["wmPartialDialog", ""];
function PartialDialogComponent_ng_template_0_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainer(0);
} }
function PartialDialogComponent_ng_template_0_div_3_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 5)(1, "button", 6);
    i0.ɵɵlistener("click", function PartialDialogComponent_ng_template_0_div_3_Template_button_click_1_listener($event) { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.onOk($event)); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵattribute("aria-label", ctx_r1.oktext);
} }
function PartialDialogComponent_ng_template_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "div", 1);
    i0.ɵɵelementStart(1, "div", 2);
    i0.ɵɵtemplate(2, PartialDialogComponent_ng_template_0_ng_container_2_Template, 1, 0, "ng-container", 3);
    i0.ɵɵelementEnd();
    i0.ɵɵtemplate(3, PartialDialogComponent_ng_template_0_div_3_Template, 2, 1, "div", 4);
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("closable", ctx_r1.closable)("iconclass", ctx_r1.iconclass)("iconurl", ctx_r1.iconurl)("iconwidth", ctx_r1.iconwidth)("iconheight", ctx_r1.iconheight)("iconmargin", ctx_r1.iconmargin)("heading", ctx_r1.title)("headinglevel", ctx_r1.headinglevel)("title", ctx_r1.title)("titleid", ctx_r1.titleId);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r1.dialogContent);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.showactions);
} }
const DIALOG_CLS = 'app-dialog modal-dialog app-page-dialog';
const WIDGET_INFO = { widgetType: 'wm-partialdialog' };
class PartialDialogComponent extends BaseDialog {
    static { this.initializeProps = registerProps(); }
    constructor(inj, app, dialogClass, modal, closable, explicitContext) {
        if (modal === null || modal === undefined) {
            modal = false;
        }
        if (closable === null || closable === undefined) {
            closable = true;
        }
        // setting the backdrop to 'static' will not close the dialog on backdrop click
        const backdrop = toBoolean(modal) ? 'static' : true;
        super(inj, WIDGET_INFO, {
            class: `${DIALOG_CLS} ${dialogClass || ''}`,
            backdrop,
            keyboard: !toBoolean(modal)
        }, explicitContext);
        this.app = app;
    }
    getTemplateRef() {
        return this.dialogTemplate;
    }
    /**
     * Click event handler for the ok button
     * invokes on-ok event callback
     * @param {Event} $event
     */
    onOk($event) {
        this.invokeEventCallback('ok', { $event });
    }
    ngOnInit() {
        super.ngOnInit();
        this.register(this.viewParent);
    }
    setPartialLoadListener() {
        const cancelSubscription = this.app.subscribe('partialLoaded', () => {
            const parEle = this.partialRef.nativeElement;
            let partialScope;
            if (parEle) {
                partialScope = parEle.widget;
                this.Widgets = partialScope.Widgets;
                this.Variables = partialScope.Variables;
                this.Actions = partialScope.Actions;
            }
            cancelSubscription();
        });
    }
    open(initState) {
        super.open(initState);
        // WMS-19410 - Set the partial load listener to access widgets, variables and actions of page dialog
        this.setPartialLoadListener();
    }
    static { this.ɵfac = function PartialDialogComponent_Factory(t) { return new (t || PartialDialogComponent)(i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i1.App), i0.ɵɵinjectAttribute('class'), i0.ɵɵinjectAttribute('modal'), i0.ɵɵinjectAttribute('closable'), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: PartialDialogComponent, selectors: [["div", "wmPartialDialog", ""]], contentQueries: function PartialDialogComponent_ContentQueries(rf, ctx, dirIndex) { if (rf & 1) {
            i0.ɵɵcontentQuery(dirIndex, TemplateRef, 5);
            i0.ɵɵcontentQuery(dirIndex, _c0, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.dialogContent = _t.first);
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.partialRef = _t.first);
        } }, viewQuery: function PartialDialogComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c1, 7);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.dialogTemplate = _t.first);
        } }, features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(PartialDialogComponent),
                provideAsDialogRef(PartialDialogComponent)
            ]), i0.ɵɵInheritDefinitionFeature], attrs: _c2, decls: 2, vars: 0, consts: [["dialogTemplate", ""], ["wmDialogHeader", "", 3, "closable", "iconclass", "iconurl", "iconwidth", "iconheight", "iconmargin", "heading", "headinglevel", "title", "titleid"], ["wmDialogBody", ""], [4, "ngTemplateOutlet"], ["wmDialogFooter", "", 4, "ngIf"], ["wmDialogFooter", ""], ["caption.bind", "oktext", "wmButton", "", 1, "btn-primary", "ok-action", 3, "click"]], template: function PartialDialogComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵtemplate(0, PartialDialogComponent_ng_template_0_Template, 4, 12, "ng-template", null, 0, i0.ɵɵtemplateRefExtractor);
        } }, dependencies: [i2.NgIf, i2.NgTemplateOutlet, i3.DialogBodyDirective, i3.DialogFooterDirective, i3.DialogHeaderComponent, i4.ButtonComponent], encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PartialDialogComponent, [{
        type: Component,
        args: [{ selector: 'div[wmPartialDialog]', providers: [
                    provideAsWidgetRef(PartialDialogComponent),
                    provideAsDialogRef(PartialDialogComponent)
                ], template: "<ng-template #dialogTemplate>\n    <div wmDialogHeader [closable]=\"closable\"\n         [iconclass]=\"iconclass\"\n         [iconurl]=\"iconurl\"\n         [iconwidth]=\"iconwidth\"\n         [iconheight]=\"iconheight\"\n         [iconmargin]=\"iconmargin\"\n         [heading]=\"title\"\n         [headinglevel]=\"headinglevel\"\n         [title]=\"title\"\n         [titleid]=\"titleId\"\n    ></div>\n    <div wmDialogBody>\n        <ng-container *ngTemplateOutlet=\"dialogContent\"></ng-container>\n    </div>\n    <div wmDialogFooter *ngIf=\"showactions\">\n        <button (click)=\"onOk($event)\" [attr.aria-label]=\"oktext\" caption.bind=\"oktext\" class=\"btn-primary ok-action\"\n                wmButton></button>\n    </div>\n</ng-template>\n" }]
    }], () => [{ type: i0.Injector }, { type: i1.App }, { type: undefined, decorators: [{
                type: Attribute,
                args: ['class']
            }] }, { type: undefined, decorators: [{
                type: Attribute,
                args: ['modal']
            }] }, { type: undefined, decorators: [{
                type: Attribute,
                args: ['closable']
            }] }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], { dialogTemplate: [{
            type: ViewChild,
            args: ['dialogTemplate', { static: true }]
        }], dialogContent: [{
            type: ContentChild,
            args: [TemplateRef]
        }], partialRef: [{
            type: ContentChild,
            args: ['partial']
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(PartialDialogComponent, { className: "PartialDialogComponent", filePath: "partial-dialog.component.ts", lineNumber: 31 }); })();

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

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

export { PartialDialogComponent, PartialDialogModule };
//# sourceMappingURL=index.mjs.map
