import { MXBaseComponent, AXHotkeyDirective, AXAutoFocusDirective, AXClosableComponent, AXComponent, AXCommonModule, AXHotkeysService } from '@acorex/cdk/common';
import { AXButtonComponent, AXButtonModule } from '@acorex/components/button';
import { AXDecoratorGenericComponent, AXDecoratorModule } from '@acorex/components/decorators';
import { AXLoadingComponent, AXLoadingModule } from '@acorex/components/loading';
import { AXTranslatorPipe, AXTranslationModule } from '@acorex/core/translation';
import { DIALOG_DATA, DialogRef, Dialog, DialogModule } from '@angular/cdk/dialog';
import { CdkDrag, CdkDragHandle, DragDropModule } from '@angular/cdk/drag-drop';
import { AsyncPipe, CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { inject, HostBinding, ViewEncapsulation, ChangeDetectionStrategy, Component, InjectionToken, Injectable, NgModule } from '@angular/core';
import { A11yModule } from '@angular/cdk/a11y';
import { AXHtmlUtil } from '@acorex/core/utils';
import { AX_GLOBAL_CONFIG } from '@acorex/core/config';
import { set } from 'lodash-es';

/**
 * A dialog component that provides a modal interface for user interactions.
 * @category Components
 */
class AXDialogComponent extends MXBaseComponent {
    constructor() {
        super(...arguments);
        this.data = inject(DIALOG_DATA);
        this.dialogRef = inject(DialogRef);
    }
    /**
     *  @ignore
     */
    _handleButtonClick(button) {
        if (button.onClick) {
            button.onClick({ source: button });
        }
    }
    /**
     *  @ignore
     */
    _hasAutoFocus(button) {
        const autoFocusItem = this.data.buttons.find((item) => item.autofocus === true);
        if (autoFocusItem && autoFocusItem.text === button.text) {
            return true;
        }
        if (!autoFocusItem) {
            if (this.data.buttons.length > 0) {
                this.data.buttons[0].autofocus = true;
                return this.data.buttons[0].text === button.text;
            }
        }
        return false;
    }
    /**
     * Closes the dialog.
     *
     * @returns void - No return value. The dialog is closed and removed from the DOM.
     */
    close() {
        this.dialogRef.close();
    }
    /**
     *  @ignore
     */
    get tabIndex() {
        return '-1';
    }
    /** @ignore */
    get __hostClass() {
        return `ax-${this.data.type}`;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXDialogComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.9", type: AXDialogComponent, isStandalone: true, selector: "ax-dialog", host: { properties: { "attr.tabIndex": "this.tabIndex", "class": "this.__hostClass" } }, providers: [
            {
                provide: AXClosableComponent,
                useExisting: AXDialogComponent,
            },
            {
                provide: AXComponent,
                useExisting: AXDialogComponent,
            },
        ], usesInheritance: true, ngImport: i0, template: "<div\n  class=\"ax-dialog ax-orientation-{{ data.orientation }}\"\n  tabindex=\"-1\"\n  cdkDrag\n  cdkDragHandle\n  [cdkDragDisabled]=\"!data.draggable\"\n>\n  <div class=\"ax-dialog-content-wrapper\">\n    @if (data.icon !== 'none') {\n      <div class=\"ax-dialog-icon-side\">\n        <i class=\"ax-dialog-icon {{ data.icon }}\"></i>\n      </div>\n    }\n    <div class=\"ax-dialog-content-side\">\n      <div class=\"ax-dialog-title\">{{ data.title }}</div>\n      <div class=\"ax-dialog-content\">{{ data.content }}</div>\n    </div>\n    <div class=\"ax-dialog-dismiss-icon\">\n      @if (data.closeButton) {\n        <i class=\"ax-icon ax-icon-close\"></i>\n      }\n    </div>\n  </div>\n\n  <ax-footer>\n    @for (button of data.buttons; let i = $index; track i) {\n      <ax-button\n        [text]=\"button.text | translate | async\"\n        [tabindex]=\"i\"\n        [axHotkey]=\"button.hotkey\"\n        [axAutoFocus]=\"_hasAutoFocus(button)\"\n        (onClick)=\"_handleButtonClick(button)\"\n        [look]=\"button.look\"\n        [disabled]=\"button.disabled\"\n        [color]=\"button.color\"\n      >\n        @if (button.loading) {\n          <ax-loading></ax-loading>\n        }\n      </ax-button>\n    }\n  </ax-footer>\n</div>\n", styles: ["ax-dialog.ax-primary{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-primary-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-primary-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-primary-surface)}ax-dialog.ax-secondary{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-secondary-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-secondary-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-secondary-surface)}ax-dialog.ax-success{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-success-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-success-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-success-surface)}ax-dialog.ax-warning{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-warning-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-warning-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-warning-surface)}ax-dialog.ax-danger{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-danger-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-danger-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-danger-surface)}ax-dialog.ax-accent1{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent1-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent1-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent1-surface)}ax-dialog.ax-accent2{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent2-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent2-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent2-surface)}ax-dialog.ax-accent3{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent3-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent3-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent3-surface)}ax-dialog.ax-accent4{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent4-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent4-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent4-surface)}ax-dialog.ax-accent5{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent5-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent5-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent5-surface)}ax-dialog.ax-accent6{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent6-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent6-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent6-surface)}ax-dialog.ax-accent7{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent7-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent7-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent7-surface)}.ax-dialog{position:relative;display:flex;width:93vw;flex-direction:column;overflow:hidden;border-radius:var(--ax-sys-border-radius);border-width:1px;border-color:rgba(var(--ax-sys-color-border-lightest-surface));background-color:rgba(var(--ax-sys-color-lightest-surface));color:rgba(var(--ax-sys-color-on-lightest-surface));outline:2px solid transparent;outline-offset:2px}@media (min-width: 768px){.ax-dialog{width:75vw}}@media (min-width: 1024px){.ax-dialog{width:50vw}}@media (min-width: 1280px){.ax-dialog{width:35vw}}@media (min-width: 1536px){.ax-dialog{width:25vw}}.ax-dialog.ax-orientation-horizontal .ax-dialog-content-wrapper{flex-direction:row}.ax-dialog.ax-orientation-vertical .ax-dialog-content-wrapper{flex-direction:column;align-items:center}.ax-dialog.ax-orientation-vertical .ax-dialog-content-wrapper .ax-dialog-icon-side{margin-bottom:1rem}.ax-dialog.ax-orientation-vertical .ax-dialog-content-wrapper .ax-dialog-content-side{margin:0;text-align:center}.ax-dialog.ax-orientation-vertical ax-footer ax-button{flex:1 1 0%}.ax-dialog .ax-dialog-content-wrapper{display:flex;gap:.5rem;padding:1.5rem 1.5rem 1rem}.ax-dialog .ax-dialog-content-wrapper .ax-dialog-icon-side .ax-dialog-icon{background-color:rgba(var(--ax-comp-dialog-icon-bg-color));color:rgba(var(--ax-comp-dialog-icon-text-color));border-width:1px;border-color:rgba(var(--ax-comp-dialog-border-color));border-style:solid;display:flex;height:3rem;width:3rem;cursor:move;align-items:center;justify-content:center;border-radius:9999px;font-size:1.5rem;line-height:2rem}.ax-dialog .ax-dialog-content-wrapper .ax-dialog-content-side{margin-inline-start:1rem;flex:1 1 0%}.ax-dialog .ax-dialog-content-wrapper .ax-dialog-content-side .ax-dialog-title{margin-bottom:.5rem;font-size:1.125rem;line-height:1.5rem;font-weight:500}.ax-dialog .ax-dialog-content-wrapper .ax-dialog-content-side .ax-dialog-content{font-size:.875rem;line-height:1.25rem}.ax-dialog ax-footer{justify-content:flex-end;padding:.75rem 1.5rem}\n"], dependencies: [{ kind: "directive", type: CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer", "cdkDragScale"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { kind: "component", type: AXDecoratorGenericComponent, selector: "ax-footer, ax-header, ax-content, ax-divider, ax-form-hint, ax-prefix, ax-suffix, ax-text, ax-title, ax-subtitle, ax-placeholder, ax-overlay" }, { 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: "directive", type: AXHotkeyDirective, selector: "[axHotkey]", inputs: ["axHotkey"] }, { kind: "directive", type: AXAutoFocusDirective, selector: "[axAutoFocus]", inputs: ["axAutoFocus", "axAutoFocusTime"] }, { kind: "component", type: AXLoadingComponent, selector: "ax-loading", inputs: ["visible", "type", "context"], outputs: ["visibleChange"] }, { 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: AXDialogComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-dialog', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [
                        {
                            provide: AXClosableComponent,
                            useExisting: AXDialogComponent,
                        },
                        {
                            provide: AXComponent,
                            useExisting: AXDialogComponent,
                        },
                    ], imports: [
                        CdkDrag,
                        CdkDragHandle,
                        AXDecoratorGenericComponent,
                        AXButtonComponent,
                        AXHotkeyDirective,
                        AXAutoFocusDirective,
                        AXLoadingComponent,
                        AsyncPipe,
                        AXTranslatorPipe,
                    ], template: "<div\n  class=\"ax-dialog ax-orientation-{{ data.orientation }}\"\n  tabindex=\"-1\"\n  cdkDrag\n  cdkDragHandle\n  [cdkDragDisabled]=\"!data.draggable\"\n>\n  <div class=\"ax-dialog-content-wrapper\">\n    @if (data.icon !== 'none') {\n      <div class=\"ax-dialog-icon-side\">\n        <i class=\"ax-dialog-icon {{ data.icon }}\"></i>\n      </div>\n    }\n    <div class=\"ax-dialog-content-side\">\n      <div class=\"ax-dialog-title\">{{ data.title }}</div>\n      <div class=\"ax-dialog-content\">{{ data.content }}</div>\n    </div>\n    <div class=\"ax-dialog-dismiss-icon\">\n      @if (data.closeButton) {\n        <i class=\"ax-icon ax-icon-close\"></i>\n      }\n    </div>\n  </div>\n\n  <ax-footer>\n    @for (button of data.buttons; let i = $index; track i) {\n      <ax-button\n        [text]=\"button.text | translate | async\"\n        [tabindex]=\"i\"\n        [axHotkey]=\"button.hotkey\"\n        [axAutoFocus]=\"_hasAutoFocus(button)\"\n        (onClick)=\"_handleButtonClick(button)\"\n        [look]=\"button.look\"\n        [disabled]=\"button.disabled\"\n        [color]=\"button.color\"\n      >\n        @if (button.loading) {\n          <ax-loading></ax-loading>\n        }\n      </ax-button>\n    }\n  </ax-footer>\n</div>\n", styles: ["ax-dialog.ax-primary{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-primary-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-primary-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-primary-surface)}ax-dialog.ax-secondary{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-secondary-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-secondary-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-secondary-surface)}ax-dialog.ax-success{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-success-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-success-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-success-surface)}ax-dialog.ax-warning{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-warning-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-warning-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-warning-surface)}ax-dialog.ax-danger{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-danger-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-danger-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-danger-surface)}ax-dialog.ax-accent1{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent1-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent1-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent1-surface)}ax-dialog.ax-accent2{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent2-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent2-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent2-surface)}ax-dialog.ax-accent3{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent3-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent3-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent3-surface)}ax-dialog.ax-accent4{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent4-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent4-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent4-surface)}ax-dialog.ax-accent5{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent5-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent5-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent5-surface)}ax-dialog.ax-accent6{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent6-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent6-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent6-surface)}ax-dialog.ax-accent7{--ax-comp-dialog-icon-bg-color: var(--ax-sys-color-accent7-surface);--ax-comp-dialog-icon-text-color: var(--ax-sys-color-on-accent7-surface);--ax-comp-dialog-border-color: var(--ax-sys-color-border-accent7-surface)}.ax-dialog{position:relative;display:flex;width:93vw;flex-direction:column;overflow:hidden;border-radius:var(--ax-sys-border-radius);border-width:1px;border-color:rgba(var(--ax-sys-color-border-lightest-surface));background-color:rgba(var(--ax-sys-color-lightest-surface));color:rgba(var(--ax-sys-color-on-lightest-surface));outline:2px solid transparent;outline-offset:2px}@media (min-width: 768px){.ax-dialog{width:75vw}}@media (min-width: 1024px){.ax-dialog{width:50vw}}@media (min-width: 1280px){.ax-dialog{width:35vw}}@media (min-width: 1536px){.ax-dialog{width:25vw}}.ax-dialog.ax-orientation-horizontal .ax-dialog-content-wrapper{flex-direction:row}.ax-dialog.ax-orientation-vertical .ax-dialog-content-wrapper{flex-direction:column;align-items:center}.ax-dialog.ax-orientation-vertical .ax-dialog-content-wrapper .ax-dialog-icon-side{margin-bottom:1rem}.ax-dialog.ax-orientation-vertical .ax-dialog-content-wrapper .ax-dialog-content-side{margin:0;text-align:center}.ax-dialog.ax-orientation-vertical ax-footer ax-button{flex:1 1 0%}.ax-dialog .ax-dialog-content-wrapper{display:flex;gap:.5rem;padding:1.5rem 1.5rem 1rem}.ax-dialog .ax-dialog-content-wrapper .ax-dialog-icon-side .ax-dialog-icon{background-color:rgba(var(--ax-comp-dialog-icon-bg-color));color:rgba(var(--ax-comp-dialog-icon-text-color));border-width:1px;border-color:rgba(var(--ax-comp-dialog-border-color));border-style:solid;display:flex;height:3rem;width:3rem;cursor:move;align-items:center;justify-content:center;border-radius:9999px;font-size:1.5rem;line-height:2rem}.ax-dialog .ax-dialog-content-wrapper .ax-dialog-content-side{margin-inline-start:1rem;flex:1 1 0%}.ax-dialog .ax-dialog-content-wrapper .ax-dialog-content-side .ax-dialog-title{margin-bottom:.5rem;font-size:1.125rem;line-height:1.5rem;font-weight:500}.ax-dialog .ax-dialog-content-wrapper .ax-dialog-content-side .ax-dialog-content{font-size:.875rem;line-height:1.25rem}.ax-dialog ax-footer{justify-content:flex-end;padding:.75rem 1.5rem}\n"] }]
        }], propDecorators: { tabIndex: [{
                type: HostBinding,
                args: ['attr.tabIndex']
            }], __hostClass: [{
                type: HostBinding,
                args: ['class']
            }] } });

