import * as i5$1 from '@angular/cdk/drag-drop';
import { DragDropModule } from '@angular/cdk/drag-drop';
import * as i6$1 from '@angular/cdk/portal';
import { ComponentPortal, PortalModule } from '@angular/cdk/portal';
import * as i6 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Directive, EventEmitter, Component, Output, Input, ViewEncapsulation, Inject, ChangeDetectionStrategy, HostListener, Injectable, NgModule } from '@angular/core';
import * as i1$1 from '@angular/material/button';
import { MatButtonModule } from '@angular/material/button';
import * as i1$2 from '@angular/material/dialog';
import { MatDialogConfig, MAT_DIALOG_DATA, MatDialog, MatDialogModule } from '@angular/material/dialog';
import * as i2 from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';
import * as i1 from '@angular/material/toolbar';
import { MatToolbarModule } from '@angular/material/toolbar';
import * as i5 from '@angular/material/tooltip';
import { MatTooltipModule } from '@angular/material/tooltip';
import * as i5$2 from '@deja-js/component/overlay';
import { DejaOverlayModule } from '@deja-js/component/overlay';
import { Destroy } from '@deja-js/component/core';
import { take, tap, takeUntil, filter, timer, BehaviorSubject, map, from, switchMap, debounceTime } from 'rxjs';
import * as i2$1 from '@angular/platform-browser';

