import * as i0 from '@angular/core';
import { inject, Injectable, EventEmitter, ViewContainerRef, booleanAttribute, forwardRef, ContentChild, ViewChild, Output, Input, ViewEncapsulation, ChangeDetectionStrategy, Component, Directive } from '@angular/core';
import { TemplatePortal, PortalModule } from '@angular/cdk/portal';
import { Subject } from 'rxjs';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { TranslateModule } from '@ngx-translate/core';
import { OverlayModule } from '@angular/cdk/overlay';
import { A11yModule } from '@angular/cdk/a11y';
import { DragDropModule } from '@angular/cdk/drag-drop';
import * as i1 from '@eui/components/shared';
import { BaseStatesDirective } from '@eui/components/shared';
import { EuiDialogService } from '@eui/components/eui-dialog';

/**
 * @description
 * Service for programmatically creating, opening, and controlling message boxes in the eui application.
 *
 * The EuiMessageBoxService wraps the EuiDialogService to provide a simplified API specifically
 * for message box functionality. Message boxes are specialized dialog windows typically used
 * for alerts, confirmations, and prompts.
 *
 * The service handles the configuration of common message box properties and delegates to the
 * underlying dialog service for rendering.
 *
 *
 * @see EuiMessageBoxComponent
 * @see EuiDialogService
 */
