import { MXBaseComponent, AXComponent, convertToPlacement } from '@acorex/cdk/common';
import * as i0 from '@angular/core';
import { Input, ChangeDetectionStrategy, ViewEncapsulation, Component, inject, ViewContainerRef, ElementRef, input, effect, TemplateRef, Directive, NgModule } from '@angular/core';
import { AXDragDirective } from '@acorex/cdk/drag-drop';
import { AXPopoverComponent } from '@acorex/components/popover';
import { OverlayModule } from '@angular/cdk/overlay';
import { CommonModule } from '@angular/common';

/**
 * A component for displaying tooltips with additional information or context when hovering over elements.
 * @category Components
 */
class AXTooltipComponent extends MXBaseComponent {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXTooltipComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.9", type: AXTooltipComponent, isStandalone: true, selector: "ax-tooltip", inputs: { text: "text", position: "position" }, providers: [{ provide: AXComponent, useExisting: AXTooltipComponent }], usesInheritance: true, ngImport: i0, template: "<div class=\"ax-tooltip-container\">\n  <div class=\"ax-tooltip\">\n    {{ text }}\n  </div>\n  <!-- <div class=\"ax-tooltip-tringle ax-tooltip-tringle-{{ position }}\"></div> -->\n</div>\n", styles: ["ax-tooltip{--ax-comp-tooltip-border-radius: .25rem;--ax-comp-tooltip-bg-color: var(--ax-sys-color-dark);--ax-comp-tooltip-text-color: var(--ax-sys-color-light)}.ax-dark ax-tooltip{--ax-comp-tooltip-bg-color: var(--ax-sys-color-light);--ax-comp-tooltip-text-color: var(--ax-sys-color-dark)}.ax-tooltip-container{position:relative}.ax-tooltip-container .ax-tooltip{display:block;padding:.25rem .5rem;background-color:rgba(var(--ax-comp-tooltip-bg-color));color:rgba(var(--ax-comp-tooltip-text-color));border-radius:var(--ax-comp-tooltip-border-radius);font-size:.75rem;font-weight:400}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXTooltipComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-tooltip', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, providers: [{ provide: AXComponent, useExisting: AXTooltipComponent }], template: "<div class=\"ax-tooltip-container\">\n  <div class=\"ax-tooltip\">\n    {{ text }}\n  </div>\n  <!-- <div class=\"ax-tooltip-tringle ax-tooltip-tringle-{{ position }}\"></div> -->\n</div>\n", styles: ["ax-tooltip{--ax-comp-tooltip-border-radius: .25rem;--ax-comp-tooltip-bg-color: var(--ax-sys-color-dark);--ax-comp-tooltip-text-color: var(--ax-sys-color-light)}.ax-dark ax-tooltip{--ax-comp-tooltip-bg-color: var(--ax-sys-color-light);--ax-comp-tooltip-text-color: var(--ax-sys-color-dark)}.ax-tooltip-container{position:relative}.ax-tooltip-container .ax-tooltip{display:block;padding:.25rem .5rem;background-color:rgba(var(--ax-comp-tooltip-bg-color));color:rgba(var(--ax-comp-tooltip-text-color));border-radius:var(--ax-comp-tooltip-border-radius);font-size:.75rem;font-weight:400}\n"] }]
        }], propDecorators: { text: [{
                type: Input
            }], position: [{
                type: Input
            }] } });