class DejaPopupAction {
    constructor(name, target) {
        this.name = name;
        this.target = target;
        this.refreshDrawer = true;
        this.isFinalAction = false;
        if (!this.icon) {
            this.icon = name;
        }
        if (!this.label) {
            this.label = name;
        }
    }
}
class DejaPopupButton extends DejaPopupAction {
    constructor(name, label, icon, isFinalAction = true) {
        super(name);
        this.name = name;
        this.label = label;
        this.icon = icon;
        this.isFinalAction = isFinalAction;
    }
}
class DejaPopupCustomAction extends DejaPopupAction {
    constructor(portal) {
        super(undefined);
        this.portal = portal;
    }
}

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
// eslint-disable-next-line @angular-eslint/directive-class-suffix
class DejaPopupBase extends Destroy {
    constructor() {
        super(...arguments);
        this.isMinified = false;
        this.isFullscreen = false;
    }
    ngOnInit() {
        this.aSub = [];
        this.dialogRef.beforeClosed().pipe(take(1), tap(() => {
            if (this.unlisten) {
                this.unlisten();
            }
            this.destroy();
            if (this.config.dejaPopupCom$) {
                const action = new DejaPopupAction('dialog-close', 'popup-tray');
                this.config.dejaPopupCom$.next(action);
            }
        }), takeUntil(this.destroyed$)).subscribe();
        if (this.config.actionComponentRef) {
            this.actionsPortal = new ComponentPortal(this.config.actionComponentRef, undefined, this.injector);
        }
        if (this.config.dejaPopupCom$) {
            this.aSub.push(this.config.dejaPopupCom$.pipe(filter(a => !!a?.target && a.target === this.config.id), tap(a => this.doAction(a)), tap(action => {
                this.actionSelected = action;
                if (action.isFinalAction) {
                    this.dialogRef.close(action);
                }
            }), takeUntil(this.destroyed$)).subscribe());
        }
    }
    dispatchAction(action) {
        if (!action) {
            return false;
        }
        this.config?.dejaPopupCom$?.next(action);
        return undefined;
    }
    destroy() {
        this.aSub.forEach(s => s.unsubscribe());
    }
}
DejaPopupBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupBase, deps: null, target: i0.ɵɵFactoryTarget.Directive });
DejaPopupBase.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.1", type: DejaPopupBase, usesInheritance: true, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupBase, decorators: [{
            type: Directive
        }] });

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
class DejaPopupToolbarComponent {
    constructor() {
        this.actionSelected = new EventEmitter();
        this.buttonClose = {
            name: 'toolbar-close',
            icon: 'close',
            label: 'Close'
        };
        this.buttonFullscreen = {
            name: 'toolbar-fullscreen',
            icon: 'fullscreen',
            label: 'Fullscreen'
        };
        this.buttonFullscreenExit = {
            name: 'toolbar-fullscreen-exit',
            icon: 'fullscreen_exit',
            label: 'Exit fullscreen'
        };
        this.buttonMinimize = {
            name: 'toolbar-minify',
            icon: 'remove',
            label: 'Dock'
        };
        this.defaultActions = [this.buttonClose];
    }
    set config(conf) {
        this.color = conf.toolbarColor;
        this.title = conf.title;
        this.iconName = conf.toolbarIconName;
        this.type = conf.toolbarType;
        this.actions = conf.toolbarActions;
        this.dialogId = conf.id;
        this.isFullScreen = conf.fullscreen;
        if (!conf.fullscreen) {
            this.defaultActions.unshift(this.buttonFullscreen);
        }
        else if (conf.buttonFullscreenExit ?? true) {
            this.defaultActions.unshift(this.buttonFullscreenExit);
        }
        if (!conf.hasBackdrop) {
            this.defaultActions.unshift(this.buttonMinimize);
        }
    }
    doEmit(action, event) {
        if (action.name === this.buttonFullscreen.name || action.name === this.buttonFullscreenExit.name) {
            this.toggleFullScreenButton();
        }
        action.target = this.dialogId;
        this.actionSelected.emit(action);
        if (event) {
            event.stopPropagation();
            event.preventDefault();
        }
    }
    toggleFullScreenButton() {
        this.isFullScreen = !this.isFullScreen;
        let formerButton;
        let newButton;
        if (this.isFullScreen) {
            formerButton = this.buttonFullscreen;
            newButton = this.buttonFullscreenExit;
        }
        else {
            formerButton = this.buttonFullscreenExit;
            newButton = this.buttonFullscreen;
        }
        const idx = this.defaultActions.findIndex((a) => a.name === formerButton.name);
        if (idx === -1) {
            return false;
        }
        this.defaultActions.splice(idx, 1, newButton);
        return undefined;
    }
}
DejaPopupToolbarComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupToolbarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
DejaPopupToolbarComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: DejaPopupToolbarComponent, selector: "deja-popup-toolbar", inputs: { config: "config" }, outputs: { actionSelected: "actionSelected" }, ngImport: i0, template: "<div tabindex=\"0\"></div>\n\n<mat-toolbar *ngIf=\"!type || type==='base'\" [color]=\"color\" class=\"deja-popup-toolbar\">\n    <mat-icon *ngIf=\"iconName\">{{ iconName }}</mat-icon>\n    <span>{{ title }}</span>\n</mat-toolbar>\n\n<mat-toolbar *ngIf=\"type && type==='window'\" [color]=\"color\" class=\"deja-popup-toolbar-mini\">\n    <span class=\"deja-popup-toolbar-spacer deja-popup-toolbar-content\">\n        <mat-icon *ngIf=\"iconName\">{{ iconName }}</mat-icon>\n        <span>{{ title }}</span>\n    </span>\n\n    <span class=\"deja-popup-toolbar-actions deja-popup-toolbar-content\">\n        <ng-container *ngFor=\"let action of actions\">\n            <button *ngIf=\"!action.portal; else portalTpl\" type=\"button\" mat-icon-button (click)=\"doEmit(action, $event)\">\n                <mat-icon aria-label=\"action.name\" [matTooltip]=\"action.label\">{{ action.icon }}</mat-icon>\n            </button>\n            <ng-template #portalTpl>\n                <ng-template [cdkPortalOutlet]=\"action.portal\"></ng-template>\n            </ng-template>\n        </ng-container>\n    </span>\n\n    <span class=\"deja-popup-toolbar-actions deja-popup-toolbar-content\">\n        <ng-container *ngFor=\"let action of defaultActions\">\n            <button type=\"button\" mat-icon-button (click)=\"doEmit(action, $event)\">\n                <mat-icon aria-label=\"action.name\">{{ action.icon }}</mat-icon>\n            </button>\n        </ng-container>\n    </span>\n</mat-toolbar>\n", styles: [".deja-popup-toolbar>.mat-icon{margin-right:4px}.deja-popup-toolbar-mini{display:flex;height:auto}.deja-popup-toolbar-mini .deja-popup-toolbar-content{font-size:12px}.deja-popup-toolbar-mini .deja-popup-toolbar-content button,.deja-popup-toolbar-mini .deja-popup-toolbar-content .mat-icon{width:18px;height:18px;line-height:18px}.deja-popup-toolbar-mini .deja-popup-toolbar-content button{margin-left:4px}.deja-popup-toolbar-mini .deja-popup-toolbar-content .mat-icon{font-size:18px}.deja-popup-toolbar-mini .deja-popup-toolbar-spacer{flex:1;cursor:grab}.deja-popup-toolbar-mini .deja-popup-toolbar-spacer .mat-icon{vertical-align:sub;margin-right:4px}.deja-popup-toolbar-mini .deja-popup-toolbar-actions{padding-left:1rem}.deja-popup-toolbar-mini .deja-popup-toolbar-actions~.deja-popup-toolbar-actions{padding-left:0}.deja-popup-toolbar-mini .actions-hide{display:none}\n"], components: [{ type: i1.MatToolbar, selector: "mat-toolbar", inputs: ["color"], exportAs: ["matToolbar"] }, { type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { type: i1$1.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button],             button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],             button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i6.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i5.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { type: i6$1.CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupToolbarComponent, decorators: [{
            type: Component,
            args: [{ selector: 'deja-popup-toolbar', template: "<div tabindex=\"0\"></div>\n\n<mat-toolbar *ngIf=\"!type || type==='base'\" [color]=\"color\" class=\"deja-popup-toolbar\">\n    <mat-icon *ngIf=\"iconName\">{{ iconName }}</mat-icon>\n    <span>{{ title }}</span>\n</mat-toolbar>\n\n<mat-toolbar *ngIf=\"type && type==='window'\" [color]=\"color\" class=\"deja-popup-toolbar-mini\">\n    <span class=\"deja-popup-toolbar-spacer deja-popup-toolbar-content\">\n        <mat-icon *ngIf=\"iconName\">{{ iconName }}</mat-icon>\n        <span>{{ title }}</span>\n    </span>\n\n    <span class=\"deja-popup-toolbar-actions deja-popup-toolbar-content\">\n        <ng-container *ngFor=\"let action of actions\">\n            <button *ngIf=\"!action.portal; else portalTpl\" type=\"button\" mat-icon-button (click)=\"doEmit(action, $event)\">\n                <mat-icon aria-label=\"action.name\" [matTooltip]=\"action.label\">{{ action.icon }}</mat-icon>\n            </button>\n            <ng-template #portalTpl>\n                <ng-template [cdkPortalOutlet]=\"action.portal\"></ng-template>\n            </ng-template>\n        </ng-container>\n    </span>\n\n    <span class=\"deja-popup-toolbar-actions deja-popup-toolbar-content\">\n        <ng-container *ngFor=\"let action of defaultActions\">\n            <button type=\"button\" mat-icon-button (click)=\"doEmit(action, $event)\">\n                <mat-icon aria-label=\"action.name\">{{ action.icon }}</mat-icon>\n            </button>\n        </ng-container>\n    </span>\n</mat-toolbar>\n", styles: [".deja-popup-toolbar>.mat-icon{margin-right:4px}.deja-popup-toolbar-mini{display:flex;height:auto}.deja-popup-toolbar-mini .deja-popup-toolbar-content{font-size:12px}.deja-popup-toolbar-mini .deja-popup-toolbar-content button,.deja-popup-toolbar-mini .deja-popup-toolbar-content .mat-icon{width:18px;height:18px;line-height:18px}.deja-popup-toolbar-mini .deja-popup-toolbar-content button{margin-left:4px}.deja-popup-toolbar-mini .deja-popup-toolbar-content .mat-icon{font-size:18px}.deja-popup-toolbar-mini .deja-popup-toolbar-spacer{flex:1;cursor:grab}.deja-popup-toolbar-mini .deja-popup-toolbar-spacer .mat-icon{vertical-align:sub;margin-right:4px}.deja-popup-toolbar-mini .deja-popup-toolbar-actions{padding-left:1rem}.deja-popup-toolbar-mini .deja-popup-toolbar-actions~.deja-popup-toolbar-actions{padding-left:0}.deja-popup-toolbar-mini .actions-hide{display:none}\n"] }]
        }], ctorParameters: function () { return []; }, propDecorators: { actionSelected: [{
                type: Output
            }], config: [{
                type: Input
            }] } });

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
class DejaPopupContentComponent {
    set config(value) {
        if (!value.content) {
            this.content = [];
        }
        else if (typeof value.content === 'string') {
            this.content = [value.content];
        }
        else {
            this.content = value.content;
        }
    }
}
DejaPopupContentComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupContentComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
DejaPopupContentComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: DejaPopupContentComponent, selector: "deja-popup-content", inputs: { config: "config" }, ngImport: i0, template: "<ng-container *ngIf=\"content.length\">\n    <div *ngFor=\"let html of content\" [innerHTML]=\"html\"></div>\n</ng-container>", styles: [""], directives: [{ type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i6.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupContentComponent, decorators: [{
            type: Component,
            args: [{ selector: 'deja-popup-content', template: "<ng-container *ngIf=\"content.length\">\n    <div *ngFor=\"let html of content\" [innerHTML]=\"html\"></div>\n</ng-container>", styles: [""] }]
        }], propDecorators: { config: [{
                type: Input
            }] } });

