import { MXBaseComponent, AXClosableComponent, AXComponent } from '@acorex/cdk/common';
import { AXButtonComponent } from '@acorex/components/button';
import { AXDecoratorCloseButtonComponent } from '@acorex/components/decorators';
import { AXLoadingComponent } from '@acorex/components/loading';
import { AXTranslatorPipe, AXTranslationService } from '@acorex/core/translation';
import { DIALOG_DATA, DialogRef, Dialog } from '@angular/cdk/dialog';
import { TemplatePortal, ComponentPortal, CdkPortalOutlet } from '@angular/cdk/portal';
import { AsyncPipe } from '@angular/common';
import * as i0 from '@angular/core';
import { inject, signal, TemplateRef, HostBinding, ViewEncapsulation, ChangeDetectionStrategy, Component, InjectionToken, NgModule, Injectable } from '@angular/core';
import { GlobalPositionStrategy } from '@angular/cdk/overlay';

/**
 * The Button is a component which detects user interaction and triggers a corresponding event
 *
 * @category Components
 */
class AXNotificationComponent extends MXBaseComponent {
    constructor() {
        super(...arguments);
        this.config = inject(DIALOG_DATA);
        this.dialogRef = inject(DialogRef);
        this.isPaused = signal(false, ...(ngDevMode ? [{ debugName: "isPaused" }] : []));
        this.remainingTime = signal(0, ...(ngDevMode ? [{ debugName: "remainingTime" }] : []));
        this.transitionDuration = signal(150, ...(ngDevMode ? [{ debugName: "transitionDuration" }] : []));
    }
    ngOnInit() {
        super.ngOnInit();
        this._initContent();
        this._initIcon();
        this.remainingTime.set(this.config.timeOut);
        this._handleTimeOut();
        this.getHostElement().addEventListener('pointerenter', () => {
            if (!this.config.pauseOnHover)
                return;
            if (this.isPaused())
                return;
            // Only pause if not already paused
            this.isPaused.set(true);
            this.pauseAnimation();
        });
        this.getHostElement().addEventListener('pointerleave', () => {
            if (!this.config.pauseOnHover)
                return;
            if (!this.isPaused())
                return;
            // Only resume if paused
            this.isPaused.set(false);
            this._handleTimeOut();
        });
    }
    pauseAnimation() {
        clearInterval(this.intervalId);
    }
    _handleTimeOut() {
        if (this.config.timeOut) {
            this.intervalId = setInterval(() => {
                this.remainingTime.update((prev) => prev - this.transitionDuration());
                if (this.remainingTime() <= 0) {
                    clearInterval(this.intervalId);
                    this.close();
                }
            }, this.transitionDuration());
        }
    }
    /** @ignore */
    _initContent() {
        if (this.config.content instanceof TemplateRef) {
            this._selectedPortal = new TemplatePortal(this.config.content, this.getViewContainer());
        }
        else if (typeof this.config.content === 'function') {
            this._selectedPortal = new ComponentPortal(this.config.content);
        }
    }
    /** @ignore */
    _initIcon() {
        if (!this.config.icon) {
            switch (this.config.color) {
                case 'success':
                    this._icon = 'ax-icon ax-icon-check-circle';
                    break;
                case 'danger':
                    this._icon = 'ax-icon ax-icon-error';
                    break;
                case 'warning':
                    this._icon = 'ax-icon ax-icon-warning';
                    break;
                default:
                    this._icon = this.config.icon || 'ax-icon ax-icon-info';
                    break;
            }
        }
        else {
            this._icon = this.config.icon;
        }
    }
    /** @ignore */
    _handleButtonClick(button) {
        if (button.onClick) {
            button.onClick({ source: button });
        }
    }
    /** @ignore */
    get __hostClass() {
        return `ax-${this.config.color}`;
    }
    /**
     * Closes the dialog and provides the component and HTML element for reference.
     */
    close() {
        this.dialogRef.close({
            component: this,
            htmlElement: this.getHostElement(),
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.9", type: AXNotificationComponent, isStandalone: true, selector: "ax-notification", host: { properties: { "class": "this.__hostClass" } }, providers: [
            { provide: AXClosableComponent, useExisting: AXNotificationComponent },
            { provide: AXComponent, useExisting: AXNotificationComponent },
        ], usesInheritance: true, ngImport: i0, template: "<span class=\"ax-notification-icon ax-icon-solid {{ _icon }}\"></span>\n<div class=\"ax-notification-content\">\n  <div class=\"ax-notification-title\">{{ config.title | translate | async }}</div>\n  @if (_selectedPortal) {\n    <ng-template [cdkPortalOutlet]=\"_selectedPortal\"></ng-template>\n  } @else {\n    <div>{{ config.content }}</div>\n  }\n\n  @if (config.buttons?.length) {\n    <div class=\"ax-notification-buttons\">\n      @for (button of config.buttons; track $index) {\n        <ax-button\n          class=\"ax-xs\"\n          [text]=\"button.text | translate | async\"\n          [color]=\"button.color\"\n          [look]=\"button.look\"\n          [disabled]=\"button.disabled\"\n          (onClick)=\"_handleButtonClick(button)\"\n        >\n          @if (button.loading) {\n            <ax-loading></ax-loading>\n          }\n        </ax-button>\n      }\n    </div>\n  }\n</div>\n@if (config.closeButton) {\n  <ax-close-button></ax-close-button>\n}\n@if (config.timeOutProgress && config.timeOut && remainingTime()) {\n  <div\n    class=\"ax-notification-progress\"\n    [style.transition-duration]=\"transitionDuration()\"\n    [style.width]=\"(remainingTime() * 100) / config.timeOut + '%'\"\n  ></div>\n}\n", styles: ["ax-notification.ax-default{--ax-comp-notification-icon-text-color: var(--ax-sys-color-on-lightest-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-surface)}.ax-dark ax-notification.ax-default{--ax-comp-notification-icon-text-color: var(--ax-sys-color-on-darkest-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-lightest-surface)}ax-notification.ax-primary{--ax-comp-notification-icon-text-color: var(--ax-sys-color-primary-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-primary-surface)}ax-notification.ax-secondary{--ax-comp-notification-icon-text-color: var(--ax-sys-color-secondary-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-secondary-surface)}ax-notification.ax-success{--ax-comp-notification-icon-text-color: var(--ax-sys-color-success-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-success-surface)}ax-notification.ax-warning{--ax-comp-notification-icon-text-color: var(--ax-sys-color-warning-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-warning-surface)}ax-notification.ax-danger{--ax-comp-notification-icon-text-color: var(--ax-sys-color-danger-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-danger-surface)}ax-notification.ax-accent1{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent1-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent1-surface)}ax-notification.ax-accent2{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent2-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent2-surface)}ax-notification.ax-accent3{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent3-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent3-surface)}ax-notification.ax-accent4{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent4-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent4-surface)}ax-notification.ax-accent5{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent5-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent5-surface)}ax-notification.ax-accent6{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent6-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent6-surface)}ax-notification.ax-accent7{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent7-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent7-surface)}ax-notification{position:relative;display:flex;width:98vw;overflow:hidden;padding:1rem;--ax-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);--ax-shadow-colored: 0 10px 15px -3px var(--ax-shadow-color), 0 4px 6px -4px var(--ax-shadow-color);box-shadow:var(--ax-ring-offset-shadow, 0 0 rgba(0, 0, 0, 0)),var(--ax-ring-shadow, 0 0 rgba(0, 0, 0, 0)),var(--ax-shadow);background-color:rgba(var(--ax-comp-notification-bg-color, var(--ax-sys-color-lightest-surface)));font-size:var(--ax-comp-notification-font-size, .875rem);line-height:var(--ax-comp-notification-line-height, 1.25rem);border-width:var(--ax-comp-notification-border-width, 1px);border-color:rgba(var(--ax-comp-notification-border-color, var(--ax-sys-color-border-lightest-surface)));border-radius:var(--ax-comp-notification-border-radius, var(--ax-sys-border-radius))}@media (min-width: 768px){ax-notification{width:24rem}}ax-notification .ax-notification-icon,ax-notification .ax-icon-close{font-size:1.25rem;line-height:1.75rem;max-width:fit-content;align-items:flex-start}ax-notification .ax-notification-icon{color:rgba(var(--ax-comp-notification-icon-text-color));padding-inline-end:.75rem}ax-notification .ax-notification-content{display:flex;flex:1 1 0%;flex-direction:column;font-weight:400;justify-content:center;color:rgba(var(--ax-comp-notification-text-color, var(--ax-sys-color-on-surface)))}ax-notification .ax-notification-content .ax-notification-title{font-weight:500;line-height:1.5}ax-notification .ax-notification-content .ax-notification-buttons{margin-top:.75rem;display:flex;gap:.75rem}ax-notification .ax-notification-progress{width:100%;bottom:0;height:.25rem;position:absolute;inset-inline-end:0px;inset-inline-start:0px;transition-property:width;transition-timing-function:linear;transition-duration:var(--ax-sys-transition-duration);background-color:rgba(var(--ax-comp-notification-progress-bg-color, 255, 255, 255, .46))}.ax-dark ax-notification{--ax-comp-notification-bg-color: var(--ax-sys-color-darkest-surface);--ax-comp-notification-border-color: var(--ax-sys-color-border-darkest-surface)}\n"], dependencies: [{ kind: "directive", type: CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }, { kind: "component", type: AXButtonComponent, selector: "ax-button", inputs: ["disabled", "size", "tabIndex", "color", "look", "text", "toggleable", "selected", "iconOnly", "type", "loadingText"], outputs: ["onBlur", "onFocus", "onClick", "selectedChange", "toggleableChange", "lookChange", "colorChange", "disabledChange", "loadingTextChange"] }, { kind: "component", type: AXLoadingComponent, selector: "ax-loading", inputs: ["visible", "type", "context"], outputs: ["visibleChange"] }, { kind: "component", type: AXDecoratorCloseButtonComponent, selector: "ax-close-button", inputs: ["closeAll", "icon"] }, { kind: "pipe", type: AsyncPipe, name: "async" }, { kind: "pipe", type: AXTranslatorPipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-notification', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [
                        { provide: AXClosableComponent, useExisting: AXNotificationComponent },
                        { provide: AXComponent, useExisting: AXNotificationComponent },
                    ], imports: [
                        CdkPortalOutlet,
                        AXButtonComponent,
                        AXLoadingComponent,
                        AXDecoratorCloseButtonComponent,
                        AsyncPipe,
                        AXTranslatorPipe,
                    ], template: "<span class=\"ax-notification-icon ax-icon-solid {{ _icon }}\"></span>\n<div class=\"ax-notification-content\">\n  <div class=\"ax-notification-title\">{{ config.title | translate | async }}</div>\n  @if (_selectedPortal) {\n    <ng-template [cdkPortalOutlet]=\"_selectedPortal\"></ng-template>\n  } @else {\n    <div>{{ config.content }}</div>\n  }\n\n  @if (config.buttons?.length) {\n    <div class=\"ax-notification-buttons\">\n      @for (button of config.buttons; track $index) {\n        <ax-button\n          class=\"ax-xs\"\n          [text]=\"button.text | translate | async\"\n          [color]=\"button.color\"\n          [look]=\"button.look\"\n          [disabled]=\"button.disabled\"\n          (onClick)=\"_handleButtonClick(button)\"\n        >\n          @if (button.loading) {\n            <ax-loading></ax-loading>\n          }\n        </ax-button>\n      }\n    </div>\n  }\n</div>\n@if (config.closeButton) {\n  <ax-close-button></ax-close-button>\n}\n@if (config.timeOutProgress && config.timeOut && remainingTime()) {\n  <div\n    class=\"ax-notification-progress\"\n    [style.transition-duration]=\"transitionDuration()\"\n    [style.width]=\"(remainingTime() * 100) / config.timeOut + '%'\"\n  ></div>\n}\n", styles: ["ax-notification.ax-default{--ax-comp-notification-icon-text-color: var(--ax-sys-color-on-lightest-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-surface)}.ax-dark ax-notification.ax-default{--ax-comp-notification-icon-text-color: var(--ax-sys-color-on-darkest-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-lightest-surface)}ax-notification.ax-primary{--ax-comp-notification-icon-text-color: var(--ax-sys-color-primary-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-primary-surface)}ax-notification.ax-secondary{--ax-comp-notification-icon-text-color: var(--ax-sys-color-secondary-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-secondary-surface)}ax-notification.ax-success{--ax-comp-notification-icon-text-color: var(--ax-sys-color-success-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-success-surface)}ax-notification.ax-warning{--ax-comp-notification-icon-text-color: var(--ax-sys-color-warning-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-warning-surface)}ax-notification.ax-danger{--ax-comp-notification-icon-text-color: var(--ax-sys-color-danger-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-danger-surface)}ax-notification.ax-accent1{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent1-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent1-surface)}ax-notification.ax-accent2{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent2-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent2-surface)}ax-notification.ax-accent3{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent3-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent3-surface)}ax-notification.ax-accent4{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent4-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent4-surface)}ax-notification.ax-accent5{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent5-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent5-surface)}ax-notification.ax-accent6{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent6-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent6-surface)}ax-notification.ax-accent7{--ax-comp-notification-icon-text-color: var(--ax-sys-color-accent7-surface);--ax-comp-notification-progress-bg-color: var(--ax-sys-color-accent7-surface)}ax-notification{position:relative;display:flex;width:98vw;overflow:hidden;padding:1rem;--ax-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);--ax-shadow-colored: 0 10px 15px -3px var(--ax-shadow-color), 0 4px 6px -4px var(--ax-shadow-color);box-shadow:var(--ax-ring-offset-shadow, 0 0 rgba(0, 0, 0, 0)),var(--ax-ring-shadow, 0 0 rgba(0, 0, 0, 0)),var(--ax-shadow);background-color:rgba(var(--ax-comp-notification-bg-color, var(--ax-sys-color-lightest-surface)));font-size:var(--ax-comp-notification-font-size, .875rem);line-height:var(--ax-comp-notification-line-height, 1.25rem);border-width:var(--ax-comp-notification-border-width, 1px);border-color:rgba(var(--ax-comp-notification-border-color, var(--ax-sys-color-border-lightest-surface)));border-radius:var(--ax-comp-notification-border-radius, var(--ax-sys-border-radius))}@media (min-width: 768px){ax-notification{width:24rem}}ax-notification .ax-notification-icon,ax-notification .ax-icon-close{font-size:1.25rem;line-height:1.75rem;max-width:fit-content;align-items:flex-start}ax-notification .ax-notification-icon{color:rgba(var(--ax-comp-notification-icon-text-color));padding-inline-end:.75rem}ax-notification .ax-notification-content{display:flex;flex:1 1 0%;flex-direction:column;font-weight:400;justify-content:center;color:rgba(var(--ax-comp-notification-text-color, var(--ax-sys-color-on-surface)))}ax-notification .ax-notification-content .ax-notification-title{font-weight:500;line-height:1.5}ax-notification .ax-notification-content .ax-notification-buttons{margin-top:.75rem;display:flex;gap:.75rem}ax-notification .ax-notification-progress{width:100%;bottom:0;height:.25rem;position:absolute;inset-inline-end:0px;inset-inline-start:0px;transition-property:width;transition-timing-function:linear;transition-duration:var(--ax-sys-transition-duration);background-color:rgba(var(--ax-comp-notification-progress-bg-color, 255, 255, 255, .46))}.ax-dark ax-notification{--ax-comp-notification-bg-color: var(--ax-sys-color-darkest-surface);--ax-comp-notification-border-color: var(--ax-sys-color-border-darkest-surface)}\n"] }]
        }], propDecorators: { __hostClass: [{
                type: HostBinding,
                args: ['class']
            }] } });

