import * as i0 from '@angular/core';
import { output, input, Directive } from '@angular/core';

class InteractiveContentDirective {
    elementRef;
    activated = output({ alias: 'sInteractiveContent' });
    focusable = input(true);
    disabled = input(false);
    stopPropagation = input(false);
    EVENT_LISTENER = (event) => {
        if (this.disabled()) {
            return;
        }
        if (event instanceof KeyboardEvent) {
            const key = event.key;
            const validKeys = ['Enter', ' '];
            if (!validKeys.includes(key)) {
                return;
            }
            event.preventDefault();
            if (this.stopPropagation()) {
                event.stopPropagation();
            }
        }
        this.activated.emit(event);
    };
    constructor(elementRef) {
        this.elementRef = elementRef;
    }
    ngOnInit() {
        this.setTabIndex();
        this.checkAccessbilityEvents();
    }
    setTabIndex() {
        if (this.disabled() || !this.focusable()) {
            this.element.tabIndex = -1;
            return;
        }
        if (this.element.tabIndex === undefined || this.element.tabIndex < 0) {
            this.element.tabIndex = 0;
        }
    }
    checkAccessbilityEvents() {
        this.element.addEventListener('click', this.EVENT_LISTENER);
        this.element.addEventListener('keydown', this.EVENT_LISTENER);
    }
    get element() {
        return this.elementRef.nativeElement;
    }
    ngOnDestroy() {
        this.element.removeEventListener('click', this.EVENT_LISTENER);
        this.element.removeEventListener('keydown', this.EVENT_LISTENER);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: InteractiveContentDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.2.14", type: InteractiveContentDirective, isStandalone: true, selector: "[sInteractiveContent]", inputs: { focusable: { classPropertyName: "focusable", publicName: "focusable", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, stopPropagation: { classPropertyName: "stopPropagation", publicName: "stopPropagation", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activated: "sInteractiveContent" }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: InteractiveContentDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[sInteractiveContent]',
                    standalone: true,
                }]
        }], ctorParameters: () => [{ type: i0.ElementRef }] });

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

export { InteractiveContentDirective };
//# sourceMappingURL=seniorsistemas-angular-components-interactive-content.mjs.map
