define("soundmanager", ["componentmodelComponentApi", "clientkernelLoaderApi", "soundManagerApi", "clientkernelEventbusApi", "clientkernelModulesApi"],
    function(componentmodelComponentApi, clientkernelLoaderApi, soundManagerApi, clientkernelEventbusApi, clientkernelModulesApi) {
        "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 (!haxe.ds) {
            haxe.ds = {};
        };
        if (!haxe.ds._StringMap) {
            haxe.ds._StringMap = {};
        };
        haxe.ds._StringMap.StringMapIterator = function(map, keys) {
            this.map = map;
            this.keys = keys;
            this.index = 0;
            this.count = keys.length;
        };
        haxe.ds._StringMap.StringMapIterator.__name__ = ["haxe", "ds", "_StringMap", "StringMapIterator"];
        haxe.ds._StringMap.StringMapIterator.prototype.map = null;
        haxe.ds._StringMap.StringMapIterator.prototype.keys = null;
        haxe.ds._StringMap.StringMapIterator.prototype.index = null;
        haxe.ds._StringMap.StringMapIterator.prototype.count = null;
        haxe.ds._StringMap.StringMapIterator.prototype.hasNext = function() {
            return this.index < this.count;
        };
        haxe.ds._StringMap.StringMapIterator.prototype.next = function() {
            return this.map.get(this.keys[this.index++]);
        };
        haxe.ds._StringMap.StringMapIterator.prototype.__class__ = haxe.ds._StringMap.StringMapIterator;
        if (typeof soundmanager == 'undefined') {
            var soundmanager = {};
        };
        soundmanager.Activator = function(context) {};
        soundmanager.Activator = ck_implements(soundmanager.Activator, clientkernelModulesApi.IModuleActivator);
        soundmanager.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        soundmanager.Activator.__name__ = ["soundmanager", "Activator"];
        soundmanager.Activator.prototype.start = function(context) {
            context.getServiceTracker([clientkernelEventbusApi.IEventBus]).then(function(context1) {
                soundmanager.ExternalService.initialize(context1);
                var bus = context1.getAnyService(clientkernelEventbusApi.IEventBus);
                context1.registerService(new soundmanager.SoundManagerFactory(bus), soundManagerApi.SoundManagerDeclaration, null);
            });
        };
        soundmanager.Activator.prototype.stop = function(context) {};
        soundmanager.Activator.main = function() {};
        soundmanager.Activator.prototype.__class__ = soundmanager.Activator;
        soundmanager.SoundInstance = function(howl, sprite, values) {
            this.isFading = false;
            this.howl = howl;
            this._sprite = sprite;
            this._duration = values[1];
        };
        soundmanager.SoundInstance.__name__ = ["soundmanager", "SoundInstance"];
        soundmanager.SoundInstance.prototype._baseGameLoopId = null;
        soundmanager.SoundInstance.prototype._freespinLoopId = null;
        soundmanager.SoundInstance.prototype._id = null;
        soundmanager.SoundInstance.prototype.howl = null;
        soundmanager.SoundInstance.prototype._sprite = null;
        soundmanager.SoundInstance.prototype._isPlaying = null;
        soundmanager.SoundInstance.prototype._duration = null;
        soundmanager.SoundInstance.prototype.fadeOutTimeout = null;
        soundmanager.SoundInstance.prototype.isFading = null;
        soundmanager.SoundInstance.prototype.executeAction = function(action, duration) {
            if (duration == null) duration = 3000;
            switch (action) {
                case "play":
                    this.play();
                    break;
                case "stop":
                    this.stop();
                    break;
                case "fade_out":
                    this.fadeOutSound(duration);
                    break;
                case "fade_in":
                    this.fadeInSound(duration);
                    break;
            }
        };
        soundmanager.SoundInstance.prototype.mute = function() {
            this.howl.mute(true, this._id);
        };
        soundmanager.SoundInstance.prototype.unmute = function() {
            this.howl.mute(false, this._id);
        };
        soundmanager.SoundInstance.prototype.destroy = function() {
            this.destroy();
        };
        soundmanager.SoundInstance.prototype.play = function() {
            this._id = this.howl.play(this._sprite);
            this._isPlaying = true;
        };
        soundmanager.SoundInstance.prototype.stop = function() {
            this.howl.stop(this._id);
            this._isPlaying = false;
        };
        soundmanager.SoundInstance.prototype.fadeOutSound = function(fadeTime) {
            this.howl.fade(1, 0, fadeTime, this._id);
        };
        soundmanager.SoundInstance.prototype.fadeInSound = function(fadeTime) {
            this.howl.fade(0, 1, fadeTime, this._id);
        };
        soundmanager.SoundInstance.prototype.__class__ = soundmanager.SoundInstance;
        soundmanager.DummySoundInstance = function() {
            var h = {};
            soundmanager.SoundInstance.call(this, h, "", []);
        };
        soundmanager.DummySoundInstance.__name__ = ["soundmanager", "DummySoundInstance"];
        soundmanager.DummySoundInstance.__super__ = soundmanager.SoundInstance;
        for (var k in soundmanager.SoundInstance.prototype) soundmanager.DummySoundInstance.prototype[k] = soundmanager.SoundInstance.prototype[k];
        soundmanager.DummySoundInstance.prototype.play = function() {};
        soundmanager.DummySoundInstance.prototype.executeAction = function(action, duration) {
            if (duration == null) duration = 0;
        };
        soundmanager.DummySoundInstance.prototype.__class__ = soundmanager.DummySoundInstance;
        soundmanager.ExternalService = function() {};
        soundmanager.ExternalService.__name__ = ["soundmanager", "ExternalService"];
        soundmanager.ExternalService.assetRegistry = null;
        soundmanager.ExternalService.variableRegistry = null;
        soundmanager.ExternalService.initialize = function(context) {
            soundmanager.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
            soundmanager.ExternalService.variableRegistry = context.getAnyService(clientkernelLoaderApi.IVariableRegistry, null);
        };
        soundmanager.ExternalService.prototype.__class__ = soundmanager.ExternalService;
        soundmanager.SoundAction = function(obj) {
            this.action_id = obj.id;
            this.action_type = obj.action;
        };
        soundmanager.SoundAction.__name__ = ["soundmanager", "SoundAction"];
        soundmanager.SoundAction.prototype.action_id = null;
        soundmanager.SoundAction.prototype.action_type = null;
        soundmanager.SoundAction.prototype.__class__ = soundmanager.SoundAction;
        soundmanager.SoundManager = function(bus, context) {
            this.initClickDisabled = false;
            this.mobileGame = false;
            this.soundEnabled = true;
            this.freespinEndWinGroup = 0;
            this.winJingle = "";
            this.outcomeWinvalue = 0;
            this.reelsWithWild = [];
            this.freegameOn = false;
            this.bgMusicIsPlaying = false;
            this.hasWildFlag = false;
            this.hasWinFlag = false;
            this.musicMuted = false;
            this.soundsMuted = false;
            var _g2 = this;
            var ua = window.navigator.userAgent;
            var isIE = ua.indexOf("MSIE ");
            var trident = ua.indexOf("Trident/");
            var edge = ua.indexOf("Edge/");
            this.bus = bus;
            this.ccontext = context;
            this.eventmap = new _hcmn_.haxe_ds_StringMap();
            this.port = this.ccontext.getImplementedPort(soundManagerApi.ISoundManagerImplementationPort);
            if (trident == 36 || trident == 59) this.soundInstances = new soundmanager.Sounds("soundplayer-assets/soundsIE", this.port);
            else this.soundInstances = new soundmanager.Sounds("soundplayer-assets/sounds", this.port);
            soundmanager.ExternalService.assetRegistry.getAsset("soundplayer-assets/soundevents").getContent().then(function(_eventmap) {
                var _g = 0;
                var _g1 = _hcmn_.Reflect.fields(_eventmap);
                while (_g < _g1.length) {
                    var i = _g1[_g];
                    ++_g;
                    var arr = _hcmn_.Reflect.field(_eventmap, i);
                    var actions = [];
                    var _g3 = 0;
                    var _g21 = arr.length;
                    while (_g3 < _g21) {
                        var j = _g3++;
                        var sAction = new soundmanager.SoundAction(arr[j]);
                        actions.push(sAction);
                    }
                    _g2.eventmap.set(i, actions);
                }
            });
            if (this.isMobileGame()) {
                this.mobileGame = true;
                this.soundInstances.load().then(function(e) {
                    _g2.subscribeToSoundActions();
                });
            } else this.soundInstances.load().then(function(e1) {
                _g2.subscribeToSoundActions();
            });
        };
        soundmanager.SoundManager.__name__ = ["soundmanager", "SoundManager"];
        soundmanager.SoundManager.prototype.port = null;
        soundmanager.SoundManager.prototype.ccontext = null;
        soundmanager.SoundManager.prototype.bus = null;
        soundmanager.SoundManager.prototype.soundInstances = null;
        soundmanager.SoundManager.prototype.eventmap = null;
        soundmanager.SoundManager.prototype.soundsMuted = null;
        soundmanager.SoundManager.prototype.musicMuted = null;
        soundmanager.SoundManager.prototype.hasWinFlag = null;
        soundmanager.SoundManager.prototype.hasWildFlag = null;
        soundmanager.SoundManager.prototype.bgMusicIsPlaying = null;
        soundmanager.SoundManager.prototype.bgMusicTimeoutId = null;
        soundmanager.SoundManager.prototype.freegameOn = null;
        soundmanager.SoundManager.prototype.reelsWithWild = null;
        soundmanager.SoundManager.prototype.bellRinging = null;
        soundmanager.SoundManager.prototype.outcomeWinvalue = null;
        soundmanager.SoundManager.prototype.winJingle = null;
        soundmanager.SoundManager.prototype.timeoutId = null;
        soundmanager.SoundManager.prototype.explosionTimeoutId = null;
        soundmanager.SoundManager.prototype.paytableNavFlag = null;
        soundmanager.SoundManager.prototype.freespinEndWinGroup = null;
        soundmanager.SoundManager.prototype.soundEnabled = null;
        soundmanager.SoundManager.prototype.mobileGame = null;
        soundmanager.SoundManager.prototype.initClickDisabled = null;
        soundmanager.SoundManager.prototype.subscribeToSoundActions = function() {
            var _g = this;
            this.bus.getChannel("GFBus").subscribe("*", $bind(this, this.onAllEvents));
            Visibility.change($bind(this, this.handleVisibilityChange));
            this.port.setGameMode().subscribe(function(event) {
                if ((function($this) {
                        var $r;
                        var a = event.getPayload();
                        $r = _hcmn_.Type.enumEq(a, soundManagerApi.EGameMode.FreeSpin);
                        return $r;
                    }(this))) _g.freegameOn = true;
                else if ((function($this) {
                        var $r;
                        var a1 = event.getPayload();
                        $r = _hcmn_.Type.enumEq(a1, soundManagerApi.EGameMode.BaseGame);
                        return $r;
                    }(this))) _g.freegameOn = false;
            });
            this.port.muteAll().subscribe(function(event1) {
                _g.soundInstances.turnOffSounds();
            });
            this.port.unmuteAll().subscribe(function(event2) {
                _g.soundInstances.turnOnSounds();
            });
            this.port.play().subscribe(function(event3) {
                _g.soundInstances.get(event3.getPayload()).executeAction("play");
            });
            this.port.stop().subscribe(function(event4) {
                _g.soundInstances.get(event4.getPayload()).executeAction("stop");
            });
            this.port.fadeIn().subscribe(function(event5) {
                _g.soundInstances.get(event5.getPayload().soundId).executeAction("fade_in");
            });
            this.port.fadeOut().subscribe(function(event6) {
                _g.soundInstances.get(event6.getPayload().soundId).executeAction("fade_out");
            });
            this.port.mute().subscribe(function(event7) {
                _g.soundInstances.get(event7.getPayload()).executeAction("mute");
            });
            this.port.unmute().subscribe(function(event8) {
                _g.soundInstances.get(event8.getPayload()).executeAction("unmute");
            });
        };
        soundmanager.SoundManager.prototype.handleVisibilityChange = function(e, state) {
            if (state == "hidden") {
                this.soundsMuted = true;
                var $it0 = this.soundInstances.iterator();
                while ($it0.hasNext()) {
                    var value = $it0.next();
                    if (value._isPlaying) value.executeAction("mute");
                }
            } else if (state == "visible") {
                this.soundsMuted = false;
                var $it1 = this.soundInstances.iterator();
                while ($it1.hasNext()) {
                    var value1 = $it1.next();
                    if (value1._isPlaying) value1.executeAction("unmute");
                }
            }
        };
        soundmanager.SoundManager.prototype.onAllEvents = function(e) {
            var topic = e.getTopic();
            var payload = e.getPayload();
            if (payload) {
                if (payload.key) {
                    var _g = payload.key;
                    switch (_g) {
                        case "sound":
                            if (payload.value == "1") this.turnOffSounds();
                            else this.turnOnSounds();
                            break;
                    }
                }
            }
            if (this.eventmap.exists(topic)) {
                var arr = this.eventmap.get(topic);
                var _g1 = 0;
                var _g2 = arr.length;
                while (_g1 < _g2) {
                    var i = _g1++;
                    if (this.soundsMuted && (arr[i].action_type == "fade_in" || arr[i].action_type == "fade_out")) return;
                    else if (!this.soundsMuted) {
                        if (topic == "betpanel:setStake" && !this.initClickDisabled) {
                            this.initClickDisabled = true;
                            return;
                        }
                        this.soundInstances.get(arr[i].action_id).executeAction(arr[i].action_type);
                    }
                }
            }
        };
        soundmanager.SoundManager.prototype.turnOffSounds = function() {
            this.soundsMuted = true;
        };
        soundmanager.SoundManager.prototype.turnOnSounds = function() {
            this.soundsMuted = false;
        };
        soundmanager.SoundManager.prototype.enableSound = function(value) {
            if (value && !this.soundEnabled) {
                this.soundEnabled = true;
                this.subscribeToSoundActions();
            }
        };
        soundmanager.SoundManager.prototype.isMobileGame = function() {
            if (soundmanager.ExternalService.variableRegistry.get("skin") == "desktop") return false;
            else if (soundmanager.ExternalService.variableRegistry.get("assetPack") == "desktop") return false;
            else return true;
        };
        soundmanager.SoundManager.prototype.__class__ = soundmanager.SoundManager;
        soundmanager.SoundManagerFactory = function(bus) {
            this.bus = bus;
        };
        soundmanager.SoundManagerFactory = ck_implements(soundmanager.SoundManagerFactory, clientkernelModulesApi.IService);
        soundmanager.SoundManagerFactory = ck_implements(soundmanager.SoundManagerFactory, componentmodelComponentApi.IComponentFactory);
        soundmanager.SoundManagerFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        soundmanager.SoundManagerFactory.__name__ = ["soundmanager", "SoundManagerFactory"];
        soundmanager.SoundManagerFactory.prototype.bus = null;
        soundmanager.SoundManagerFactory.prototype.assetRegistry = null;
        soundmanager.SoundManagerFactory.prototype.getComponentDeclaration = function() {
            return soundManagerApi.SoundManagerDeclaration;
        };
        soundmanager.SoundManagerFactory.prototype.createComponent = function(context) {
            new soundmanager.SoundManager(this.bus, context);
        };
        soundmanager.SoundManagerFactory.prototype.__class__ = soundmanager.SoundManagerFactory;
        soundmanager.Sounds = function(soundAssetId, port) {
            this.loaded = false;
            this.dummySoundInstance = new soundmanager.DummySoundInstance();
            this.soundAssetId = soundAssetId;
            this.soundsArray = [];
            this.port = port;
        };
        soundmanager.Sounds.__name__ = ["soundmanager", "Sounds"];
        soundmanager.Sounds.prototype.soundInstances = null;
        soundmanager.Sounds.prototype.dummySoundInstance = null;
        soundmanager.Sounds.prototype.loaded = null;
        soundmanager.Sounds.prototype.soundAssetId = null;
        soundmanager.Sounds.prototype.soundsArray = null;
        soundmanager.Sounds.prototype.howl = null;
        soundmanager.Sounds.prototype.port = null;
        soundmanager.Sounds.prototype.get = function(key) {
            if (!this.loaded) {
                this.load();
                return this.dummySoundInstance;
            } else return this.soundInstances.get(key);
        };
        soundmanager.Sounds.prototype.iterator = function() {
            return this.soundInstances.iterator();
        };
        soundmanager.Sounds.prototype.muteSounds = function() {
            var _g1 = 0;
            var _g = this.soundsArray.length;
            while (_g1 < _g) {
                var i = _g1++;
                this.howl.mute(true, this.soundInstances.get(this.soundsArray[i])._id);
            }
        };
        soundmanager.Sounds.prototype.unmuteSounds = function() {
            var _g1 = 0;
            var _g = this.soundsArray.length;
            while (_g1 < _g) {
                var i = _g1++;
                this.howl.mute(false, this.soundInstances.get(this.soundsArray[i])._id);
            }
        };
        soundmanager.Sounds.prototype.muteAllSounds = function() {
            var _g1 = 0;
            var _g = this.soundsArray.length;
            while (_g1 < _g) {
                var i = _g1++;
                this.howl.mute(true, this.soundInstances.get(this.soundsArray[i])._id);
            }
        };
        soundmanager.Sounds.prototype.unmuteAllSounds = function() {
            var _g1 = 0;
            var _g = this.soundsArray.length;
            while (_g1 < _g) {
                var i = _g1++;
                this.howl.mute(false, this.soundInstances.get(this.soundsArray[i])._id);
            }
        };
        soundmanager.Sounds.prototype.turnOffSounds = function() {
            var _g1 = 0;
            var _g = this.soundsArray.length;
            while (_g1 < _g) {
                var i = _g1++;
                this.howl.volume(0, this.soundInstances.get(this.soundsArray[i])._id);
            }
        };
        soundmanager.Sounds.prototype.turnOnSounds = function() {
            var _g1 = 0;
            var _g = this.soundsArray.length;
            while (_g1 < _g) {
                var i = _g1++;
                this.howl.volume(1, this.soundInstances.get(this.soundsArray[i])._id);
            }
        };
        soundmanager.Sounds.prototype.load = function() {
            var _g = this;
            var loadPromise = new Promise(function(resolve, reject) {
                soundmanager.ExternalService.assetRegistry.getAsset(_g.soundAssetId).getContent().then(function(sound) {
                    soundmanager.ExternalService.assetRegistry.getAsset("soundmaps/soundmap").getContent().then(function(soundmap) {
                        _g.soundInstances = new _hcmn_.haxe_ds_StringMap();
                        _g.howl = sound;
                        var _g1 = 0;
                        var _g2 = _hcmn_.Reflect.fields(soundmap);
                        while (_g1 < _g2.length) {
                            var i = _g2[_g1];
                            ++_g1;
                            var val = _hcmn_.Reflect.field(soundmap, i);
                            var soundInstance = new soundmanager.SoundInstance(_g.howl, i, val);
                            _g.soundInstances.set(i, soundInstance);
                            _g.soundsArray.push(i);
                        }
                        _g.loaded = true;
                        _g.port.onLoaded().publish(null);
                        resolve(null);
                    });
                });
            });
            return loadPromise;
        };
        soundmanager.Sounds.prototype.__class__ = soundmanager.Sounds;
        soundmanager.SoundManager.LOADER_CHANNEL = "loader";;
        return {
            exports: soundmanager,
            activator: soundmanager.Activator
        };
    });
//# sourceURL=soundManager.js