class EuiMessageBoxService {
    constructor() {
        this.euiDialogService = inject(EuiDialogService);
    }
    /**
     * Opens a message box with the specified configuration.
     *
     * This method sets default message box properties and delegates to the dialog service
     * to render the message box. Message boxes don't close on outside click or escape key,
     * and have no header component or close button by default.
     *
     * @param config - Configuration options for the message box
     * @typeParam HC - Header content type
     * @typeParam HCC - Header component context type
     * @typeParam BC - Body content type
     * @typeParam BCC - Body component context type
     * @typeParam FC - Footer content type
     * @typeParam FCC - Footer component context type
     */
    openMessageBox(config = {}) {
        this.euiDialogService.openDialog({
            ...config,
            header: null,
            headerComponent: null,
            hasClosedOnClickOutside: false,
            hasCloseButton: false,
            hasClosedOnEscape: false,
            hasFooter: true,
        });
    }
    /**
     * Closes the currently active message box.
     *
     * This method delegates to the dialog service to close any open dialog.
     */
    closeMessageBox() {
        this.euiDialogService.closeDialog();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: EuiMessageBoxService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: EuiMessageBoxService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: EuiMessageBoxService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

/**
 * @description
 * Component for displaying modal message boxes with structured content and customizable actions.
 * This component provides a user-friendly interface for confirmation dialogs, alerts, and other
 * types of modal messages.
 *
 * The component supports various styling variants through the BaseStatesDirective hostDirective,
 * customizable buttons, and configurable behavior for dialog actions.
 *
 * @usageNotes
 * ### Basic Usage
 * ```html
 * <eui-message-box #messageBox
 *   title="Confirm Action"
 *   (accept)="onConfirm()"
 *   (dismiss)="onCancel()">
 *   Are you sure you want to proceed?
 * </eui-message-box>
 * ```
 *
 * ```typescript
 * @ViewChild('messageBox') messageBox: EuiMessageBoxComponent;
 *
 * showMessage() {
 *   this.messageBox.openMessageBox();
 * }
 * ```
 *
 * ### With Custom Footer
 * ```html
 * <eui-message-box title="Custom Actions">
 *   <p>Message content</p>
 *   <eui-message-box-footer>
 *     <button euiButton>Custom Action</button>
 *   </eui-message-box-footer>
 * </eui-message-box>
 * ```
 *
 * ### Accessibility
 * - Modal traps focus within the dialog
 * - Escape key closes the dialog by default
 * - Accept/Dismiss buttons are keyboard accessible
 *
 * ### Notes
 * - Use `openMessageBox()` and `closeMessageBox()` methods to control visibility
 * - Supports draggable positioning with `isDraggable` input
 * - Variant styling (primary, danger, warning, etc.) via BaseStatesDirective
 */
class EuiMessageBoxComponent {
    constructor() {
        /**
         * Data attribute for e2e testing purposes.
         * @default 'eui-dialog'
         */
        this.e2eAttr = 'eui-dialog';
        /**
         * Width of the message box.
         * @default '33rem'
         */
        this.width = '33rem';
        /**
         * Height of the message box.
         * @default 'auto'
         */
        this.height = 'auto';
        /**
         * Whether to show the accept/confirm button.
         * @default true
         */
        this.hasAcceptButton = true;
        /**
         * Whether to show the dismiss/cancel button.
         * @default true
         */
        this.hasDismissButton = true;
        /**
         * Label for the accept/confirm button. Can be a translation key.
         * @default 'eui.OK'
         */
        this.acceptLabel = 'eui.OK';
        /**
         * Label for the dismiss/cancel button. Can be a translation key.
         * @default 'eui.CANCEL'
         */
        this.dismissLabel = 'eui.CANCEL';
        /**
         * Whether to manually handle closing the dialog on dismiss button click.
         * @default false
         */
        this.isHandleCloseOnDismiss = false;
        /**
         * Whether to manually handle closing the dialog on close button click.
         * @default false
         */
        this.isHandleCloseOnClose = false;
        /**
         * Whether to manually handle closing the dialog on accept button click.
         * @default false
         */
        this.isHandleCloseOnAccept = false;
        /**
         * Whether the message box can be dragged around the screen.
         * @default false
         */
        this.isDraggable = false;
        /**
         * Whether to remove padding from the message box body.
         * @default false
         */
        this.hasNoBodyPadding = false;
        /**
         * Event emitted when the message box opens.
         */
        this.messageBoxOpen = new EventEmitter();
        /**
         * Event emitted when the message box closes.
         */
        this.messageBoxClose = new EventEmitter();
        /**
         * Event emitted when the dismiss/cancel button is clicked.
         */
        this.dismiss = new EventEmitter();
        /**
         * Event emitted when the accept/confirm button is clicked.
         */
        this.accept = new EventEmitter();
        this.baseStatesDirective = inject(BaseStatesDirective);
        /**
         * Subject used for cleaning up subscriptions when the component is destroyed.
         */
        this.destroy$ = new Subject();
        this.viewContainerRef = inject(ViewContainerRef);
        this.euiMessageBoxService = inject(EuiMessageBoxService);
    }
    /**
     * Lifecycle hook called after Angular has fully initialized the component's view.
     * Creates the template portals for content and footer (if available).
     */
    ngAfterViewInit() {
        this.templatePortalContent = new TemplatePortal(this.templateRefContent, this.viewContainerRef);
        if (this.euiMessageBoxFooterDirective) {
            this.templatePortalFooter = new TemplatePortal(this.templateRefFooter, this.viewContainerRef);
        }
    }
    /**
     * Lifecycle hook that's called when the component is destroyed.
     * Cleans up any subscriptions to prevent memory leaks.
     */
    ngOnDestroy() {
        this.destroy$.next(true);
        this.destroy$.unsubscribe();
    }
    /**
     * Opens the message box with the current configuration.
     * This method configures and displays the message box using the EuiMessageBoxService.
     */
    openMessageBox() {
        const config = {
            e2eAttr: this.e2eAttr,
            title: this.title,
            width: this.width,
            height: this.height,
            variant: this.baseStatesDirective.euiVariant()?.length > 0 ? this.baseStatesDirective.euiVariant() : 'primary',
            acceptLabel: this.acceptLabel,
            dismissLabel: this.dismissLabel,
            hasCloseButton: false,
            hasAcceptButton: this.hasAcceptButton,
            hasDismissButton: this.hasDismissButton,
            hasClosedOnClickOutside: false,
            hasClosedOnEscape: false,
            isHandleCloseOnDismiss: this.isHandleCloseOnDismiss,
            isHandleCloseOnClose: this.isHandleCloseOnClose,
            isHandleCloseOnAccept: this.isHandleCloseOnAccept,
            isHandleCloseOnClickOutside: false,
            isHandleCloseOnEscape: false,
            isDraggable: coerceBooleanProperty(this.isDraggable),
            hasNoBodyPadding: coerceBooleanProperty(this.hasNoBodyPadding),
            content: this.templatePortalContent,
            footer: this.templatePortalFooter,
            isMessageBox: true,
            open: () => {
                this.messageBoxOpen.emit();
            },
            close: () => {
                this.messageBoxClose.emit();
            },
            dismiss: () => {
                this.dismiss.emit();
            },
            accept: () => {
                this.accept.emit();
            },
        };
        this.euiMessageBoxService.openMessageBox(config);
    }
    /**
     * Closes the currently open message box.
     * This method uses the EuiMessageBoxService to close the dialog.
     */
    closeMessageBox() {
        this.euiMessageBoxService.closeMessageBox();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: EuiMessageBoxComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "21.1.0", type: EuiMessageBoxComponent, isStandalone: true, selector: "eui-message-box", inputs: { e2eAttr: "e2eAttr", title: "title", width: "width", height: "height", hasAcceptButton: ["hasAcceptButton", "hasAcceptButton", booleanAttribute], hasDismissButton: ["hasDismissButton", "hasDismissButton", booleanAttribute], acceptLabel: "acceptLabel", dismissLabel: "dismissLabel", isHandleCloseOnDismiss: ["isHandleCloseOnDismiss", "isHandleCloseOnDismiss", booleanAttribute], isHandleCloseOnClose: ["isHandleCloseOnClose", "isHandleCloseOnClose", booleanAttribute], isHandleCloseOnAccept: ["isHandleCloseOnAccept", "isHandleCloseOnAccept", booleanAttribute], isDraggable: ["isDraggable", "isDraggable", booleanAttribute], hasNoBodyPadding: ["hasNoBodyPadding", "hasNoBodyPadding", booleanAttribute] }, outputs: { messageBoxOpen: "messageBoxOpen", messageBoxClose: "messageBoxClose", dismiss: "dismiss", accept: "accept" }, queries: [{ propertyName: "euiMessageBoxFooterDirective", first: true, predicate: i0.forwardRef(() => EuiMessageBoxFooterDirective), descendants: true }], viewQueries: [{ propertyName: "templateRefContent", first: true, predicate: ["templateRefContent"], descendants: true }, { propertyName: "templateRefFooter", first: true, predicate: ["templateRefFooter"], descendants: true }], hostDirectives: [{ directive: i1.BaseStatesDirective, inputs: ["euiPrimary", "euiPrimary", "euiSecondary", "euiSecondary", "euiInfo", "euiInfo", "euiSuccess", "euiSuccess", "euiWarning", "euiWarning", "euiDanger", "euiDanger", "euiVariant", "euiVariant"] }], ngImport: i0, template: "<ng-template #templateRefContent>\n    <ng-content />\n</ng-template>\n<ng-template #templateRefFooter>\n    <ng-content select=\"eui-message-box-footer\" />\n</ng-template>\n", dependencies: [{ kind: "ngmodule", type: TranslateModule }, { kind: "ngmodule", type: PortalModule }, { kind: "ngmodule", type: OverlayModule }, { kind: "ngmodule", type: A11yModule }, { kind: "ngmodule", type: DragDropModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: EuiMessageBoxComponent, decorators: [{
            type: Component,
            args: [{ selector: 'eui-message-box', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, imports: [
                        TranslateModule,
                        PortalModule,
                        OverlayModule,
                        A11yModule,
                        DragDropModule,
                    ], hostDirectives: [
                        {
                            directive: BaseStatesDirective,
                            inputs: [
                                'euiPrimary',
                                'euiSecondary',
                                'euiInfo',
                                'euiSuccess',
                                'euiWarning',
                                'euiDanger',
                                'euiVariant',
                            ],
                        },
                    ], template: "<ng-template #templateRefContent>\n    <ng-content />\n</ng-template>\n<ng-template #templateRefFooter>\n    <ng-content select=\"eui-message-box-footer\" />\n</ng-template>\n" }]
        }], propDecorators: { e2eAttr: [{
                type: Input
            }], title: [{
                type: Input
            }], width: [{
                type: Input
            }], height: [{
                type: Input
            }], hasAcceptButton: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], hasDismissButton: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], acceptLabel: [{
                type: Input
            }], dismissLabel: [{
                type: Input
            }], isHandleCloseOnDismiss: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], isHandleCloseOnClose: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], isHandleCloseOnAccept: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], isDraggable: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], hasNoBodyPadding: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], messageBoxOpen: [{
                type: Output
            }], messageBoxClose: [{
                type: Output
            }], dismiss: [{
                type: Output
            }], accept: [{
                type: Output
            }], templateRefContent: [{
                type: ViewChild,
                args: ['templateRefContent']
            }], templateRefFooter: [{
                type: ViewChild,
                args: ['templateRefFooter']
            }], euiMessageBoxFooterDirective: [{
                type: ContentChild,
                args: [forwardRef(() => EuiMessageBoxFooterDirective)]
            }] } });
