import * as i0 from '@angular/core';
import { input, booleanAttribute, inject, ElementRef, Renderer2, effect, HostListener, ViewEncapsulation, Component, NgModule } from '@angular/core';
import { EuiGrowlService } from '@eui/core';

/**
 * @description
 * Component that provides functionality to disable content and show a visual overlay.
 * When disabled, it adds a semi-transparent overlay and handles focus management.
 */
class EuiDisableContentComponent {
    /**
     * Initializes the component and sets up an effect to handle disabled state changes
     */
    constructor() {
        /**
         * Text to display in an eui-growl (type info) notification when clicking
         * the disabled content.
         */
        this.disabledText = input('');
        /**
         * Controls whether the content is disabled. If disabled, a semi-transparent
         * overlay with spinner is shown.
         */
        this.isDisabled = input(null, { transform: booleanAttribute });
        /** Stores the last active element before disabling */
        this.lastActiveElement = null;
        /** Reference to the component's element */
        this.elRef = inject(ElementRef);
        /** Service for displaying growl notifications */
        this.growlService = inject(EuiGrowlService);
        /** Renderer for DOM manipulations */
        this.renderer = inject(Renderer2);
        effect(() => {
            const disabled = this.isDisabled();
            if (disabled) {
                this.renderer.addClass(this.elRef.nativeElement, 'eui-disable-content--disabled');
            }
            else {
                this.renderer.removeClass(this.elRef.nativeElement, 'eui-disable-content--disabled');
            }
        });
        // TODO: Implement a LinkedSignal effect for isBlocking logic inside ngOnChanges
    }
    /**
     * Handles changes to component inputs
     * @param changes Object containing changed properties
     * @deprecated It will be removed in the next major version. In favor of
     * `effect` and linkedSignal.
     */
    ngOnChanges(changes) {
        if (changes['isDisabled']) {
            const change = changes['isDisabled'];
            const isBlocking = change.currentValue && !change.previousValue;
            if (isBlocking) {
                const activeElement = this.getActiveElement();
                this.desactivateElement(activeElement);
            }
            else {
                this.reactivateElement();
            }
        }
    }
    /**
     * Checks if the component is about to enter a blocked state
     * @param change The change object to evaluate
     * @returns True if the component is transitioning to blocked state
     * @deprecated It will become private in the next major version.
     * @internal
     */
    isAboutToBlock(change) {
        return Boolean(change?.currentValue && !change.previousValue);
    }
    /**
     * Stores the currently active element before disabling
     * @param activeElement The element to deactivate
     * @deprecated It will become private in the next major version.
     * @internal
     */
    desactivateElement(activeElement) {
        if (activeElement) {
            this.renderer.setAttribute(activeElement, 'disabled', 'true');
            this.renderer.setAttribute(activeElement, 'tabindex', '-1');
            this.renderer.setAttribute(activeElement, 'aria-disabled', 'true');
            this.lastActiveElement = activeElement;
        }
        else {
            this.lastActiveElement = null;
        }
    }
    /**
     * Reactivates the last active element
     * @deprecated It will become private in the next major version.
     * @internal
     */
    reactivateElement() {
        if (this.lastActiveElement) {
            this.renderer.removeAttribute(this.lastActiveElement, 'disabled');
            this.renderer.setAttribute(this.lastActiveElement, 'tabindex', '0');
            this.renderer.setAttribute(this.lastActiveElement, 'aria-disabled', 'false');
            this.lastActiveElement.focus();
        }
    }
    /**
     * Gets the currently focused element within the component
     * @returns The focused HTML element or null
     * @deprecated It will become private in the next major version.
     * @internal
     */
    getActiveElement() {
        return this.elRef.nativeElement.querySelector(':focus');
    }
    /**
     * Handles click events on the disabled content
     * Shows a growl notification if content is disabled and has disabled text
     * @deprecated It will become private in the next major version.
     * @internal
     */
    onClick() {
        if (this.isDisabled() && this.disabledText()) {
            this.growlService.growlInfo(this.disabledText());
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiDisableContentComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.17", type: EuiDisableContentComponent, isStandalone: true, selector: "eui-disable-content", inputs: { disabledText: { classPropertyName: "disabledText", publicName: "disabledText", isSignal: true, isRequired: false, transformFunction: null }, isDisabled: { classPropertyName: "isDisabled", publicName: "isDisabled", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "onClick()" } }, usesOnChanges: true, ngImport: i0, template: '<ng-content/>', isInline: true, styles: [".eui-19 .eui-disable-content--disabled{position:relative;z-index:var(--eui-zi-overlay);cursor:not-allowed;display:flex}.eui-19 .eui-disable-content--disabled:after{background-color:#ffffff40;content:\"\";height:100%;left:0;position:absolute;top:0;width:100%;z-index:var(--eui-zi-overlay)}\n"], encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiDisableContentComponent, decorators: [{
            type: Component,
            args: [{ selector: 'eui-disable-content', template: '<ng-content/>', encapsulation: ViewEncapsulation.None, styles: [".eui-19 .eui-disable-content--disabled{position:relative;z-index:var(--eui-zi-overlay);cursor:not-allowed;display:flex}.eui-19 .eui-disable-content--disabled:after{background-color:#ffffff40;content:\"\";height:100%;left:0;position:absolute;top:0;width:100%;z-index:var(--eui-zi-overlay)}\n"] }]
        }], ctorParameters: () => [], propDecorators: { onClick: [{
                type: HostListener,
                args: ['click']
            }] } });
/**
 * Module that declares and exports the EuiDisableContentComponent
 *
 * @deprecated Use the {@link EUI_DISABLE_CONTENT} directly instead of this module.
 */
class EuiDisableContentModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiDisableContentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.17", ngImport: i0, type: EuiDisableContentModule, imports: [EuiDisableContentComponent], exports: [EuiDisableContentComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiDisableContentModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiDisableContentModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [EuiDisableContentComponent],
                    exports: [EuiDisableContentComponent],
                }]
        }] });

const EUI_DISABLE_CONTENT = [
    EuiDisableContentComponent,
];
// export { EuiDisableContentComponent as EuiDisableContent } from './eui-disable-content.component';

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

export { EUI_DISABLE_CONTENT, EuiDisableContentComponent, EuiDisableContentModule };
//# sourceMappingURL=eui-components-eui-disable-content.mjs.map
