import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { EventEmitter, Directive, Input, Output, HostListener, NgModule } from '@angular/core';
import { Subject } from 'rxjs';
import { debounceTime, takeUntil, repeat } from 'rxjs/operators';

/**
 * @description Diretiva que detecta o gesto de pressão longa (long press) em um elemento.
 * Emite o evento `sLongPress` após o tempo configurado em `sLongPressDelay` sem que o
 * botão do mouse ou o toque seja liberado.
 *
 * @example
 * ```html
 * <button [sLongPressDelay]="800" (sLongPress)="onLongPress($event)">Segurar</button>
 * ```
 *
 * @category Inputs
 */
class LongPressDirective {
    /** @description Tempo em milissegundos para disparar o long press. @default 500 */
    sLongPressDelay = 500;
    /** @description Emitido quando o elemento é pressionado por mais de `sLongPressDelay` ms. */
    sLongPress = new EventEmitter();
    mouseUp = new Subject();
    mouseDown = new Subject();
    ngUnsubscribe = new Subject();
    onMouseUp(event) {
        this.mouseUp.next(event);
    }
    onMouseDown(event) {
        this.mouseDown.next(event);
    }
    ngOnInit() {
        this.mouseDown
            .pipe(debounceTime(this.sLongPressDelay), takeUntil(this.mouseUp), repeat(), takeUntil(this.ngUnsubscribe))
            .subscribe((event) => this.sLongPress.emit(event));
    }
    ngOnDestroy() {
        this.ngUnsubscribe.next();
        this.ngUnsubscribe.complete();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LongPressDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: LongPressDirective, selector: "[sLongPress]", inputs: { sLongPressDelay: "sLongPressDelay" }, outputs: { sLongPress: "sLongPress" }, host: { listeners: { "mouseup": "onMouseUp($event)", "touchend": "onMouseUp($event)", "mousedown": "onMouseDown($event)", "touchstart": "onMouseDown($event)" } }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LongPressDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[sLongPress]',
                }]
        }], propDecorators: { sLongPressDelay: [{
                type: Input
            }], sLongPress: [{
                type: Output
            }], onMouseUp: [{
                type: HostListener,
                args: ['mouseup', ['$event']]
            }, {
                type: HostListener,
                args: ['touchend', ['$event']]
            }], onMouseDown: [{
                type: HostListener,
                args: ['mousedown', ['$event']]
            }, {
                type: HostListener,
                args: ['touchstart', ['$event']]
            }] } });

/**
 * @description Diretiva que detecta duplo clique em um elemento com um intervalo
 * configurável entre cliques (`_DOUBLE_CLICK_DELAY`). Emite o evento `doubleClicked`
 * somente quando dois cliques ocorrem dentro do intervalo definido.
 *
 * @example
 * ```html
 * <div sDoubleClick (doubleClicked)="onDoubleClick($event)">Duplo clique aqui</div>
 * ```
 *
 * @category Inputs
 */
class DoubleClickDirective {
    /** @description Emitido quando um duplo clique é detectado dentro do intervalo de tempo. */
    doubleClicked = new EventEmitter();
    _timeout;
    _DOUBLE_CLICK_DELAY = 500;
    onClick(event) {
        this.handleOnClickEvent(event);
    }
    handleOnClickEvent(event) {
        if (this._timeout) {
            this.clearTimeout();
            this.doubleClicked.emit(event);
        }
        else {
            this._timeout = setTimeout(() => this.clearTimeout(), this._DOUBLE_CLICK_DELAY);
        }
    }
    clearTimeout() {
        clearTimeout(this._timeout);
        this._timeout = undefined;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DoubleClickDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: DoubleClickDirective, isStandalone: true, selector: "[sDoubleClick]", outputs: { doubleClicked: "doubleClicked" }, host: { listeners: { "click": "onClick($event)" } }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DoubleClickDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[sDoubleClick]',
                    standalone: true,
                }]
        }], propDecorators: { doubleClicked: [{
                type: Output
            }], onClick: [{
                type: HostListener,
                args: ['click', ['$event']]
            }] } });

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

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

export { DoubleClickDirective, LongPressDirective, MouseEventsModule };
//# sourceMappingURL=seniorsistemas-angular-components-mouse-events.mjs.map