class DejaPopupConfig extends MatDialogConfig {
    constructor() {
        super();
        this.positionStart = { top: 100, left: 100 };
        this.dimensionDefault = { width: '60vw', height: '65vh' };
        this.autoFocus = false;
        this.fullscreen = false;
        this.availableInTray = true;
        this.maxWidth = '100vw';
        this.maxHeight = '100vh';
        this.shareActions = true;
        this.toolbarColor = 'primary';
    }
    ensureDimension() {
        if (!this.width) {
            this.setDefaultWidth();
        }
        if (!this.height) {
            this.setDefaultHeight();
        }
    }
    setDefaultWidth() {
        this.width = this.dimensionDefault.width;
    }
    setDefaultHeight() {
        this.height = this.dimensionDefault.height;
    }
    getDefaultPosition() {
        const shift = (10 * DejaPopupConfig.dialogCount) - (100 * Math.ceil(DejaPopupConfig.dialogCount / 10));
        return {
            top: `${(this.positionStart.top + shift)}px`,
            left: `${(this.positionStart.left + shift)}px`
        };
    }
    getMatDialogConfig() {
        this.createIds();
        if (this.autoposition) {
            this.ensurePosition();
        }
        if (!this.title) {
            this.title = `Popup ${DejaPopupConfig.dialogCount}`;
        }
        const config = new MatDialogConfig();
        config.ariaDescribedBy = this.ariaDescribedBy;
        config.backdropClass = this.backdropClass;
        config.direction = this.direction;
        config.disableClose = this.disableClose;
        config.hasBackdrop = this.hasBackdrop;
        config.height = this.height;
        config.id = this.id;
        config.maxHeight = this.maxHeight;
        config.maxWidth = this.maxWidth;
        config.minHeight = this.minHeight;
        config.minWidth = this.minWidth;
        config.panelClass = this.panelClass;
        config.position = this.position;
        config.role = this.role;
        config.viewContainerRef = this.viewContainerRef;
        config.width = this.width;
        config.data = this;
        return config;
    }
    addPanelClass(panelClass) {
        if (!this.panelClass) {
            this.panelClass = [panelClass];
        }
        else if (Array.isArray(this.panelClass)) {
            this.panelClass.push(panelClass);
        }
        else {
            this.panelClass = [panelClass, this.panelClass];
        }
    }
    hasContent() {
        return !!this.content && this.content.length > 0;
    }
    hasActions() {
        return !!this.actions && !!this.actionComponentRef;
    }
    ensurePosition() {
        if (!this.position) {
            this.position = this.getDefaultPosition();
            return true;
        }
        if (!this.position.top && !this.position.bottom) {
            this.position.top = `${(this.positionStart.top)}px`;
        }
        if (!this.position.left && !this.position.right) {
            this.position.left = `${(this.positionStart.left)}px`;
        }
        return undefined;
    }
    createIds() {
        // Generate an ID if null or empty
        if (!this.id) {
            this.id = `deja-popup-${++DejaPopupConfig.dialogCount}`;
        }
        const className = `deja-popup-pane-${DejaPopupConfig.dialogCount}`;
        this.addPanelClass(className);
        this.dialogPanelId = `.${className}`;
    }
}
// eslint-disable-next-line @typescript-eslint/naming-convention
DejaPopupConfig.dialogCount = 0;

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
class DejaPopupComponent extends DejaPopupBase {
    constructor(dialogRef, config, injector) {
        super();
        this.dialogRef = dialogRef;
        this.config = config;
        this.injector = injector;
        this.isMinified = false;
        this.isFullscreen = false;
    }
    // eslint-disable-next-line @typescript-eslint/no-empty-function
    doAction(_action) { }
}
DejaPopupComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupComponent, deps: [{ token: i1$2.MatDialogRef }, { token: MAT_DIALOG_DATA }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component });
DejaPopupComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: DejaPopupComponent, selector: "deja-popup", usesInheritance: true, ngImport: i0, template: "<deja-popup-toolbar *ngIf=\"config && config.title\" [config]=\"config\" (actionSelected)=\"dispatchAction($event)\">\n</deja-popup-toolbar>\n\n<div mat-dialog-content>\n    <deja-popup-content *ngIf=\"config?.hasContent()\" [config]=\"config\">\n    </deja-popup-content>\n</div>\n\n<div mat-dialog-actions *ngIf=\"config.hasActions()\">\n    <div [cdkPortalOutlet]=\"actionsPortal\"></div>\n</div>", styles: ["deja-popup .mat-dialog-content{padding:24px;margin:0}deja-popup .mat-dialog-actions:last-child{margin:0 24px!important}\n"], components: [{ type: DejaPopupToolbarComponent, selector: "deja-popup-toolbar", inputs: ["config"], outputs: ["actionSelected"] }, { type: DejaPopupContentComponent, selector: "deja-popup-content", inputs: ["config"] }], directives: [{ type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1$2.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i1$2.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }, { type: i6$1.CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }], encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupComponent, decorators: [{
            type: Component,
            args: [{ encapsulation: ViewEncapsulation.None, selector: 'deja-popup', template: "<deja-popup-toolbar *ngIf=\"config && config.title\" [config]=\"config\" (actionSelected)=\"dispatchAction($event)\">\n</deja-popup-toolbar>\n\n<div mat-dialog-content>\n    <deja-popup-content *ngIf=\"config?.hasContent()\" [config]=\"config\">\n    </deja-popup-content>\n</div>\n\n<div mat-dialog-actions *ngIf=\"config.hasActions()\">\n    <div [cdkPortalOutlet]=\"actionsPortal\"></div>\n</div>", styles: ["deja-popup .mat-dialog-content{padding:24px;margin:0}deja-popup .mat-dialog-actions:last-child{margin:0 24px!important}\n"] }]
        }], ctorParameters: function () { return [{ type: i1$2.MatDialogRef }, { type: DejaPopupConfig, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }, { type: i0.Injector }]; } });

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
class DejaPopupActionsComponent {
    constructor(config) {
        this.config = config;
    }
    ngOnInit() {
        if (this.config.actions.length) {
            this.buttons = this.config.actions;
        }
    }
    emit(action) {
        if (this.config.dejaPopupCom$) {
            action.target = this.config.id;
            this.config.dejaPopupCom$.next(action);
        }
    }
}
DejaPopupActionsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupActionsComponent, deps: [{ token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component });
DejaPopupActionsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: DejaPopupActionsComponent, selector: "deja-popup-actions", ngImport: i0, template: "<div class=\"deja-popup-spacer\">&nbsp;</div>\n<ng-container *ngFor=\"let but of buttons\">\n\n    <button type=\"button\" *ngIf=\"!but.label\" mat-icon-button (click)=\"emit(but)\">\n        <mat-icon *ngIf=\"but.icon\" color=\"primary\" role=\"img\" aria-hidden=\"true\">{{but.icon}}</mat-icon>\n    </button>\n\n    <button type=\"button\" *ngIf=\"but.label\" mat-raised-button color=\"primary\" [name]=\"but.name\" (click)=\"emit(but)\">\n        <mat-icon *ngIf=\"but.icon\" role=\"img\" aria-hidden=\"true\">{{but.icon}}</mat-icon>{{but.label}}\n    </button>\n\n</ng-container>", styles: [":host{display:flex;width:100%;height:100%}:host .deja-popup-spacer{flex:1 1 auto}:host button{margin-left:8px}:host button .mat-icon{line-height:18px;font-size:18px;height:18px;width:18px;margin-right:3px}\n"], components: [{ type: i1$1.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button],             button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],             button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], directives: [{ type: i6.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupActionsComponent, decorators: [{
            type: Component,
            args: [{ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'deja-popup-actions', template: "<div class=\"deja-popup-spacer\">&nbsp;</div>\n<ng-container *ngFor=\"let but of buttons\">\n\n    <button type=\"button\" *ngIf=\"!but.label\" mat-icon-button (click)=\"emit(but)\">\n        <mat-icon *ngIf=\"but.icon\" color=\"primary\" role=\"img\" aria-hidden=\"true\">{{but.icon}}</mat-icon>\n    </button>\n\n    <button type=\"button\" *ngIf=\"but.label\" mat-raised-button color=\"primary\" [name]=\"but.name\" (click)=\"emit(but)\">\n        <mat-icon *ngIf=\"but.icon\" role=\"img\" aria-hidden=\"true\">{{but.icon}}</mat-icon>{{but.label}}\n    </button>\n\n</ng-container>", styles: [":host{display:flex;width:100%;height:100%}:host .deja-popup-spacer{flex:1 1 auto}:host button{margin-left:8px}:host button .mat-icon{line-height:18px;font-size:18px;height:18px;width:18px;margin-right:3px}\n"] }]
        }], ctorParameters: function () { return [{ type: DejaPopupConfig, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }]; } });

