import * as i0 from '@angular/core';
import { Directive, Input, NgModule } from '@angular/core';
import { DomHandler } from 'primeng/dom';

// TODO: O que é esta diretiva?
/**
 * @description Diretiva aplicada a um `p-table` do PrimeNG para corrigir o comportamento
 * de clique fora da célula editável, evitando que cliques em overlays (como dropdowns e modais)
 * fechem indevidamente o modo de edição da célula.
 *
 * @example
 * ```html
 * <p-table sEditableOverlay [table]="dt" #dt>...</p-table>
 * ```
 *
 * @category Overlay
 */
class EditableOverlayDirective {
    /**
     * @description Referência direta à instância do `p-table` ao qual a diretiva está aplicada.
     * Utilizada para sobrescrever o comportamento padrão de `bindDocumentEditListener`.
     */
    table;
    ngAfterViewInit() {
        this.table.bindDocumentEditListener = this._bindDocument.bind(this);
    }
    isFromOverlayTrigger(event) {
        return event.path.some((path) => path.className && path.className.includes('ng-trigger-overlayAnimation'));
    }
    isFromModal(event) {
        return event.path.some((path) => path.className && path.className.includes('s-lookup'));
    }
    _bindDocument() {
        if (!this.table.documentEditListener) {
            this.table.documentEditListener = (event) => {
                if (!this.isFromOverlayTrigger(event) &&
                    !this.isFromModal(event) &&
                    this.table.editingCell &&
                    !this.table.editingCellClick &&
                    this.table.isEditingCellValid()) {
                    DomHandler.removeClass(this.table.editingCell, 'ui-editing-cell');
                    this.table.editingCell = null;
                    this.table.unbindDocumentEditListener();
                }
                this.table.editingCellClick = false;
            };
            document.addEventListener('click', this.table.documentEditListener);
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: EditableOverlayDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: EditableOverlayDirective, isStandalone: true, selector: "p-table[sEditableOverlay]", inputs: { table: "table" }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: EditableOverlayDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: 'p-table[sEditableOverlay]',
                    standalone: true,
                }]
        }], propDecorators: { table: [{
                type: Input
            }] } });

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

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

export { EditableOverlayDirective, EditableOverlayModule };
//# sourceMappingURL=seniorsistemas-angular-components-editable-overlay.mjs.map
