define("wolfRunRules", ["componentmodelComponentApi", "slotModelApi", "clientkernelEventbusApi", "clientkernelModulesApi", "clientkernelLoggerApi", "moneyApi", "RulesDeclaration"],
    function(componentmodelComponentApi, slotModelApi, clientkernelEventbusApi, clientkernelModulesApi, clientkernelLoggerApi, moneyApi, RulesDeclaration) {
        "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 haxe == 'undefined') {
            var haxe = {};
        };

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

        };
        if (typeof wolfRunRules == 'undefined') {
            var wolfRunRules = {};
        };
        wolfRunRules.LoggerFactory = function() {};
        wolfRunRules.LoggerFactory.__name__ = ["wolfRunRules", "LoggerFactory"];
        wolfRunRules.LoggerFactory.lf = null;
        wolfRunRules.LoggerFactory.init = function(lf) {
            wolfRunRules.LoggerFactory.lf = lf;
        };
        wolfRunRules.LoggerFactory.getLogger = function(name, that) {
            if (that != null) return wolfRunRules.LoggerFactory.getOrCreate(_hcmn_.Type.getClassName(_hcmn_.Type.getClass(that)).split(".").pop());
            else if (name != null && name != "") return wolfRunRules.LoggerFactory.getOrCreate(name);
            else return wolfRunRules.LoggerFactory.getOrCreate("slotmodel.mpt");
        };
        wolfRunRules.LoggerFactory.getOrCreate = function(key) {
            if (!wolfRunRules.LoggerFactory.loggers.exists(key)) {
                var value = wolfRunRules.LoggerFactory.lf.getLogger(key);
                wolfRunRules.LoggerFactory.loggers.set(key, value);
            }
            return wolfRunRules.LoggerFactory.loggers.get(key);
        };
        wolfRunRules.LoggerFactory.prototype.__class__ = wolfRunRules.LoggerFactory;
        wolfRunRules.ModuleActivator = function() {};
        wolfRunRules.ModuleActivator = ck_implements(wolfRunRules.ModuleActivator, clientkernelModulesApi.IModuleActivator);
        wolfRunRules.ModuleActivator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        wolfRunRules.ModuleActivator.__name__ = ["wolfRunRules", "ModuleActivator"];
        wolfRunRules.ModuleActivator.prototype.factory = null;
        wolfRunRules.ModuleActivator.prototype.registration = null;
        wolfRunRules.ModuleActivator.prototype.start = function(context) {
            var _g = this;
            context.getServiceTracker([clientkernelLoggerApi.ILoggerFactory, clientkernelEventbusApi.IEventBus]).then(function(mContext) {
                wolfRunRules.LoggerFactory.init(mContext.getAnyService(clientkernelLoggerApi.ILoggerFactory, null));
                _g.factory = new wolfRunRules.RulesFactory(context);
                _g.registration = context.registerService(_g.factory, RulesDeclaration.RulesDeclaration, null);
            });
        };
        wolfRunRules.ModuleActivator.prototype.stop = function(context) {
            if (this.factory.rules != null) {
                this.registration.unregister();
                this.factory.rules.stop();
            }
        };
        wolfRunRules.ModuleActivator.main = function() {};
        wolfRunRules.ModuleActivator.prototype.__class__ = wolfRunRules.ModuleActivator;
        wolfRunRules.Rules = function(smPort) {
            this.logger = wolfRunRules.LoggerFactory.getLogger(null, this);
            this.smPort = smPort;
            this.helpInstance = null;
            this.paytableInstance = null;
            this.subscribe();
        };
        wolfRunRules.Rules.__name__ = ["wolfRunRules", "Rules"];
        wolfRunRules.Rules.prototype.logger = null;
        wolfRunRules.Rules.prototype.smPort = null;
        wolfRunRules.Rules.prototype.helpInstance = null;
        wolfRunRules.Rules.prototype.paytableInstance = null;
        wolfRunRules.Rules.prototype.subscriptions = null;
        wolfRunRules.Rules.prototype.subscribe = function() {
            this.subscriptions = [];
            this.subscriptions.push(this.smPort.getStages().getIdleStage().getOpenHelp().subscribe($bind(this, this.openHelp)));
            this.subscriptions.push(this.smPort.getStages().getIdleStage().getOpenPaytable().subscribe($bind(this, this.openPaytable)));
        };
        wolfRunRules.Rules.prototype.openHelp = 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(null);
                return;
            }
            this.helpInstance = new wolfRunRules.RulesInstance(url, "Help", $bind(this, this.helpClosed));
        };
        wolfRunRules.Rules.prototype.openPaytable = function(event) {
            this.closeHelp(null);
        };
        wolfRunRules.Rules.prototype.closeHelp = function(event) {
            this.logger.debug("closeHelp");
            if (this.helpInstance == null) {
                this.logger.warn("helpInstance == null");
                return;
            }
            this.helpInstance.close();
        };
        wolfRunRules.Rules.prototype.helpClosed = function() {
            this.logger.debug("helpClosed");
            this.helpInstance.close();
            this.helpInstance = null;
        };
        wolfRunRules.Rules.prototype.closePaytable = function(event) {
            this.logger.debug("closePaytable");
            if (this.paytableInstance == null) {
                this.logger.warn("paytableInstance == null");
                return;
            }
            this.paytableInstance.close();
        };
        wolfRunRules.Rules.prototype.paytableClosed = function() {
            this.logger.debug("paytableClosed");
            this.paytableInstance = null;
        };
        wolfRunRules.Rules.prototype.stop = function() {
            this.unsubscribe();
        };
        wolfRunRules.Rules.prototype.unsubscribe = function() {
            if (this.subscriptions == null) return;
            while (this.subscriptions.length > 0) this.subscriptions.pop().unsubscribe();
            this.subscriptions = null;
        };
        wolfRunRules.Rules.prototype.__class__ = wolfRunRules.Rules;
        wolfRunRules.RulesFactory = function(moduleContext) {
            this.moduleContext = moduleContext;
        };
        wolfRunRules.RulesFactory = ck_implements(wolfRunRules.RulesFactory, clientkernelModulesApi.IService);
        wolfRunRules.RulesFactory = ck_implements(wolfRunRules.RulesFactory, componentmodelComponentApi.IComponentFactory);
        wolfRunRules.RulesFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        wolfRunRules.RulesFactory.__name__ = ["wolfRunRules", "RulesFactory"];
        wolfRunRules.RulesFactory.prototype.moduleContext = null;
        wolfRunRules.RulesFactory.prototype.rules = null;
        wolfRunRules.RulesFactory.prototype.getComponentDeclaration = function() {
            return RulesDeclaration.RulesDeclaration;
        };
        wolfRunRules.RulesFactory.prototype.createComponent = function(componentContext) {
            this.rules = new wolfRunRules.Rules(componentContext.getUsedPort(slotModelApi.ISlotModelPort));
        };
        wolfRunRules.RulesFactory.prototype.__class__ = wolfRunRules.RulesFactory;
        wolfRunRules.RulesInstance = function(url, id, closeCallback) {
            wolfRunRules.LoggerFactory.getLogger("RulesInstance").debug("Creating with url: " + url);
            this.logger = wolfRunRules.LoggerFactory.getLogger(null, this);
            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));
        };
        wolfRunRules.RulesInstance.__name__ = ["wolfRunRules", "RulesInstance"];
        wolfRunRules.RulesInstance.prototype.logger = null;
        wolfRunRules.RulesInstance.prototype.iframe = null;
        wolfRunRules.RulesInstance.prototype.node = null;
        wolfRunRules.RulesInstance.prototype.id = null;
        wolfRunRules.RulesInstance.prototype.closeCallback = null;
        wolfRunRules.RulesInstance.prototype.divWrapper = null;
        wolfRunRules.RulesInstance.prototype.onLoad = function(e) {
            this.iframe.height = this.iframe.contentWindow.document.body.scrollHeight + "px";
            this.setDivWrapperStyle();
        };
        wolfRunRules.RulesInstance.prototype.setDivWrapperStyle = function() {
            this.divWrapper.setAttribute("style", "overflow-x: hidden; overflow-y: auto; 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");
        };
        wolfRunRules.RulesInstance.prototype.onResize = function() {
            this.setDivWrapperStyle();
            _hcmn_.haxe_Timer.delay($bind(this, this.updateIFrame), 0);
        };
        wolfRunRules.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";
        };
        wolfRunRules.RulesInstance.prototype.closeListener = function(event) {
            if ("rules:close" + this.id == event.data) {
                window.document.removeEventListener("message", $bind(this, this.closeListener));
                this.close();
            }
        };
        wolfRunRules.RulesInstance.prototype.close = function() {
            this.logger.debug("Closing instance with url: " + this.iframe.src);
            if (this.node == null) return;
            if (this.node.parentNode != null) this.node.parentNode.removeChild(this.node);
            this.node = null;
            this.logger.debug("closeCallback: " + _hcmn_.Std.string(this.closeCallback));
            if (this.closeCallback != null) {
                this.logger.debug("closeCallback called");
                this.closeCallback();
            }
        };
        wolfRunRules.RulesInstance.prototype.__class__ = wolfRunRules.RulesInstance;
        wolfRunRules.LoggerFactory.loggers = new _hcmn_.haxe_ds_StringMap();;
        return {
            exports: wolfRunRules,
            activator: wolfRunRules.ModuleActivator
        };
    });
//# sourceURL=wolfRunRules.js