const AX_DIALOG_CONFIG = new InjectionToken('AX_DIALOG_CONFIG', {
    providedIn: 'root',
    factory: () => {
        const global = inject(AX_GLOBAL_CONFIG);
        set(global, 'layout.dialog', AX_DIALOG_CONFIG);
        return AXDialogDefaultConfig;
    },
});
const AXDialogDefaultConfig = {
    confirm: { defaultAction: 'cancel' },
};
function dialogConfig(config = {}) {
    const result = {
        ...AXDialogDefaultConfig,
        ...config,
    };
    return result;
}

/**
 * The Button is a component which detects user interaction and triggers a corresponding event
 *
 * @category Components
 */
class AXDialogService {
    constructor() {
        this.dialog = inject(Dialog);
        this.defaultConfig = inject(AX_DIALOG_CONFIG);
    }
    detectIcon(type) {
        let icon;
        switch (type) {
            case 'success':
                icon = 'ax-icon ax-icon-check';
                break;
            case 'danger':
                icon = 'ax-icon ax-icon-error';
                break;
            case 'warning':
                icon = 'ax-icon ax-icon-warning';
                break;
            default:
                icon = 'ax-icon ax-icon-info';
                break;
        }
        return icon;
    }
    /**
     * Show an alert box with 'Okay' button.
     *
     * @param title - The title of the alert dialog.
     * @param content - The content message of the alert dialog.
     * @param type - The type/color of the alert (primary, success, warning, danger).
     * @param orientation - The orientation of the dialog (horizontal or vertical).
     * @param draggable - Whether the dialog can be dragged.
     * @returns Promise<void> - Promise that resolves when the dialog is closed.
     */
    alert(title, content, type = 'primary', orientation = 'horizontal', draggable) {
        return new Promise((resolve) => {
            const popup = this.open({
                title,
                type: type,
                content,
                icon: this.detectIcon(type),
                orientation,
                draggable,
                buttons: [
                    {
                        name: 'confirm',
                        text: AXHtmlUtil.isRtl() ? 'باشه' : 'Okay',
                        color: type,
                        autofocus: true,
                        onClick: () => {
                            popup.close();
                            if (resolve) {
                                resolve();
                            }
                        },
                    },
                ],
            });
        });
    }
    /**
     * Show a confirm box with 'Okay' & 'Cancel' buttons.
     *
     * @param title - The title of the confirm dialog.
     * @param content - The content message of the confirm dialog.
     * @param type - The type/color of the confirm dialog (primary, success, warning, danger).
     * @param orientation - The orientation of the dialog (horizontal or vertical).
     * @param draggable - Whether the dialog can be dragged.
     * @param defaultAction - The default action to focus (confirm or cancel).
     * @returns Promise<{ result: boolean }> - Promise that resolves with the user's choice.
     */
    confirm(title, content, type = 'primary', orientation = 'horizontal', draggable, defaultAction) {
        return new Promise((resolve) => {
            const tokenConfig = this.defaultConfig.confirm.defaultAction;
            const action = defaultAction || (type === 'danger' ? 'cancel' : tokenConfig);
            const popup = this.open({
                title,
                content,
                type,
                icon: this.detectIcon(type),
                orientation,
                draggable,
                buttons: [
                    {
                        name: 'confirm',
                        text: AXHtmlUtil.isRtl() ? 'باشه' : 'Okay',
                        color: type,
                        autofocus: action === 'confirm',
                        onClick: () => {
                            popup.close();
                            if (resolve) {
                                resolve({ result: true });
                            }
                        },
                    },
                    {
                        name: 'cancel',
                        text: AXHtmlUtil.isRtl() ? 'انصراف' : 'Cancel',
                        color: 'default',
                        autofocus: action === 'cancel',
                        onClick: () => {
                            popup.close();
                            if (resolve) {
                                resolve({ result: false });
                            }
                        },
                        hotkey: {
                            Escape: () => {
                                popup.close();
                                if (resolve) {
                                    resolve({ result: false });
                                }
                            },
                        },
                    },
                ],
            });
        });
    }
    /**
     * Show a custom dialog box.
     *
     * @param options - Configuration options for the custom dialog.
     * @returns Promise<{ name: string }> - Promise that resolves with the button name that was clicked.
     */
    show(options) {
        return new Promise((resolve) => {
            options.orientation = options.orientation || 'horizontal';
            options.icon = options.icon ?? this.detectIcon(options.type);
            const popup = this.open(options);
            options.buttons?.forEach((b) => {
                const orginalClick = b.onClick;
                b.onClick = () => {
                    const e = { source: b, handled: false };
                    if (orginalClick) {
                        orginalClick(e);
                        if (e.handled) {
                            resolve({ name: b.name ?? b.text });
                        }
                        else {
                            popup.close();
                            resolve({ name: b.name ?? b.text });
                        }
                    }
                    else if (resolve) {
                        popup.close();
                        resolve({ name: b.name ?? b.text });
                    }
                    else {
                        popup.close();
                    }
                };
            });
        });
    }
    /**
     * Show a custom dialog box.
     *
     * @param options - Configuration options for the custom dialog.
     * @returns Promise<{ name: string }> - Promise that resolves with the button name that was clicked.
     */
    open(config) {
        config.orientation = config.orientation || 'horizontal';
        config.icon = config.icon ?? this.detectIcon(config.type);
        const dialogRef = this.dialog.open(AXDialogComponent, {
            data: config,
            role: 'alertdialog',
            ariaModal: true,
            restoreFocus: true,
            closeOnNavigation: true,
            closeOnDestroy: true,
            hasBackdrop: true,
            disableClose: true,
            panelClass: ['ax-animate-bounceIn', 'ax-animate-faster'],
            direction: config.direction ? config.direction : AXHtmlUtil.isRtl() ? 'rtl' : 'ltr',
        });
        return {
            close: () => {
                dialogRef.componentInstance?.close();
            },
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXDialogService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXDialogService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXDialogService, decorators: [{
            type: Injectable
        }] });

const COMPONENT = [AXDialogComponent];
const MODULES = [
    CommonModule,
    AXCommonModule,
    DragDropModule,
    A11yModule,
    AXButtonModule,
    AXDecoratorModule,
    AXLoadingModule,
    DialogModule,
    AXTranslationModule,
];
class AXDialogModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXDialogModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.9", ngImport: i0, type: AXDialogModule, imports: [CommonModule,
            AXCommonModule,
            DragDropModule,
            A11yModule,
            AXButtonModule,
            AXDecoratorModule,
            AXLoadingModule,
            DialogModule,
            AXTranslationModule, AXDialogComponent], exports: [AXDialogComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXDialogModule, providers: [AXDialogService, AXHotkeysService], imports: [MODULES, COMPONENT] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXDialogModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [...MODULES, ...COMPONENT],
                    exports: [...COMPONENT],
                    providers: [AXDialogService, AXHotkeysService],
                }]
        }] });

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

export { AXDialogComponent, AXDialogModule, AXDialogService };
//# sourceMappingURL=acorex-components-dialog.mjs.map