class DejaPopupAdvancedComponent extends DejaPopupBase {
    constructor(dialogRef, config, injector, renderer, elRef, domSanitizer) {
        super();
        this.dialogRef = dialogRef;
        this.config = config;
        this.injector = injector;
        this.renderer = renderer;
        this.elRef = elRef;
        this.domSanitizer = domSanitizer;
        this.dragstart = false;
        this.dragPosition = { x: 0, y: 0 };
        if (config.url && typeof config.url === 'string') {
            config.url = this.domSanitizer.bypassSecurityTrustResourceUrl(config.url);
        }
    }
    ngOnInit() {
        super.ngOnInit();
        if (this.config.contentComponentRef) {
            this.componentPortal = new ComponentPortal(this.config.contentComponentRef, undefined, this.injector);
        }
    }
    ngAfterViewInit() {
        this.left = this.elRef.nativeElement.offsetLeft;
        this.top = this.elRef.nativeElement.offsetTop;
        if (this.config.fullscreen) {
            timer(0).pipe(takeUntil(this.destroyed$)).subscribe(() => this.goFullScreen());
        }
    }
    doAction(action) {
        this.actionSelected = action;
        const actionName = typeof action === 'string' ? action : action.name;
        switch (actionName) {
            case 'toolbar-close':
            case 'close':
                action.isFinalAction = true;
                break;
            case 'toolbar-fullscreen':
                this.goFullScreen();
                break;
            case 'toolbar-fullscreen-exit':
                this.exitFullScreen();
                break;
            case 'toolbar-minify':
                this.isMinified = true;
                if (this.config.dejaPopupCom$) {
                    const actionOut = new DejaPopupAction('do-minify', 'popup-tray');
                    actionOut.panelClass = this.config.dialogPanelId;
                    this.config.dejaPopupCom$.next(actionOut);
                }
                break;
            default:
        }
    }
    goFullScreen() {
        this.isFullscreen = true;
        this.dragPosition = { x: 0, y: 0 };
        this.dialogRef.updateSize('100vw', '100vh');
    }
    exitFullScreen() {
        this.isFullscreen = false;
        const updatedWidth = (!this.config.width || this.config.width.length < 1) ? 'auto' : this.config.width;
        const updatedHeight = (!this.config.height || this.config.height.length < 1) ? 'auto' : this.config.height;
        this.dialogRef.updatePosition({ top: `${this.top}px`, left: `${this.left}px` });
        this.dialogRef.updateSize(updatedWidth, updatedHeight);
    }
    onCdkDragEnded(cdkDrag) {
        this.dragstart = false;
        this.top += cdkDrag.source.getFreeDragPosition().y;
        this.left += cdkDrag.source.getFreeDragPosition().x;
    }
}
DejaPopupAdvancedComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupAdvancedComponent, deps: [{ token: i1$2.MatDialogRef }, { token: MAT_DIALOG_DATA }, { token: i0.Injector }, { token: i0.Renderer2 }, { token: i0.ElementRef }, { token: i2$1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component });
DejaPopupAdvancedComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: DejaPopupAdvancedComponent, selector: "deja-popup-advanced", usesInheritance: true, ngImport: i0, template: "<div class=\"deja-popup-container\" cdkDrag cdkDragRootElement=\".cdk-overlay-pane\" cdkDragBoundary=\".cdk-overlay-container\" (cdkDragStarted)=\"dragstart = true\" (cdkDragEnded)=\"onCdkDragEnded($event)\" [cdkDragFreeDragPosition]=\"dragPosition\">\n    <div *ngIf=\"dragstart\" class=\"dialog-overlay\">&nbsp;</div>\n\n    <deja-popup-toolbar cdkDragHandle *ngIf=\"config && config.toolbarType\" [config]=\"config\" (actionSelected)=\"dispatchAction($event)\"></deja-popup-toolbar>\n\n    <div mat-dialog-content [ngClass]=\"{'frame-full': !config.padding, 'frame-padding': !!config.padding}\">\n\n        <deja-popup-content *ngIf=\"config?.hasContent()\" [config]=\"config\">\n        </deja-popup-content>\n\n        <div *ngIf=\"config?.url\" class=\"iframe-wrapper\">\n            <iframe [src]=\"config.url\"></iframe>\n        </div>\n\n        <ng-container *ngIf=\"config?.contentComponentRef\">\n            <div [cdkPortalOutlet]=\"componentPortal\"></div>\n        </ng-container>\n\n        <ng-container *ngIf=\"config?.contentTemplate\">\n            <ng-template [ngTemplateOutlet]=\"config?.contentTemplate.templateRef\" [ngTemplateOutletContext]=\"config?.contentTemplate.templateContext\"></ng-template>\n        </ng-container>\n    </div>\n\n    <div mat-dialog-actions *ngIf=\"config.hasActions()\">\n        <div [cdkPortalOutlet]=\"actionsPortal\"></div>\n    </div>\n</div>\n", styles: ["deja-popup-advanced{width:100%}deja-popup-advanced .deja-popup-container{height:100%;position:relative;display:flex;flex-direction:column}deja-popup-advanced .deja-popup-container .dialog-overlay{height:100%;width:100%;z-index:100;position:absolute;top:0;left:0;cursor:grabbing}deja-popup-advanced .deja-popup-container .mat-dialog-content{height:100%;flex:1 1 auto;display:flex;flex-direction:column}deja-popup-advanced .deja-popup-container .mat-dialog-content.frame-padding{padding:24px;margin:0;max-height:100vh}deja-popup-advanced .deja-popup-container .mat-dialog-content.frame-full{padding:0;margin:0;overflow:hidden;max-height:100vh}deja-popup-advanced .deja-popup-container .mat-dialog-content .iframe-wrapper{width:100%;height:100%}deja-popup-advanced .deja-popup-container .mat-dialog-content .iframe-wrapper iframe{border:none;height:100%;width:100%}deja-popup-advanced .deja-popup-container .mat-dialog-actions{flex:1 1 auto;padding-bottom:18px}deja-popup-advanced .deja-popup-container .mat-dialog-actions.mat-dialog-actions:last-child{margin:0 24px!important}\n"], components: [{ type: DejaPopupToolbarComponent, selector: "deja-popup-toolbar", inputs: ["config"], outputs: ["actionSelected"] }, { type: DejaPopupContentComponent, selector: "deja-popup-content", inputs: ["config"] }], directives: [{ type: i5$1.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i5$1.CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { type: i1$2.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i6.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i6$1.CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }, { type: i6.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }, { type: i1$2.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }], encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupAdvancedComponent, decorators: [{
            type: Component,
            args: [{ encapsulation: ViewEncapsulation.None, selector: 'deja-popup-advanced', template: "<div class=\"deja-popup-container\" cdkDrag cdkDragRootElement=\".cdk-overlay-pane\" cdkDragBoundary=\".cdk-overlay-container\" (cdkDragStarted)=\"dragstart = true\" (cdkDragEnded)=\"onCdkDragEnded($event)\" [cdkDragFreeDragPosition]=\"dragPosition\">\n    <div *ngIf=\"dragstart\" class=\"dialog-overlay\">&nbsp;</div>\n\n    <deja-popup-toolbar cdkDragHandle *ngIf=\"config && config.toolbarType\" [config]=\"config\" (actionSelected)=\"dispatchAction($event)\"></deja-popup-toolbar>\n\n    <div mat-dialog-content [ngClass]=\"{'frame-full': !config.padding, 'frame-padding': !!config.padding}\">\n\n        <deja-popup-content *ngIf=\"config?.hasContent()\" [config]=\"config\">\n        </deja-popup-content>\n\n        <div *ngIf=\"config?.url\" class=\"iframe-wrapper\">\n            <iframe [src]=\"config.url\"></iframe>\n        </div>\n\n        <ng-container *ngIf=\"config?.contentComponentRef\">\n            <div [cdkPortalOutlet]=\"componentPortal\"></div>\n        </ng-container>\n\n        <ng-container *ngIf=\"config?.contentTemplate\">\n            <ng-template [ngTemplateOutlet]=\"config?.contentTemplate.templateRef\" [ngTemplateOutletContext]=\"config?.contentTemplate.templateContext\"></ng-template>\n        </ng-container>\n    </div>\n\n    <div mat-dialog-actions *ngIf=\"config.hasActions()\">\n        <div [cdkPortalOutlet]=\"actionsPortal\"></div>\n    </div>\n</div>\n", styles: ["deja-popup-advanced{width:100%}deja-popup-advanced .deja-popup-container{height:100%;position:relative;display:flex;flex-direction:column}deja-popup-advanced .deja-popup-container .dialog-overlay{height:100%;width:100%;z-index:100;position:absolute;top:0;left:0;cursor:grabbing}deja-popup-advanced .deja-popup-container .mat-dialog-content{height:100%;flex:1 1 auto;display:flex;flex-direction:column}deja-popup-advanced .deja-popup-container .mat-dialog-content.frame-padding{padding:24px;margin:0;max-height:100vh}deja-popup-advanced .deja-popup-container .mat-dialog-content.frame-full{padding:0;margin:0;overflow:hidden;max-height:100vh}deja-popup-advanced .deja-popup-container .mat-dialog-content .iframe-wrapper{width:100%;height:100%}deja-popup-advanced .deja-popup-container .mat-dialog-content .iframe-wrapper iframe{border:none;height:100%;width:100%}deja-popup-advanced .deja-popup-container .mat-dialog-actions{flex:1 1 auto;padding-bottom:18px}deja-popup-advanced .deja-popup-container .mat-dialog-actions.mat-dialog-actions:last-child{margin:0 24px!important}\n"] }]
        }], ctorParameters: function () { return [{ type: i1$2.MatDialogRef }, { type: DejaPopupConfig, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }, { type: i0.Injector }, { type: i0.Renderer2 }, { type: i0.ElementRef }, { type: i2$1.DomSanitizer }]; } });

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
class DejaPopupBoxComponent {
    constructor() {
        this.action = new EventEmitter();
        this.showActions = false;
        this.buttonClose = {
            name: 'toolbar-close',
            icon: 'close',
            label: 'Close'
        };
        this.buttonFullscreen = {
            name: 'toolbar-fullscreen',
            icon: 'fullscreen',
            label: 'Fullscreen'
        };
        this.buttonMinimize = {
            name: 'toolbar-minify',
            icon: 'remove',
            label: 'Minify'
        };
    }
    onMouseEnter() {
        this.showActions = true;
    }
    onMouseLeave() {
        this.showActions = false;
    }
    doEmit(action) {
        action.target = 'popup-tray';
        this.dialog.componentInstance.isMinified = !this.dialog.componentInstance.isMinified;
        action.panelClass = this.dialog.componentInstance.config.dialogPanelId;
        this.action.emit(action);
    }
    doClose() {
        this.dialog.close();
        const a = new DejaPopupAction('tray-refresh', 'popup-tray');
        this.action.emit(a);
    }
}
DejaPopupBoxComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupBoxComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
DejaPopupBoxComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: DejaPopupBoxComponent, selector: "deja-popup-box", inputs: { dialog: "dialog" }, outputs: { action: "action" }, host: { listeners: { "mouseenter": "onMouseEnter()", "mouseleave": "onMouseLeave()" } }, ngImport: i0, template: "<span class=\"deja-popup-box-title\">{{dialog.componentInstance.config.title}}</span>\n\n<span *ngIf=\"showActions\" class=\"deja-popup-box-actions\">\n    <span class=\"deja-popup-box-content\">\n        <button type=\"button\" *ngIf=\"!dialog.componentInstance.isMinified\" mat-icon-button (click)=\"doEmit(buttonMinimize)\" tabindex=\"0\">\n            <mat-icon aria-label=\"buttonMinimize.label\">{{buttonMinimize.icon}}</mat-icon>\n        </button>\n        <button type=\"button\" *ngIf=\"dialog.componentInstance.isMinified\" mat-icon-button (click)=\"doEmit(buttonFullscreen)\" tabindex=\"0\">\n            <mat-icon aria-label=\"buttonFullscreen.label\">{{buttonFullscreen.icon}}</mat-icon>\n        </button>\n        <button type=\"button\" mat-icon-button (click)=\"doClose()\" tabindex=\"0\">\n            <mat-icon aria-label=\"buttonClose.label\">{{buttonClose.icon}}</mat-icon>\n        </button>\n    </span>\n</span>", styles: [":host{line-height:36px;font-size:.8rem;margin:0 1px;position:relative;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .deja-popup-box-title{padding:0 .8rem}:host .deja-popup-box-actions{position:absolute;width:100%;top:0;left:0;text-align:right}:host .deja-popup-box-actions .deja-popup-box-content{padding-right:1rem}:host .deja-popup-box-actions .deja-popup-box-content button{width:18px;height:18px;line-height:18px}:host .deja-popup-box-actions .deja-popup-box-content button .mat-icon{line-height:18px;font-size:18px;height:18px;width:18px}\n"], components: [{ type: i1$1.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button],             button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],             button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], directives: [{ type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupBoxComponent, decorators: [{
            type: Component,
            args: [{ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'deja-popup-box', template: "<span class=\"deja-popup-box-title\">{{dialog.componentInstance.config.title}}</span>\n\n<span *ngIf=\"showActions\" class=\"deja-popup-box-actions\">\n    <span class=\"deja-popup-box-content\">\n        <button type=\"button\" *ngIf=\"!dialog.componentInstance.isMinified\" mat-icon-button (click)=\"doEmit(buttonMinimize)\" tabindex=\"0\">\n            <mat-icon aria-label=\"buttonMinimize.label\">{{buttonMinimize.icon}}</mat-icon>\n        </button>\n        <button type=\"button\" *ngIf=\"dialog.componentInstance.isMinified\" mat-icon-button (click)=\"doEmit(buttonFullscreen)\" tabindex=\"0\">\n            <mat-icon aria-label=\"buttonFullscreen.label\">{{buttonFullscreen.icon}}</mat-icon>\n        </button>\n        <button type=\"button\" mat-icon-button (click)=\"doClose()\" tabindex=\"0\">\n            <mat-icon aria-label=\"buttonClose.label\">{{buttonClose.icon}}</mat-icon>\n        </button>\n    </span>\n</span>", styles: [":host{line-height:36px;font-size:.8rem;margin:0 1px;position:relative;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .deja-popup-box-title{padding:0 .8rem}:host .deja-popup-box-actions{position:absolute;width:100%;top:0;left:0;text-align:right}:host .deja-popup-box-actions .deja-popup-box-content{padding-right:1rem}:host .deja-popup-box-actions .deja-popup-box-content button{width:18px;height:18px;line-height:18px}:host .deja-popup-box-actions .deja-popup-box-content button .mat-icon{line-height:18px;font-size:18px;height:18px;width:18px}\n"] }]
        }], propDecorators: { dialog: [{
                type: Input
            }], action: [{
                type: Output
            }], onMouseEnter: [{
                type: HostListener,
                args: ['mouseenter']
            }], onMouseLeave: [{
                type: HostListener,
                args: ['mouseleave']
            }] } });

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
class DejaPopupReponse {
    constructor(resp, componentInstance) {
        this.resp = resp;
        this.componentInstance = componentInstance;
        this.acceptedActionNames = ['check', 'ok', 'yes', 'confirm', 'save'];
        if (componentInstance?.actionSelected) {
            this.lastAction = this.componentInstance.actionSelected;
        }
        else {
            this.lastAction = new DejaPopupAction('cancel');
        }
    }
    get accepted() {
        return this.acceptedActionNames.some((nameOk) => typeof this.lastAction === 'string' ? nameOk === this.lastAction : nameOk === this.lastAction.name);
    }
}

