"use strict";
var _ = require("lodash");
var rxjs_1 = require("rxjs");
var componentsDowngrade_1 = require("../../componentsDowngrade");
var visibleBreakpoint_service_1 = require("./visibleBreakpoint.service");
var breakpoint_1 = require("./breakpoint");
exports.breakpointServiceName = 'breakpoints';
var BreakpointService = (function () {
    function BreakpointService($rootScope, visibleBreakpoints, resizeDebounceMilliseconds, windowService) {
        var _this = this;
        this.$rootScope = $rootScope;
        this.visibleBreakpoints = visibleBreakpoints;
        this.updateBreakpoint = function () {
            var newBreakPoint = _this.getBreakpoint();
            if (newBreakPoint !== _this.currentBreakpoint) {
                _this.$rootScope.$apply(function () {
                    _this.currentBreakpoint = newBreakPoint;
                    _this.breakpointChanges.next(_this.currentBreakpoint);
                });
            }
        };
        this.breakpointChanges = new rxjs_1.Subject();
        this.currentBreakpoint = this.getBreakpoint();
        var efficientResize = _.debounce(this.updateBreakpoint, resizeDebounceMilliseconds, {
            leading: true,
            trailing: true,
            maxWait: resizeDebounceMilliseconds,
        });
        windowService.resize(efficientResize);
    }
    BreakpointService.prototype.getBreakpoint = function () {
        if (this.visibleBreakpoints.isVisible(breakpoint_1.lg)) {
            return breakpoint_1.lg;
        }
        else if (this.visibleBreakpoints.isVisible(breakpoint_1.md)) {
            return breakpoint_1.md;
        }
        else if (this.visibleBreakpoints.isVisible(breakpoint_1.sm)) {
            return breakpoint_1.sm;
        }
        else {
            return breakpoint_1.xs;
        }
    };
    BreakpointService.prototype.isBreakpoint = function (breakpoint) {
        return this.currentBreakpoint === breakpoint;
    };
    return BreakpointService;
}());
BreakpointService.$inject = ['$rootScope', visibleBreakpoint_service_1.visibleBreakpointServiceName, 'resizeDebounceMilliseconds', componentsDowngrade_1.windowServiceName];
exports.BreakpointService = BreakpointService;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJlYWtwb2ludHMuc2VydmljZS5uZzEuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJicmVha3BvaW50cy5zZXJ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