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);
};
import { customElement, ViewSlot } from "aurelia-framework";
import { AppRouter } from "aurelia-router";
import { UIInternal } from "../../utils/ui-internal";
import { Config } from "../../config";
import * as Constants from "../../constants/constants";
export var UIViewport = (function () {
    function UIViewport(element, appConfig, router) {
        var _this = this;
        this.appConfig = appConfig;
        this.router = router;
        element.addEventListener("resize", function () {
            _this.detectSmallDevice();
            UIInternal.broadcast(UIInternal.EVT_VIEWPORT_RESIZE);
        });
        document.addEventListener("mouseup", function ($event) { return _this.broadcastEvent($event); });
        document.addEventListener("wheel", function ($event) { return _this.broadcastWheelEvent($event); });
    }
    UIViewport.prototype.attached = function () {
        this.detectSmallDevice();
        this.appConfig.containerConfig.DialogContainer = new ViewSlot(this.dialogContainer, true);
        this.appConfig.containerConfig.TaskbarContainer = new ViewSlot(this.taskbarContainer, true);
        this.appConfig.containerConfig.DialogContainer.attached();
        this.appConfig.containerConfig.TaskbarContainer.attached();
    };
    UIViewport.prototype.broadcastEvent = function ($event) {
        if (!hasParent($event.target, this.appConfig.containerConfig.FloatingContainer)) {
            UIInternal.broadcast(UIInternal.EVT_VIEWPORT_CLICK, $event.target);
        }
    };
    UIViewport.prototype.broadcastWheelEvent = function ($event) {
        if (!hasParent($event.target, this.appConfig.containerConfig.FloatingContainer)) {
            UIInternal.broadcast(UIInternal.EVT_VIEWPORT_WHEEL, $event.target);
        }
    };
    UIViewport.prototype.detectSmallDevice = function () {
        var windowWidth = window.outerWidth;
        if (windowWidth <= Constants.CSSBreakpoints.xs) {
            if (this.currentCSSBreakpoing != Constants.CSSBreakpoints.xs) {
                this.currentCSSBreakpoing = Constants.CSSBreakpoints.xs;
                UIInternal.broadcast(UIInternal.EVT_VIEWPORT_CSS_BREAKPOINT_CHANGE, this.currentCSSBreakpoing);
            }
        }
        else if (windowWidth <= Constants.CSSBreakpoints.sm) {
            if (this.currentCSSBreakpoing != Constants.CSSBreakpoints.sm) {
                this.currentCSSBreakpoing = Constants.CSSBreakpoints.sm;
                UIInternal.broadcast(UIInternal.EVT_VIEWPORT_CSS_BREAKPOINT_CHANGE, this.currentCSSBreakpoing);
            }
        }
        else if (windowWidth <= Constants.CSSBreakpoints.md) {
            if (this.currentCSSBreakpoing != Constants.CSSBreakpoints.md) {
                this.currentCSSBreakpoing = Constants.CSSBreakpoints.md;
                UIInternal.broadcast(UIInternal.EVT_VIEWPORT_CSS_BREAKPOINT_CHANGE, this.currentCSSBreakpoing);
            }
        }
        else if (windowWidth <= Constants.CSSBreakpoints.lg) {
            if (this.currentCSSBreakpoing != Constants.CSSBreakpoints.lg) {
                this.currentCSSBreakpoing = Constants.CSSBreakpoints.lg;
                UIInternal.broadcast(UIInternal.EVT_VIEWPORT_CSS_BREAKPOINT_CHANGE, this.currentCSSBreakpoing);
            }
        }
        else if (windowWidth <= Constants.CSSBreakpoints.xl) {
            if (this.currentCSSBreakpoing != Constants.CSSBreakpoints.xl) {
                this.currentCSSBreakpoing = Constants.CSSBreakpoints.xl;
                UIInternal.broadcast(UIInternal.EVT_VIEWPORT_CSS_BREAKPOINT_CHANGE, this.currentCSSBreakpoing);
            }
        }
        else {
            if (this.currentCSSBreakpoing != Constants.CSSBreakpoints.xxl) {
                this.currentCSSBreakpoing = Constants.CSSBreakpoints.xxl;
                UIInternal.broadcast(UIInternal.EVT_VIEWPORT_CSS_BREAKPOINT_CHANGE, this.currentCSSBreakpoing);
            }
        }
        if (this.appConfig.globalConfig.isAutomaticSmallDevice) {
            if (windowWidth < Constants.CSSBreakpoints.lg) {
                UIInternal.broadcast(UIInternal.EVT_VIEWPORT_SMALL_DEVICE_ACTIVATED);
                $('body').addClass('small-device');
            }
            else {
                $('body').removeClass('small-device');
            }
        }
    };
    UIViewport = __decorate([
        customElement("ui-viewport"),
        __metadata("design:paramtypes", [Element, Config, AppRouter])
    ], UIViewport);
    return UIViewport;
}());

//# sourceMappingURL=ui-viewport.js.map