class DejaPopupService extends MatDialog {
    constructor() {
        super(...arguments);
        this.defaultActionComponent = DejaPopupActionsComponent;
    }
    get openDialogs() {
        return super.openDialogs;
    }
    get dejaPopupCom$() {
        if (!this._dialogCom$) {
            this._dialogCom$ = new BehaviorSubject(null);
        }
        return this._dialogCom$;
    }
    /**
     * Displays a modal dialog, with the given buttons.
     * @param title
     * @param message
     * @param buttons types de DpiButton
     * @param customComponent Custom Component that must extend DpiDialogComponent.
     * @param data Données que l'on peux passer au Dialog
     * @return La réponse du dialog sous forme d'un Observable
     */
    // eslint-disable-next-line rxjs/finnish
    openInline(title, content, buttons, config = new DejaPopupConfig()) {
        config.title = title;
        config.content = content;
        config.actions = buttons;
        const dialogRef = this.open(DejaPopupComponent, config);
        return dialogRef.afterClosed().pipe(map(resp => new DejaPopupReponse(resp, dialogRef.componentInstance)));
    }
    // eslint-disable-next-line rxjs/finnish
    openCustom(customComponent, config = new DejaPopupConfig()) {
        const dialogRef = this.open(customComponent, config);
        return dialogRef.afterClosed().pipe(map(resp => new DejaPopupReponse(resp, dialogRef.componentInstance)));
    }
    // eslint-disable-next-line rxjs/finnish
    openUrl(url, config = new DejaPopupConfig()) {
        config.url = url;
        config.ensureDimension();
        const dialogRef = this.open(DejaPopupAdvancedComponent, config);
        return dialogRef.afterClosed().pipe(map(resp => new DejaPopupReponse(resp, dialogRef.componentInstance)));
    }
    openAdvanced(config = new DejaPopupConfig()) {
        const dialogRef = this.open(DejaPopupAdvancedComponent, config);
        return dialogRef;
    }
    openAdvanced$(config = new DejaPopupConfig()) {
        const dialogRef = this.openAdvanced(config);
        return dialogRef.afterClosed().pipe(map(resp => new DejaPopupReponse(resp, dialogRef.componentInstance)));
    }
    // eslint-disable-next-line rxjs/finnish
    openPopUp(config = new DejaPopupConfig()) {
        config.hasBackdrop = false;
        // config.isModal = false;
        // config.ensureDimension();
        if (config.autoposition === undefined) {
            config.autoposition = true;
        }
        if (config.toolbarType === undefined) {
            config.toolbarType = 'window';
        }
        return this.openAdvanced$(config);
    }
    /**
      * Opens a modal dialog containing the given component.
      * @param componentOrTemplateRef Type of the component to load into the dialog,
      *     or a TemplateRef to instantiate as the dialog content.
      * @param config Extra configuration options.
      * @returns Reference to the newly-opened dialog.
      */
    open(componentOrTemplateRef, config) {
        if (config.shareActions && !config.dejaPopupCom$) {
            config.dejaPopupCom$ = this.dejaPopupCom$;
        }
        if (!config.actionComponentRef && this.defaultActionComponent) {
            config.actionComponentRef = this.defaultActionComponent;
        }
        return super.open(componentOrTemplateRef, config.getMatDialogConfig());
    }
}
DejaPopupService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
DejaPopupService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupService, decorators: [{
            type: Injectable
        }] });

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
class DejaPopupTrayComponent {
    constructor(dialogSrv) {
        this.dialogSrv = dialogSrv;
    }
    ngOnInit() {
        this.dialogs$ = from(this.dialogSrv.afterOpened).pipe(switchMap(() => this.dialogSrv.dejaPopupCom$.pipe(filter(action => !!action && action.target === 'popup-tray'), map(action => {
            if (action.name === 'do-minify') {
                this.minify(action);
                action.refreshDrawer = false;
            }
            return action;
        }), filter(action => action.refreshDrawer))), debounceTime(500), map(() => this.dialogSrv.openDialogs.filter(dialog => dialog.componentInstance.config?.availableInTray)));
    }
    minify(action) {
        const el = document.querySelector(action.panelClass);
        if (!el) {
            return false;
        }
        el.style.display = 'none';
        this.refresh();
        return undefined;
    }
    maxify(action) {
        const el = document.querySelector(action.panelClass);
        if (!el) {
            return false;
        }
        el.style.display = 'initial';
        this.refresh();
        return undefined;
    }
    doAction(action) {
        if (action.name === 'toolbar-minify') {
            this.minify(action);
        }
        else if (action.name === 'toolbar-fullscreen') {
            this.maxify(action);
        }
        else {
            this.dialogSrv.dejaPopupCom$.next(action);
        }
        return undefined;
    }
    closeAll() {
        this.dialogSrv.closeAll();
        this.refresh();
    }
    minimizeAll() {
        this.dialogSrv.openDialogs.forEach((d) => {
            const a = new DejaPopupAction('minify-all', 'popup-tray');
            d.componentInstance.isMinified = true;
            a.panelClass = d.componentInstance.config.dialogPanelId;
            this.minify(a);
        });
    }
    showAll() {
        this.dialogSrv.openDialogs.forEach((d) => {
            const a = new DejaPopupAction('show-all', 'popup-tray');
            d.componentInstance.isMinified = false;
            a.panelClass = d.componentInstance.config.dialogPanelId;
            this.maxify(a);
        });
    }
    refresh() {
        const a = new DejaPopupAction('tray-refresh', 'popup-tray');
        this.dialogSrv.dejaPopupCom$.next(a);
    }
}
DejaPopupTrayComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupTrayComponent, deps: [{ token: DejaPopupService }], target: i0.ɵɵFactoryTarget.Component });
DejaPopupTrayComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: DejaPopupTrayComponent, selector: "deja-popup-tray", ngImport: i0, template: "<span class=\"deja-popup-box-container\">\n    <ng-container *ngFor=\"let dialog of (dialogs$ | async)\">\n        <deja-popup-box [dialog]=\"dialog\" (action)=\"doAction($event)\">\n        </deja-popup-box>\n    </ng-container>\n</span>\n\n<button type=\"button\" mat-icon-button (click)=\"posYMenu.show($event)\">\n    <mat-icon>more_vert</mat-icon>\n</button>\n\n<deja-overlay #posYMenu>\n    <div class=\"deja-menu-content\">\n        <ul>\n            <li class=\"menu-item\" (click)=\"closeAll();posYMenu.close()\">\n                <mat-icon>close</mat-icon> Close all\n            </li>\n            <li class=\"menu-item\" (click)=\"showAll();posYMenu.close()\">\n                <mat-icon>fullscreen</mat-icon> Show all\n            </li>\n            <li class=\"menu-item\" (click)=\"minimizeAll();posYMenu.close()\">\n                <mat-icon>remove</mat-icon> Dock all\n            </li>\n        </ul>\n    </div>\n</deja-overlay>", styles: [":host{display:flex;flex-direction:row;position:absolute;bottom:0;left:0;width:100%;height:36px;overflow-x:hidden}:host .deja-popup-box-container{flex:1;display:flex;overflow:hidden}:host .deja-popup-box-container deja-popup-box{flex:1;max-width:25%;min-width:36px}:host button{width:36px;height:36px;line-height:36px}\n"], components: [{ type: DejaPopupBoxComponent, selector: "deja-popup-box", inputs: ["dialog"], outputs: ["action"] }, { type: i1$1.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button],             button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],             button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { type: i5$2.DejaOverlayComponent, selector: "deja-overlay", inputs: ["overlayBackdropClass", "overlayContainerClass", "overlayOffsetX", "overlayOffsetY", "isVisible", "hasBackdrop", "ownerElement", "positions", "positionsForMobile", "isMobile", "width", "widthForMobile"], outputs: ["visibleChange", "closed"] }], directives: [{ type: i6.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], pipes: { "async": i6.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupTrayComponent, decorators: [{
            type: Component,
            args: [{ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'deja-popup-tray', template: "<span class=\"deja-popup-box-container\">\n    <ng-container *ngFor=\"let dialog of (dialogs$ | async)\">\n        <deja-popup-box [dialog]=\"dialog\" (action)=\"doAction($event)\">\n        </deja-popup-box>\n    </ng-container>\n</span>\n\n<button type=\"button\" mat-icon-button (click)=\"posYMenu.show($event)\">\n    <mat-icon>more_vert</mat-icon>\n</button>\n\n<deja-overlay #posYMenu>\n    <div class=\"deja-menu-content\">\n        <ul>\n            <li class=\"menu-item\" (click)=\"closeAll();posYMenu.close()\">\n                <mat-icon>close</mat-icon> Close all\n            </li>\n            <li class=\"menu-item\" (click)=\"showAll();posYMenu.close()\">\n                <mat-icon>fullscreen</mat-icon> Show all\n            </li>\n            <li class=\"menu-item\" (click)=\"minimizeAll();posYMenu.close()\">\n                <mat-icon>remove</mat-icon> Dock all\n            </li>\n        </ul>\n    </div>\n</deja-overlay>", styles: [":host{display:flex;flex-direction:row;position:absolute;bottom:0;left:0;width:100%;height:36px;overflow-x:hidden}:host .deja-popup-box-container{flex:1;display:flex;overflow:hidden}:host .deja-popup-box-container deja-popup-box{flex:1;max-width:25%;min-width:36px}:host button{width:36px;height:36px;line-height:36px}\n"] }]
        }], ctorParameters: function () { return [{ type: DejaPopupService }]; } });

