import { MXBaseComponent, AXHotkeyDirective, AXAutoFocusDirective, AXComponent } from '@acorex/cdk/common';
import { AXButtonComponent } from '@acorex/components/button';
import { AXDecoratorGenericComponent } from '@acorex/components/decorators';
import { AXLoadingComponent } from '@acorex/components/loading';
import { AXProgressBarComponent } from '@acorex/components/progress-bar';
import { AXTranslatorPipe } from '@acorex/core/translation';
import { DIALOG_DATA, DialogRef, Dialog } from '@angular/cdk/dialog';
import { AsyncPipe } from '@angular/common';
import * as i0 from '@angular/core';
import { inject, signal, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule, Injectable } from '@angular/core';

/**
 * Represents a loading dialog component with custom styles and encapsulation.
 * @category components
 */
class AXLoadingDialogComponent extends MXBaseComponent {
    constructor() {
        super(...arguments);
        this.data = inject(DIALOG_DATA);
        this.dialogRef = inject(DialogRef);
        /** @ignore */
        this.progressText = signal(this.data.text, ...(ngDevMode ? [{ debugName: "progressText" }] : []));
        /** @ignore */
        this.progressStatus = signal(this.data.status, ...(ngDevMode ? [{ debugName: "progressStatus" }] : []));
        /** @ignore */
        this.progressColor = signal(this.data.progressColor, ...(ngDevMode ? [{ debugName: "progressColor" }] : []));
        /** @ignore */
        this.dialogTitle = signal(this.data.title, ...(ngDevMode ? [{ debugName: "dialogTitle" }] : []));
        /** @ignore */
        this.progressValue = signal(this.data.progressValue, ...(ngDevMode ? [{ debugName: "progressValue" }] : []));
    }
    /**
     * Closes the loading dialog.
     *
     * @returns void - No return value. The dialog is closed and control returns to the caller.
     */
    close() {
        this.dialogRef.close();
    }
    /**
     * Sets the displayed progress text inside the dialog.
     *
     * @param text The text to display under the progress bar.
     * @returns void
     */
    setProgressText(text) {
        this.progressText.set(text);
    }
    /**
     * Sets the status text, typically representing the current step out of total steps (e.g., "5/10").
     *
     * @param status The status text to display.
     * @returns void
     */
    setProgressStatus(status) {
        this.progressStatus.set(status);
    }
    /**
     * Sets the color used by the progress indicator.
     *
     * @param color The color token to apply to the progress UI.
     * @returns void
     */
    setProgressColor(color) {
        this.progressColor.set(color);
    }
    /**
     * Sets the dialog title text.
     *
     * @param text The title text to display at the top of the dialog.
     * @returns void
     */
    setDialogTitle(text) {
        this.dialogTitle.set(text);
    }
    /**
     * Sets the numeric progress value.
     *
     * @param value A number in the range 0–100 representing the current progress.
     * @returns void
     */
    setProgressValue(value) {
        this.progressValue.set(value);
    }
    /** @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;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXLoadingDialogComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.9", type: AXLoadingDialogComponent, isStandalone: true, selector: "ax-loading-dialog", providers: [{ provide: AXComponent, useExisting: AXLoadingDialogComponent }], usesInheritance: true, ngImport: i0, template: "<ax-title>{{ dialogTitle() }}</ax-title>\n\n<ax-progress-bar [mode]=\"data.mode\" [progress]=\"this.progressValue()\" [color]=\"progressColor()\"></ax-progress-bar>\n<div class=\"progress-decorators\">\n  <div>{{ progressText() }}</div>\n  <div>{{ progressStatus() }}</div>\n</div>\n<ax-footer>\n  @for (button of data.buttons; track $index) {\n    <ax-button\n      [text]=\"button.text | translate | async\"\n      [tabindex]=\"$index\"\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", styles: ["ax-loading-dialog{display:flex;flex-direction:column;gap:.5rem;width:33vw;background-color:rgba(var(--ax-comp-loading-dialog-bg-color, var(--ax-sys-color-lightest-surface)));padding:1rem;border-radius:var(--ax-comp-loading-dialog-border-radius, var(--ax-sys-border-radius))}ax-loading-dialog ax-title{font-weight:500;font-size:1rem;margin-bottom:.5rem}@media (min-width: 320px) and (max-width: 640px){ax-loading-dialog{width:93vw!important}}@media (min-width: 768px){ax-loading-dialog{width:55vw!important}}@media (min-width: 1280px){ax-loading-dialog{width:30vw!important}}@media (min-width: 1536px){ax-loading-dialog{width:25vw!important}}ax-loading-dialog .progress-decorators{display:flex;justify-content:space-between;font-size:.875rem}ax-loading-dialog ax-footer{justify-content:flex-end;padding-top:.75rem}\n"], dependencies: [{ 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: AXProgressBarComponent, selector: "ax-progress-bar", inputs: ["color", "mode", "progress", "height"], outputs: ["ValueChange", "sizeChange"] }, { 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: AXTranslatorPipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXLoadingDialogComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-loading-dialog', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, imports: [
                        AXDecoratorGenericComponent,
                        AXProgressBarComponent,
                        AXButtonComponent,
                        AXHotkeyDirective,
                        AXAutoFocusDirective,
                        AXLoadingComponent,
                        AXTranslatorPipe,
                        AsyncPipe,
                    ], providers: [{ provide: AXComponent, useExisting: AXLoadingDialogComponent }], template: "<ax-title>{{ dialogTitle() }}</ax-title>\n\n<ax-progress-bar [mode]=\"data.mode\" [progress]=\"this.progressValue()\" [color]=\"progressColor()\"></ax-progress-bar>\n<div class=\"progress-decorators\">\n  <div>{{ progressText() }}</div>\n  <div>{{ progressStatus() }}</div>\n</div>\n<ax-footer>\n  @for (button of data.buttons; track $index) {\n    <ax-button\n      [text]=\"button.text | translate | async\"\n      [tabindex]=\"$index\"\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", styles: ["ax-loading-dialog{display:flex;flex-direction:column;gap:.5rem;width:33vw;background-color:rgba(var(--ax-comp-loading-dialog-bg-color, var(--ax-sys-color-lightest-surface)));padding:1rem;border-radius:var(--ax-comp-loading-dialog-border-radius, var(--ax-sys-border-radius))}ax-loading-dialog ax-title{font-weight:500;font-size:1rem;margin-bottom:.5rem}@media (min-width: 320px) and (max-width: 640px){ax-loading-dialog{width:93vw!important}}@media (min-width: 768px){ax-loading-dialog{width:55vw!important}}@media (min-width: 1280px){ax-loading-dialog{width:30vw!important}}@media (min-width: 1536px){ax-loading-dialog{width:25vw!important}}ax-loading-dialog .progress-decorators{display:flex;justify-content:space-between;font-size:.875rem}ax-loading-dialog ax-footer{justify-content:flex-end;padding-top:.75rem}\n"] }]
        }] });

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

class AXLoadingDialogService {
    constructor() {
        this.dialog = inject(Dialog);
    }
    // private data$: BehaviorSubject<AXLoadingDialogConfig> = new BehaviorSubject<AXLoadingDialogConfig>(null);
    /**
     * Opens a loading dialog with the specified configuration.
     *
     * @param options Configuration for the loading dialog, including title, progress mode, and optional initial values.
     * @returns AXDialogRef - A reference with helper methods to control the dialog lifecycle and UI (close, setProgressValue, setProgressText, setDialogTitle, setProgressColor, setProgressStatus).
     */
    show(options) {
        const dialogRef = this.dialog.open(AXLoadingDialogComponent, {
            hasBackdrop: true,
            disableClose: true,
            restoreFocus: true,
            closeOnDestroy: true,
            closeOnNavigation: true,
            ariaModal: true,
            role: 'alertdialog',
            panelClass: ['ax-animate-fadeIn'],
            data: options,
        });
        return {
            close: () => dialogRef.componentInstance?.close(),
            setProgressValue: (value) => dialogRef.componentInstance?.setProgressValue(value),
            setDialogTitle: (text) => dialogRef.componentInstance?.setDialogTitle(text),
            setProgressText: (text) => dialogRef.componentInstance?.setProgressText(text),
            setProgressStatus: (status) => dialogRef.componentInstance?.setProgressStatus(status),
            setProgressColor: (color) => dialogRef.componentInstance?.setProgressColor(color),
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXLoadingDialogService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXLoadingDialogService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXLoadingDialogService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }] });

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

export { AXLoadingDialogComponent, AXLoadingDialogModule, AXLoadingDialogService };
//# sourceMappingURL=acorex-components-loading-dialog.mjs.map