class AXTooltipDirective {
    get placement() {
        return this._placement;
    }
    set placement(v) {
        this._placement = v;
        if (this.popupRef) {
            this.popupRef.placement = v;
        }
    }
    get offsetX() {
        return this._offsetX;
    }
    set offsetX(v) {
        this._offsetX = v;
        if (this.popupRef) {
            this.popupRef.offsetX = v;
        }
    }
    get offsetY() {
        return this._offsetY;
    }
    set offsetY(v) {
        this._offsetY = v;
        if (this.popupRef) {
            this.popupRef.offsetY = v;
        }
    }
    get openAfter() {
        return this._openAfter;
    }
    set openAfter(v) {
        this._openAfter = v;
        if (this.popupRef) {
            this.popupRef.openAfter = v;
        }
    }
    get closeAfter() {
        return this._closeAfter;
    }
    set closeAfter(v) {
        this._closeAfter = v;
        if (this.popupRef) {
            this.popupRef.closeAfter = v;
        }
    }
    constructor() {
        this.vc = inject(ViewContainerRef);
        this.elementRef = inject(ElementRef);
        this.dragRef = inject(AXDragDirective, { optional: true });
        this.axTooltipDisabled = input(false, ...(ngDevMode ? [{ debugName: "axTooltipDisabled" }] : []));
        this.content = input('', ...(ngDevMode ? [{ debugName: "content", alias: 'axTooltip' }] : [{ alias: 'axTooltip' }]));
        this.context = input({}, ...(ngDevMode ? [{ debugName: "context", alias: 'axTooltipContext' }] : [{ alias: 'axTooltipContext' }]));
        this._placement = convertToPlacement('top');
        this._offsetX = 0;
        this._offsetY = 0;
        this._openAfter = 100;
        this._closeAfter = 100;
        this.#contentEff = effect(() => {
            if (typeof this.content() === 'string' && this.content()) {
                this.popupRef.content = AXTooltipComponent;
                this.popupRef.context = { text: this.content() };
            }
            else if (this.content() instanceof TemplateRef) {
                this.popupRef.content = this.content();
                this.popupRef.context = this.context();
            }
        }, ...(ngDevMode ? [{ debugName: "#contentEff" }] : []));
        this.#disabledEff = effect(() => {
            this.popupRef.disabled = this.axTooltipDisabled();
        }, ...(ngDevMode ? [{ debugName: "#disabledEff" }] : []));
        this.#dragWatchEff = effect(() => {
            if (this.dragRef?.isMoving()) {
                this.popupRef.close();
            }
        }, ...(ngDevMode ? [{ debugName: "#dragWatchEff" }] : []));
        this.popupRef = this.vc.createComponent(AXPopoverComponent).instance;
        this.popupRef.target = this.elementRef.nativeElement;
    }
    ngOnInit() {
        this.popupRef.target = this.elementRef.nativeElement;
        this.popupRef.openOn = 'hover';
        this.popupRef.closeOn = 'leave';
        this.popupRef.placement = this.placement;
        this.popupRef.openAfter = this.openAfter;
        this.popupRef.closeAfter = this.closeAfter;
    }
    #contentEff;
    #disabledEff;
    #dragWatchEff;
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXTooltipDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: AXTooltipDirective, isStandalone: true, selector: "[axTooltip]", inputs: { axTooltipDisabled: { classPropertyName: "axTooltipDisabled", publicName: "axTooltipDisabled", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "axTooltip", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "axTooltipContext", isSignal: true, isRequired: false, transformFunction: null }, placement: { classPropertyName: "placement", publicName: "axTooltipPlacement", isSignal: false, isRequired: false, transformFunction: null }, offsetX: { classPropertyName: "offsetX", publicName: "axTooltipOffsetX", isSignal: false, isRequired: false, transformFunction: null }, offsetY: { classPropertyName: "offsetY", publicName: "axTooltipOffsetY", isSignal: false, isRequired: false, transformFunction: null }, openAfter: { classPropertyName: "openAfter", publicName: "axTooltipOpenAfter", isSignal: false, isRequired: false, transformFunction: null }, closeAfter: { classPropertyName: "closeAfter", publicName: "axTooltipCloseAfter", isSignal: false, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXTooltipDirective, decorators: [{
            type: Directive,
            args: [{ selector: '[axTooltip]' }]
        }], ctorParameters: () => [], propDecorators: { axTooltipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "axTooltipDisabled", required: false }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "axTooltip", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "axTooltipContext", required: false }] }], placement: [{
                type: Input,
                args: ['axTooltipPlacement']
            }], offsetX: [{
                type: Input,
                args: ['axTooltipOffsetX']
            }], offsetY: [{
                type: Input,
                args: ['axTooltipOffsetY']
            }], openAfter: [{
                type: Input,
                args: ['axTooltipOpenAfter']
            }], closeAfter: [{
                type: Input,
                args: ['axTooltipCloseAfter']
            }] } });

const COMPONENT = [AXTooltipComponent, AXTooltipDirective];
const MODULES = [CommonModule, OverlayModule];
class AXTooltipModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXTooltipModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.9", ngImport: i0, type: AXTooltipModule, imports: [CommonModule, OverlayModule, AXTooltipComponent, AXTooltipDirective], exports: [AXTooltipComponent, AXTooltipDirective] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXTooltipModule, imports: [MODULES] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXTooltipModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [...MODULES, ...COMPONENT],
                    exports: [...COMPONENT],
                }]
        }] });

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

export { AXTooltipComponent, AXTooltipDirective, AXTooltipModule };
//# sourceMappingURL=acorex-components-tooltip.mjs.map
