var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { share } from 'rxjs/operators';
/**
 * Layout scroll service. Provides information about current scroll position,
 * as well as methods to update position of the scroll.
 *
 * The reason we added this service is that in Endlessjs there are two scroll modes:
 * - the default mode when scroll is on body
 * - and the `withScroll` mode, when scroll is removed from the body and moved to an element inside of the
 * `el-layout` component
 */
var ElLayoutScrollService = /** @class */ (function () {
    function ElLayoutScrollService() {
        this.scrollPositionReq$ = new Subject();
        this.manualScroll$ = new Subject();
        this.scroll$ = new Subject();
        this.scrollable$ = new Subject();
    }
    /**
     * Returns scroll position
     *
     * @returns {Observable<ElScrollPosition>}
     */
    ElLayoutScrollService.prototype.getPosition = function () {
        var _this = this;
        return Observable.create(function (observer) {
            var listener = new Subject();
            listener.subscribe(observer);
            _this.scrollPositionReq$.next({ listener: listener });
            return function () { return listener.complete(); };
        });
    };
    /**
     * Sets scroll position
     *
     * @param {number} x
     * @param {number} y
     */
    ElLayoutScrollService.prototype.scrollTo = function (x, y) {
        if (x === void 0) { x = null; }
        if (y === void 0) { y = null; }
        this.manualScroll$.next({ x: x, y: y });
    };
    /**
     * Returns a stream of scroll events
     *
     * @returns {Observable<any>}
     */
    ElLayoutScrollService.prototype.onScroll = function () {
        return this.scroll$.pipe(share());
    };
    /**
     * @private
     * @returns Observable<ElScrollPosition>.
     */
    ElLayoutScrollService.prototype.onManualScroll = function () {
        return this.manualScroll$.pipe(share());
    };
    /**
     * @private
     * @returns {Subject<any>}
     */
    ElLayoutScrollService.prototype.onGetPosition = function () {
        return this.scrollPositionReq$;
    };
    ElLayoutScrollService.prototype.onScrollableChange = function () {
        return this.scrollable$.pipe(share());
    };
    /**
     * @private
     * @param {any} event
     */
    ElLayoutScrollService.prototype.fireScrollChange = function (event) {
        this.scroll$.next(event);
    };
    ElLayoutScrollService.prototype.scrollable = function (scrollable) {
        this.scrollable$.next(scrollable);
    };
    ElLayoutScrollService = __decorate([
        Injectable()
    ], ElLayoutScrollService);
    return ElLayoutScrollService;
}());
export { ElLayoutScrollService };
//# sourceMappingURL=scroll.service.js.map