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

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

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