define("ballooniesIXFRules", ["componentmodelComponentApi", "ballooniesIXFRulesDeclaration", "slotModelApi", "clientkernelEventbusApi", "clientkernelModulesApi", "clientkernelLoggerApi", "ballooniesIXFAnimationPort", "moneyApi"],
    function(componentmodelComponentApi, ballooniesIXFRulesDeclaration, slotModelApi, clientkernelEventbusApi, clientkernelModulesApi, clientkernelLoggerApi, ballooniesIXFAnimationPort, moneyApi) {
        "use strict";

        function $iterator(o) {
            if (o instanceof Array) return function() {
                return {
                    cur: 0,
                    arr: o,
                    hasNext: function() {
                        return this.cur < this.arr.length;
                    },
                    next: function() {
                        return this.arr[this.cur++];
                    }
                };
            };
            return typeof(o.iterator) == 'function' ? $bind(o, o.iterator) : o.iterator;
        };;
        var $fid = 0;

        function $bind(o, m) {
            if (m == null) return null;
            if (m.__id__ == null) m.__id__ = $fid++;
            var f;
            if (o.hx__closures__ == null) o.hx__closures__ = {};
            else f = o.hx__closures__[m.__id__];
            if (f == null) {
                f = function() {
                    return f.method.apply(f.scope, arguments);
                };
                f.scope = o;
                f.method = m;
                o.hx__closures__[m.__id__] = f;
            }
            return f;
        };
        var $_;
        var $estr = function() {
            return _hcmn_.js_Boot.__string_rec(this, '');
        };
        if (typeof ballooniesIXFRules == 'undefined') {
            var ballooniesIXFRules = {};
        };
        ballooniesIXFRules.LoggerFactory = function() {};
        ballooniesIXFRules.LoggerFactory.__name__ = ["ballooniesIXFRules", "LoggerFactory"];
        ballooniesIXFRules.LoggerFactory.lf = null;
        ballooniesIXFRules.LoggerFactory.init = function(lf) {
            ballooniesIXFRules.LoggerFactory.lf = lf;
        };
        ballooniesIXFRules.LoggerFactory.getLogger = function(name, that) {
            if (that != null) return ballooniesIXFRules.LoggerFactory.getOrCreate(_hcmn_.Type.getClassName(_hcmn_.Type.getClass(that)).split(".").pop());
            else if (name != null && name != "") return ballooniesIXFRules.LoggerFactory.getOrCreate(name);
            else return ballooniesIXFRules.LoggerFactory.getOrCreate("rules.module");
        };
        ballooniesIXFRules.LoggerFactory.getOrCreate = function(key) {
            if (!ballooniesIXFRules.LoggerFactory.loggers.exists(key)) {
                var value = ballooniesIXFRules.LoggerFactory.lf.getLogger(key);
                ballooniesIXFRules.LoggerFactory.loggers.set(key, value);
            }
            return ballooniesIXFRules.LoggerFactory.loggers.get(key);
        };
        ballooniesIXFRules.LoggerFactory.prototype.__class__ = ballooniesIXFRules.LoggerFactory;
        ballooniesIXFRules.ModuleActivator = function() {};
        ballooniesIXFRules.ModuleActivator = ck_implements(ballooniesIXFRules.ModuleActivator, clientkernelModulesApi.IModuleActivator);
        ballooniesIXFRules.ModuleActivator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        ballooniesIXFRules.ModuleActivator.__name__ = ["ballooniesIXFRules", "ModuleActivator"];
        ballooniesIXFRules.ModuleActivator.prototype.factory = null;
        ballooniesIXFRules.ModuleActivator.prototype.registration = null;
        ballooniesIXFRules.ModuleActivator.prototype.start = function(context) {
            var _g = this;
            context.getServiceTracker([clientkernelLoggerApi.ILoggerFactory, clientkernelEventbusApi.IEventBus]).then(function(mContext) {
                ballooniesIXFRules.LoggerFactory.init(mContext.getAnyService(clientkernelLoggerApi.ILoggerFactory, null));
                _g.factory = new ballooniesIXFRules.RulesFactory(context);
                _g.registration = context.registerService(_g.factory, ballooniesIXFRulesDeclaration.RulesDeclaration, null);
            });
        };
        ballooniesIXFRules.ModuleActivator.prototype.stop = function(context) {
            if (this.factory.rules != null) {
                this.registration.unregister();
                this.factory.rules.stop();
            }
        };
        ballooniesIXFRules.ModuleActivator.main = function() {};
        ballooniesIXFRules.ModuleActivator.prototype.__class__ = ballooniesIXFRules.ModuleActivator;
        ballooniesIXFRules.Rules = function(componentContext) {
            this.isPaytableOpened = false;
            this.logger = ballooniesIXFRules.LoggerFactory.getLogger(null, this);
            this.slotModelPort = componentContext.getUsedPort(slotModelApi.ISlotModelPort);
            this.animationsPort = componentContext.getUsedPort(ballooniesIXFAnimationPort.IAnimationPort);
            this.helpInstance = null;
            this.subscribe();
        };
        ballooniesIXFRules.Rules.__name__ = ["ballooniesIXFRules", "Rules"];
        ballooniesIXFRules.Rules.prototype.logger = null;
        ballooniesIXFRules.Rules.prototype.slotModelPort = null;
        ballooniesIXFRules.Rules.prototype.animationsPort = null;
        ballooniesIXFRules.Rules.prototype.helpInstance = null;
        ballooniesIXFRules.Rules.prototype.subscriptions = null;
        ballooniesIXFRules.Rules.prototype.isPaytableOpened = null;
        ballooniesIXFRules.Rules.prototype.subscribe = function() {
            this.subscriptions = [];
            var idleStagePort = this.slotModelPort.getStages().getIdleStage();
            this.subscriptions.push(idleStagePort.getOpenHelp().subscribe($bind(this, this.onOpenHelp)));
            this.subscriptions.push(idleStagePort.getOpenPaytable().subscribe($bind(this, this.onOpenPaytable)));
        };
        ballooniesIXFRules.Rules.prototype.onOpenHelp = function(event) {
            var url = event.getPayload();
            this.logger.debug("openHelp with url:" + url);
            if (url == null || url == "") {
                this.logger.warn("url == null || url == \"\"");
                return;
            }
            if (window.document.getElementById("rulesInstance") != null) {
                this.closeHelp();
                return;
            }
            this.helpInstance = new ballooniesIXFRules.RulesInstance(url, "Help", $bind(this, this.onHelpClosed));
            this.animationsPort.getMainLogo().sleep();
            this.isPaytableOpened = false;
        };
        ballooniesIXFRules.Rules.prototype.onOpenPaytable = function(event) {
            this.isPaytableOpened = true;
            this.closeHelp();
        };
        ballooniesIXFRules.Rules.prototype.closeHelp = function() {
            this.logger.debug("closeHelp");
            if (this.helpInstance == null) {
                this.logger.warn("helpInstance == null");
                return;
            }
            this.helpInstance.close();
        };
        ballooniesIXFRules.Rules.prototype.onHelpClosed = function() {
            this.logger.debug("helpClosed");
            if (!this.isPaytableOpened) this.animationsPort.getMainLogo().wakeUp();
            this.helpInstance = null;
        };
        ballooniesIXFRules.Rules.prototype.stop = function() {
            this.unsubscribe();
        };
        ballooniesIXFRules.Rules.prototype.unsubscribe = function() {
            if (this.subscriptions == null) return;
            while (this.subscriptions.length > 0) this.subscriptions.pop().unsubscribe();
            this.subscriptions = null;
        };
        ballooniesIXFRules.Rules.prototype.__class__ = ballooniesIXFRules.Rules;
        ballooniesIXFRules.RulesFactory = function(moduleContext) {};
        ballooniesIXFRules.RulesFactory = ck_implements(ballooniesIXFRules.RulesFactory, clientkernelModulesApi.IService);
        ballooniesIXFRules.RulesFactory = ck_implements(ballooniesIXFRules.RulesFactory, componentmodelComponentApi.IComponentFactory);
        ballooniesIXFRules.RulesFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        ballooniesIXFRules.RulesFactory.__name__ = ["ballooniesIXFRules", "RulesFactory"];
        ballooniesIXFRules.RulesFactory.prototype.rules = null;
        ballooniesIXFRules.RulesFactory.prototype.getComponentDeclaration = function() {
            return ballooniesIXFRulesDeclaration.RulesDeclaration;
        };
        ballooniesIXFRules.RulesFactory.prototype.createComponent = function(componentContext) {
            this.rules = new ballooniesIXFRules.Rules(componentContext);
        };
        ballooniesIXFRules.RulesFactory.prototype.__class__ = ballooniesIXFRules.RulesFactory;
        ballooniesIXFRules.RulesInstance = function(url, id, closeCallback) {
            this.logger = ballooniesIXFRules.LoggerFactory.getLogger(null, this);
            this.logger.debug("Creating with url:" + url);
            this.id = id;
            this.closeCallback = closeCallback;
            var _this = window.document;
            this.iframe = _this.createElement("iframe");
            this.iframe.marginHeight = "0";
            this.iframe.marginWidth = "0";
            this.iframe.src = url;
            this.iframe.frameBorder = "0";
            this.iframe.setAttribute("style", "width:100%; height:100%; min-height:101%; background:white; position:absolute;");
            this.iframe.height = window.document.body.scrollHeight + "px";
            var _this1 = window.document;
            this.divWrapper = _this1.createElement("div");
            this.setDivWrapperStyle();
            this.divWrapper.appendChild(this.iframe);
            this.divWrapper.id = "rulesInstance";
            this.node = window.document.body.appendChild(this.divWrapper);
            window.addEventListener("resize", $bind(this, this.onResize));
            this.iframe.addEventListener("load", $bind(this, this.onLoad));
            window.addEventListener("closeHelp", $bind(this, this.onCloseHelp));
        };
        ballooniesIXFRules.RulesInstance.__name__ = ["ballooniesIXFRules", "RulesInstance"];
        ballooniesIXFRules.RulesInstance.prototype.logger = null;
        ballooniesIXFRules.RulesInstance.prototype.iframe = null;
        ballooniesIXFRules.RulesInstance.prototype.node = null;
        ballooniesIXFRules.RulesInstance.prototype.id = null;
        ballooniesIXFRules.RulesInstance.prototype.closeCallback = null;
        ballooniesIXFRules.RulesInstance.prototype.divWrapper = null;
        ballooniesIXFRules.RulesInstance.prototype.onLoad = function(e) {
            this.iframe.height = this.iframe.contentWindow.document.body.scrollHeight + "px";
            this.setDivWrapperStyle();
        };
        ballooniesIXFRules.RulesInstance.prototype.setDivWrapperStyle = function() {
            if (this.isAppleDevice()) this.divWrapper.setAttribute("style", "overflow-x: hidden; overflow-y: auto; width:100%; height:100%; position: absolute; z-index: 99999; background:white; top:0px");
            else this.divWrapper.setAttribute("style", "width:100%; height:100%; position: absolute; z-index: 99999; background:white; top:0px");
            this.divWrapper.style.setProperty("-webkit-overflow-scrolling", "touch");
            this.divWrapper.style.setProperty("-webkit-user-select", "none");
            this.divWrapper.style.setProperty("-webkit-text-size-adjust", "none");
        };
        ballooniesIXFRules.RulesInstance.prototype.isAppleDevice = function() {
            return new _hcmn_.EReg("iP(hone|od|ad)", "").match(window.navigator.platform);
        };
        ballooniesIXFRules.RulesInstance.prototype.onResize = function() {
            this.setDivWrapperStyle();
            _hcmn_.haxe_Timer.delay($bind(this, this.updateIFrame), 0);
        };
        ballooniesIXFRules.RulesInstance.prototype.updateIFrame = function() {
            if (this.iframe == null || this.iframe.contentWindow == null || this.iframe.contentWindow.document == null) {
                window.removeEventListener("resize", $bind(this, this.onResize));
                this.iframe.removeEventListener("load", $bind(this, this.onLoad));
                this.divWrapper = null;
                this.iframe = null;
                return;
            }
            this.iframe.height = this.iframe.contentWindow.document.body.scrollHeight + "px";
        };
        ballooniesIXFRules.RulesInstance.prototype.onCloseHelp = function() {
            this.close();
        };
        ballooniesIXFRules.RulesInstance.prototype.close = function() {
            this.logger.debug("Closing instance with url:" + this.iframe.src);
            window.removeEventListener("closeHelp", $bind(this, this.onCloseHelp));
            this.logger.debug("closeCallback:" + _hcmn_.Std.string(this.closeCallback));
            if (this.closeCallback != null) {
                this.logger.debug("closeCallback called");
                this.closeCallback();
            }
            if (this.node == null) return;
            if (this.node.parentNode != null) this.node.parentNode.removeChild(this.node);
            this.node = null;
        };
        ballooniesIXFRules.RulesInstance.prototype.__class__ = ballooniesIXFRules.RulesInstance;
        if (typeof haxe == 'undefined') {
            var haxe = {};
        };

        haxe.IMap = function() {}
        haxe.IMap.prototype = {

        };
        ballooniesIXFRules.LoggerFactory.loggers = new _hcmn_.haxe_ds_StringMap();;
        return {
            exports: ballooniesIXFRules,
            activator: ballooniesIXFRules.ModuleActivator
        };
    });
//# sourceURL=ballooniesIxfRules.js