import * as i0 from '@angular/core';
import { EventEmitter, Output, Input, Directive, NgModule } from '@angular/core';
import { Subscription, fromEvent } from 'rxjs';
import { debounceTime, filter } from 'rxjs/operators';

/**
 * Tool directive used to achieve the infinite scroll mechanism.
 */
class InfiniteScrollDirective {
    /** @hidden */
    constructor(_element) {
        this._element = _element;
        /** Scroll percentage at which the onScrollAction event is fired. */
        this.scrollPercent = 75;
        /** Scroll PX at which the onScrollAction event is fired. */
        this.scrollOffset = null;
        /** Event emitted when the scrollPercent threshold is met. */
        this.onScrollAction = new EventEmitter();
        /** @hidden */
        this._subscription = new Subscription();
    }
    /** @hidden */
    ngOnInit() {
        this._listenOnScroll();
    }
    /** @hidden */
    ngOnDestroy() {
        this._subscription.unsubscribe();
    }
    /** @hidden */
    shouldTriggerAction() {
        const element = this._element.nativeElement;
        const offset = element.scrollTop + element.offsetHeight;
        if (this.scrollOffset) {
            return offset > element.scrollHeight - this.scrollOffset;
        }
        else {
            return offset / element.scrollHeight > this.scrollPercent / 100;
        }
    }
    /** @hidden */
    _listenOnScroll() {
        this._subscription.add(fromEvent(this._element.nativeElement, 'scroll')
            .pipe(debounceTime(50), filter(() => this.shouldTriggerAction()))
            .subscribe(() => this.onScrollAction.emit()));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: InfiniteScrollDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.1.4", type: InfiniteScrollDirective, isStandalone: true, selector: "[fdInfiniteScroll]", inputs: { scrollPercent: "scrollPercent", scrollOffset: "scrollOffset" }, outputs: { onScrollAction: "onScrollAction" }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: InfiniteScrollDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[fdInfiniteScroll]',
                    standalone: true
                }]
        }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { scrollPercent: [{
                type: Input
            }], scrollOffset: [{
                type: Input
            }], 
        // eslint-disable-next-line @angular-eslint/no-output-on-prefix
        onScrollAction: [{
                type: Output
            }] } });

/**
 * @deprecated
 * Use direct imports of components and directives.
 */
class InfiniteScrollModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: InfiniteScrollModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.4", ngImport: i0, type: InfiniteScrollModule, imports: [InfiniteScrollDirective], exports: [InfiniteScrollDirective] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: InfiniteScrollModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: InfiniteScrollModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [InfiniteScrollDirective],
                    exports: [InfiniteScrollDirective]
                }]
        }] });

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

export { InfiniteScrollDirective, InfiniteScrollModule };
//# sourceMappingURL=fundamental-ngx-core-infinite-scroll.mjs.map