/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
class DejaPopupModule {
}
DejaPopupModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
DejaPopupModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupModule, declarations: [DejaPopupActionsComponent,
        DejaPopupAdvancedComponent,
        DejaPopupBoxComponent,
        DejaPopupComponent,
        DejaPopupComponent,
        DejaPopupContentComponent,
        DejaPopupToolbarComponent,
        DejaPopupTrayComponent], imports: [CommonModule,
        DejaOverlayModule,
        DragDropModule,
        MatButtonModule,
        MatDialogModule,
        MatIconModule,
        MatToolbarModule,
        MatTooltipModule,
        PortalModule], exports: [DejaPopupActionsComponent,
        DejaPopupAdvancedComponent,
        DejaPopupComponent,
        DejaPopupComponent,
        DejaPopupContentComponent,
        DejaPopupToolbarComponent,
        DejaPopupTrayComponent,
        PortalModule] });
DejaPopupModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupModule, providers: [DejaPopupService], imports: [[
            CommonModule,
            DejaOverlayModule,
            DragDropModule,
            MatButtonModule,
            MatDialogModule,
            MatIconModule,
            MatToolbarModule,
            MatTooltipModule,
            PortalModule
        ], PortalModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: DejaPopupModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        DejaPopupActionsComponent,
                        DejaPopupAdvancedComponent,
                        DejaPopupBoxComponent,
                        DejaPopupComponent,
                        DejaPopupComponent,
                        DejaPopupContentComponent,
                        DejaPopupToolbarComponent,
                        DejaPopupTrayComponent
                    ],
                    entryComponents: [DejaPopupActionsComponent, DejaPopupAdvancedComponent, DejaPopupComponent],
                    exports: [
                        DejaPopupActionsComponent,
                        DejaPopupAdvancedComponent,
                        DejaPopupComponent,
                        DejaPopupComponent,
                        DejaPopupContentComponent,
                        DejaPopupToolbarComponent,
                        DejaPopupTrayComponent,
                        PortalModule
                    ],
                    imports: [
                        CommonModule,
                        DejaOverlayModule,
                        DragDropModule,
                        MatButtonModule,
                        MatDialogModule,
                        MatIconModule,
                        MatToolbarModule,
                        MatTooltipModule,
                        PortalModule
                    ],
                    providers: [DejaPopupService]
                }]
        }] });

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

export { DejaPopupAction, DejaPopupActionsComponent, DejaPopupAdvancedComponent, DejaPopupBase, DejaPopupBoxComponent, DejaPopupButton, DejaPopupComponent, DejaPopupConfig, DejaPopupContentComponent, DejaPopupCustomAction, DejaPopupModule, DejaPopupReponse, DejaPopupService, DejaPopupToolbarComponent, DejaPopupTrayComponent };
//# sourceMappingURL=deja-js-component-popup.mjs.map
