"use strict";
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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require("@angular/core");
var _ = require("lodash");
var rxjs_1 = require("rxjs");
var windowWrapper_service_1 = require("../windowWrapper/windowWrapper.service");
var visibleBreakpoint_service_1 = require("./visibleBreakpoint.service");
var breakpoint_1 = require("./breakpoint");
exports.breakpointServiceName = 'breakpoints';
exports.RESIZE_DEBOUNCE_MILLISECONDS = 500;
var BreakpointService = (function () {
    function BreakpointService(visibleBreakpoints, windowService) {
        var _this = this;
        this.visibleBreakpoints = visibleBreakpoints;
        this.updateBreakpoint = function () {
            var newBreakPoint = _this.getBreakpoint();
            if (newBreakPoint !== _this.currentBreakpoint) {
                _this.currentBreakpoint = newBreakPoint;
                _this.breakpointChanges.next(_this.currentBreakpoint);
            }
        };
        this.breakpointChanges = new rxjs_1.Subject();
        this.currentBreakpoint = this.getBreakpoint();
        var efficientResize = _.debounce(this.updateBreakpoint, exports.RESIZE_DEBOUNCE_MILLISECONDS, {
            leading: true,
            trailing: true,
            maxWait: exports.RESIZE_DEBOUNCE_MILLISECONDS,
        });
        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 = __decorate([
    core_1.Injectable(),
    __metadata("design:paramtypes", [visibleBreakpoint_service_1.VisibleBreakpointService, windowWrapper_service_1.WindowService])
], BreakpointService);
exports.BreakpointService = BreakpointService;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJlYWtwb2ludHMuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImJyZWFrcG9pbnRzLnNlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLHNDQUE2RDtBQUM3RCwwQkFBNEI7QUFDNUIsNkJBQStCO0FBRS9CLGdGQUF1RjtBQUN2Rix5RUFBa0c7QUFFbEcsMkNBQThDO0FBRWpDLFFBQUEscUJBQXFCLEdBQVcsYUFBYSxDQUFDO0FBRTlDLFFBQUEsNEJBQTRCLEdBQVcsR0FBRyxDQUFDO0FBU3hELElBQWEsaUJBQWlCO0lBRTdCLDJCQUFvQixrQkFBNEMsRUFBRSxhQUE0QjtRQUE5RixpQkFVQztRQVZtQix1QkFBa0IsR0FBbEIsa0JBQWtCLENBQTBCO1FBK0J4RCxxQkFBZ0IsR0FBaUI7WUFDeEMsSUFBSSxhQUFhLEdBQVcsS0FBSSxDQUFDLGFBQWEsRUFBRSxDQUFDO1lBRWpELEVBQUUsQ0FBQyxDQUFDLGFBQWEsS0FBSyxLQUFJLENBQUMsaUJBQWlCLENBQUMsQ0FBQyxDQUFDO2dCQUM5QyxLQUFJLENBQUMsaUJBQWlCLEdBQUcsYUFBYSxDQUFDO2dCQUN2QyxLQUFJLENBQUMsaUJBQWlCLENBQUMsSUFBSSxDQUFDLEtBQUksQ0FBQyxpQkFBaUIsQ0FBQyxDQUFD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