import * as i0 from '@angular/core';
import { Directive, inject, ElementRef, NgZone, DestroyRef } from '@angular/core';
import * as i1 from 'primeng/tooltip';
import { Tooltip as Tooltip$1 } from 'primeng/tooltip';

class Tooltip {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: Tooltip, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.3", type: Tooltip, isStandalone: true, selector: "[mtTooltip]", hostDirectives: [{ directive: i1.Tooltip, inputs: ["pTooltip", "mtTooltip", "tooltipPosition", "tooltipPosition", "tooltipEvent", "tooltipEvent", "appendTo", "appendTo", "tooltipStyleClass", "tooltipStyleClass", "escape", "escape", "showDelay", "showDelay", "hideDelay", "hideDelay", "life", "life", "positionTop", "positionTop", "positionLeft", "positionLeft", "autoHide", "autoHide", "fitContent", "fitContent", "hideOnEscape", "hideOnEscape", "tooltipDisabled", "tooltipDisabled"] }], ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: Tooltip, decorators: [{
            type: Directive,
            args: [{
                    selector: '[mtTooltip]',
                    standalone: true,
                    hostDirectives: [
                        {
                            directive: Tooltip$1,
                            inputs: [
                                'pTooltip: mtTooltip',
                                'tooltipPosition',
                                'tooltipEvent',
                                'appendTo',
                                'tooltipStyleClass',
                                'escape',
                                'showDelay',
                                'hideDelay',
                                'life',
                                'positionTop',
                                'positionLeft',
                                'autoHide',
                                'fitContent',
                                'hideOnEscape',
                                'tooltipDisabled',
                            ],
                        },
                    ],
                }]
        }] });

class TruncateTooltip {
    elementRef = inject(ElementRef);
    zone = inject(NgZone);
    destroyRef = inject(DestroyRef);
    tooltip = inject(Tooltip$1);
    resizeObserver;
    mutationObserver;
    syncTimeout = null;
    ngAfterViewInit() {
        this.zone.runOutsideAngular(() => {
            const element = this.elementRef.nativeElement;
            if (typeof ResizeObserver !== 'undefined') {
                this.resizeObserver = new ResizeObserver(() => this.queueSync());
                this.resizeObserver.observe(element);
            }
            if (typeof MutationObserver !== 'undefined') {
                this.mutationObserver = new MutationObserver(() => this.queueSync());
                this.mutationObserver.observe(element, {
                    childList: true,
                    characterData: true,
                    subtree: true,
                    attributes: true,
                    attributeFilter: ['class', 'style'],
                });
            }
            this.queueSync();
        });
        this.destroyRef.onDestroy(() => {
            this.resizeObserver?.disconnect();
            this.mutationObserver?.disconnect();
            if (this.syncTimeout !== null) {
                clearTimeout(this.syncTimeout);
            }
        });
    }
    syncTooltipState() {
        this.queueSync();
    }
    queueSync() {
        if (this.syncTimeout !== null) {
            return;
        }
        this.syncTimeout = setTimeout(() => {
            this.syncTimeout = null;
            this.syncTooltip();
        });
    }
    syncTooltip() {
        const element = this.elementRef.nativeElement;
        const text = element.textContent?.replace(/\s+/g, ' ').trim() ?? '';
        const isTruncated = element.scrollWidth > element.clientWidth ||
            element.scrollHeight > element.clientHeight;
        this.tooltip.content = text || undefined;
        this.tooltip.disabled = !text || !isTruncated;
        if (!this.tooltip.active) {
            return;
        }
        if (this.tooltip.disabled) {
            this.tooltip.hide();
            return;
        }
        this.tooltip.updateText();
        this.tooltip.align();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: TruncateTooltip, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.3", type: TruncateTooltip, isStandalone: true, selector: "[mtTruncateTooltip]", host: { listeners: { "mouseenter": "syncTooltipState()", "focusin": "syncTooltipState()" } }, hostDirectives: [{ directive: i1.Tooltip, inputs: ["tooltipPosition", "tooltipPosition", "tooltipEvent", "tooltipEvent", "appendTo", "appendTo", "tooltipStyleClass", "tooltipStyleClass", "escape", "escape", "showDelay", "showDelay", "hideDelay", "hideDelay", "life", "life", "positionTop", "positionTop", "positionLeft", "positionLeft", "autoHide", "autoHide", "fitContent", "fitContent", "hideOnEscape", "hideOnEscape"] }], ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: TruncateTooltip, decorators: [{
            type: Directive,
            args: [{
                    selector: '[mtTruncateTooltip]',
                    host: {
                        '(mouseenter)': 'syncTooltipState()',
                        '(focusin)': 'syncTooltipState()',
                    },
                    hostDirectives: [
                        {
                            directive: Tooltip$1,
                            inputs: [
                                'tooltipPosition',
                                'tooltipEvent',
                                'appendTo',
                                'tooltipStyleClass',
                                'escape',
                                'showDelay',
                                'hideDelay',
                                'life',
                                'positionTop',
                                'positionLeft',
                                'autoHide',
                                'fitContent',
                                'hideOnEscape',
                            ],
                        },
                    ],
                }]
        }] });

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

export { Tooltip, TruncateTooltip };
//# sourceMappingURL=masterteam-components-tooltip.mjs.map
