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';

class LongPressDirective {
    sLongPressDelay = 500;
    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"]]
            }] } });

class DoubleClickDirective {
    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, 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]'
                }]
        }], 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,
            DoubleClickDirective], imports: [CommonModule], 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],
                    declarations: [
                        LongPressDirective,
                        DoubleClickDirective
                    ],
                    exports: [
                        LongPressDirective,
                        DoubleClickDirective
                    ],
                }]
        }] });

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

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