const AX_NOTIFICATION_CONFIG = new InjectionToken('AX_NOTIFICATION_CONFIG', {
    providedIn: 'root',
    factory: () => AXNotificationDefaultConfig,
});
const AXNotificationDefaultConfig = {
    gap: 5,
    timeOut: 2500,
    timeOutProgress: true,
    closeButton: true,
    location: 'top-end',
    limit: 3,
    pauseOnHover: true,
};
function notificationConfig(config = {}) {
    const result = {
        ...AXNotificationDefaultConfig,
        ...config,
    };
    return result;
}

class AXNotificationModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationModule, imports: [AXNotificationComponent], exports: [AXNotificationComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationModule, imports: [AXNotificationComponent] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [AXNotificationComponent],
                    exports: [AXNotificationComponent],
                }]
        }] });

class AXNotificationService {
    constructor() {
        this.dialog = inject(Dialog);
        this.translationService = inject(AXTranslationService);
        this.defaultConfig = inject(AX_NOTIFICATION_CONFIG);
        this.activeNotifications = [];
        this.reservedNotifications = [];
        this.notificationCounterElement = null;
        this.moreNotificationsColor = 'primary';
        this.moreNotificationsLocation = 'bottom-center';
        this.reserveCounter = 0;
    }
    show(config) {
        config = { ...this.defaultConfig, ...config };
        this.moreNotificationsColor = config.color;
        this.moreNotificationsLocation = config.location;
        if (this.defaultConfig.limit > 0 && this.activeNotifications.length >= this.defaultConfig.limit) {
            const reservedRef = {
                close: () => {
                    console.warn('Reserved notification cannot be closed until it is displayed.');
                },
            };
            this.reservedNotifications.push({ config, reservedRef });
            this.handleReservedNotificationCounter();
            return reservedRef;
        }
        return this.displayNotification(config);
    }
    displayNotification(config) {
        const gap = this.defaultConfig.gap;
        const pos = this.getPosition(config.location) + gap + 'px';
        const positionStrategy = this.getPositionStrategy(new GlobalPositionStrategy(), config.location, pos, gap);
        const dialogRef = this.dialog.open(AXNotificationComponent, {
            data: config,
            autoFocus: '__no_element__',
            restoreFocus: false,
            role: 'dialog',
            ariaModal: true,
            closeOnNavigation: true,
            closeOnDestroy: true,
            hasBackdrop: false,
            panelClass: ['ax-animate-animated', 'ax-animate-fadeIn', 'ax-animate-faster'],
            positionStrategy,
        });
        this.activeNotifications.push(dialogRef.id);
        this.handleReservedNotificationCounter();
        const notificationRef = dialogRef.componentInstance;
        dialogRef.closed.subscribe(() => {
            this.activeNotifications = this.activeNotifications.filter((id) => id !== dialogRef.id);
            this.handleShowReservedNotification();
            this.handleReservedNotificationCounter();
            setTimeout(() => {
                this.reposition(config.location, gap);
            }, 0);
        });
        return {
            close: () => {
                notificationRef.close();
            },
        };
    }
    hideAll() {
        this.dialog.closeAll();
        this.reserveCounter = 0;
        this.reservedNotifications = [];
        this.activeNotifications = [];
        this.handleReservedNotificationCounter();
    }
    handleShowReservedNotification() {
        if (this.activeNotifications.length > this.defaultConfig.limit - 1)
            return;
        if (!this.reservedNotifications.length)
            return;
        const { config, reservedRef } = this.reservedNotifications.shift();
        const displayedRef = this.displayNotification(config);
        this.handleReservedNotificationCounter();
        reservedRef.close = displayedRef.close;
    }
    handleReservedNotificationCounter() {
        const reservedCount = this.reservedNotifications.length;
        if (reservedCount === this.reserveCounter)
            return;
        this.reserveCounter = reservedCount;
        if (reservedCount === 0 && this.notificationCounterElement !== null) {
            this.notificationCounterElement.close();
            return;
        }
        if (reservedCount > 0) {
            if (this.notificationCounterElement !== null) {
                this.notificationCounterElement.close();
            }
            this.createReservedCounternotification();
        }
    }
    async createReservedCounternotification() {
        const opt = {
            closeButton: false,
            color: this.moreNotificationsColor,
            location: this.moreNotificationsLocation,
            title: await this.translationService.translateAsync('@acorex:common.notifications.more', {
                params: { number: this.reserveCounter },
            }),
            timeOutProgress: false,
        };
        const gap = this.defaultConfig.gap;
        const pos = this.getPosition(opt.location) + gap + 'px';
        const positionStrategy = this.getPositionStrategy(new GlobalPositionStrategy(), opt.location, pos, gap);
        const dialogRef = this.dialog.open(AXNotificationComponent, {
            data: opt,
            autoFocus: '__no_element__',
            restoreFocus: true,
            role: 'dialog',
            ariaModal: true,
            closeOnNavigation: true,
            closeOnDestroy: true,
            hasBackdrop: false,
            panelClass: ['ax-animate-animated', 'ax-animate-fadeIn', 'ax-animate-faster'],
            positionStrategy,
        });
        this.notificationCounterElement = dialogRef.componentInstance;
    }
    reposition(notificationLocation, gap) {
        const list = this.dialog.openDialogs
            .map((c) => c.componentInstance)
            .filter((c) => c.config?.location == notificationLocation);
        list.forEach((element, index) => {
            const pos = this.getRepositionPosition(index, gap, list, notificationLocation);
            this.getPositionStrategy(element.dialogRef.config.positionStrategy, notificationLocation, pos, gap).apply();
        });
    }
    getRepositionPosition(index, gap, list, notificationLocation) {
        if (index === 0)
            return gap + 'px';
        const previouseElement = list[index - 1];
        if (notificationLocation.split('-')[0] == 'bottom') {
            return window.innerHeight - previouseElement.getHostElement().offsetTop + gap + 'px';
        }
        return previouseElement.getHostElement().offsetTop + previouseElement.getHostElement().offsetHeight + gap + 'px';
    }
    getPosition(location) {
        const list = this.dialog.openDialogs
            .map((c) => c.componentInstance)
            .filter((c) => c.config.location == location);
        if (list.length == 0)
            return 0;
        if (location.split('-')[0] == 'bottom') {
            return window.innerHeight - list[list.length - 1].getHostElement().offsetTop;
        }
        return list[list.length - 1].getHostElement().offsetTop + list[list.length - 1].getHostElement().offsetHeight;
    }
    getPositionStrategy(positionStrategy, location, pos, gap) {
        switch (location) {
            case 'bottom-center':
                return positionStrategy.bottom(pos).centerHorizontally();
                break;
            case 'bottom-end':
                return positionStrategy.bottom(pos).right(gap + 'px');
                break;
            case 'bottom-start':
                return positionStrategy.bottom(pos).left(gap + 'px');
                break;
            case 'top-center':
                return positionStrategy.top(pos).centerHorizontally();
                break;
            case 'top-end':
                return positionStrategy.top(pos).right(gap + 'px');
                break;
            case 'top-start':
                return positionStrategy.top(pos).left(gap + 'px');
                break;
            case 'center-start':
                return positionStrategy.centerVertically().left(gap + 'px');
                break;
            case 'center-end':
                return positionStrategy.centerVertically().right(gap + 'px');
                break;
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXNotificationService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }] });

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

export { AXNotificationComponent, AXNotificationDefaultConfig, AXNotificationModule, AXNotificationService, AX_NOTIFICATION_CONFIG, notificationConfig };
//# sourceMappingURL=acorex-components-notification.mjs.map
