"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
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 __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIViewport = void 0;
var aurelia_framework_1 = require("aurelia-framework");
var aurelia_router_1 = require("aurelia-router");
var ui_internal_1 = require("../../utils/ui-internal");
var config_1 = require("../../config");
var Constants = __importStar(require("../../constants/constants"));
var UIViewport = exports.UIViewport = (function () {
    function UIViewport(element, appConfig, router) {
        var _this = this;
        this.appConfig = appConfig;
        this.router = router;
        element.addEventListener("resize", function () {
            _this.detectSmallDevice();
            ui_internal_1.UIInternal.broadcast(ui_internal_1.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 aurelia_framework_1.ViewSlot(this.dialogContainer, true);
        this.appConfig.containerConfig.TaskbarContainer = new aurelia_framework_1.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)) {
            ui_internal_1.UIInternal.broadcast(ui_internal_1.UIInternal.EVT_VIEWPORT_CLICK, $event.target);
        }
    };
    UIViewport.prototype.broadcastWheelEvent = function ($event) {
        if (!hasParent($event.target, this.appConfig.containerConfig.FloatingContainer)) {
            ui_internal_1.UIInternal.broadcast(ui_internal_1.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;
                ui_internal_1.UIInternal.broadcast(ui_internal_1.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;
                ui_internal_1.UIInternal.broadcast(ui_internal_1.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;
                ui_internal_1.UIInternal.broadcast(ui_internal_1.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;
                ui_internal_1.UIInternal.broadcast(ui_internal_1.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;
                ui_internal_1.UIInternal.broadcast(ui_internal_1.UIInternal.EVT_VIEWPORT_CSS_BREAKPOINT_CHANGE, this.currentCSSBreakpoing);
            }
        }
        else {
            if (this.currentCSSBreakpoing != Constants.CSSBreakpoints.xxl) {
                this.currentCSSBreakpoing = Constants.CSSBreakpoints.xxl;
                ui_internal_1.UIInternal.broadcast(ui_internal_1.UIInternal.EVT_VIEWPORT_CSS_BREAKPOINT_CHANGE, this.currentCSSBreakpoing);
            }
        }
        if (this.appConfig.globalConfig.isAutomaticSmallDevice) {
            if (windowWidth < Constants.CSSBreakpoints.lg) {
                ui_internal_1.UIInternal.broadcast(ui_internal_1.UIInternal.EVT_VIEWPORT_SMALL_DEVICE_ACTIVATED);
                $('body').addClass('small-device');
            }
            else {
                $('body').removeClass('small-device');
            }
        }
    };
    UIViewport = __decorate([
        (0, aurelia_framework_1.customElement)("ui-viewport"),
        __metadata("design:paramtypes", [Element, config_1.Config, aurelia_router_1.AppRouter])
    ], UIViewport);
    return UIViewport;
}());

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