/* eslint-disable */
class EuiMessageBoxFooterDirective {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: EuiMessageBoxFooterDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.0", type: EuiMessageBoxFooterDirective, isStandalone: true, selector: "eui-message-box-footer", ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: EuiMessageBoxFooterDirective, decorators: [{
            type: Directive,
            args: [{ selector: 'eui-message-box-footer' }]
        }] });

class EuiMessageBoxConfig {
    constructor(values) {
        this.e2eAttr = 'eui-message-box';
        this.acceptLabel = 'eui.OK';
        this.dismissLabel = 'eui.CANCEL';
        this.variant = 'primary';
        this.width = '33rem';
        this.height = 'auto';
        this.hasCloseButton = false;
        this.hasAcceptButton = true;
        this.hasDismissButton = true;
        this.hasClosedOnClickOutside = false;
        this.hasClosedOnEscape = false;
        this.isHandleCloseOnDismiss = false;
        this.isHandleCloseOnClose = false;
        this.isHandleCloseOnAccept = false;
        this.isHandleCloseOnClickOutside = false;
        this.isHandleCloseOnEscape = false;
        this.hasFooter = true;
        this.isMessageBox = true;
        this.header = null;
        this.headerComponent = null;
        Object.assign(this, values);
    }
}
class EuiMessageBoxComponentInstances {
    constructor() {
        this.headerComponent = null;
        this.bodyComponent = null;
        this.footerComponent = null;
    }
}

const EUI_MESSAGE_BOX = [
    EuiMessageBoxComponent,
    EuiMessageBoxFooterDirective,
];

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

export { EUI_MESSAGE_BOX, EuiMessageBoxComponent, EuiMessageBoxComponentInstances, EuiMessageBoxConfig, EuiMessageBoxFooterDirective, EuiMessageBoxService };
//# sourceMappingURL=eui-components-eui-message-box.mjs.map
