#include settings.js
#include audio/context.js
#include sound/sndpacks.js
#include sound/seinfeld.js

Umi.Sound = (function() {
    return {
        Play: function(sound) {
            if(!sound || sound === 'none' || !mami.hasSound())
                return;

            const sndPackPlay = mami.getSoundPackPlayer();

            switch(sound) {
                case 'join':
                    if(!Umi.Settings.get('soundEnableJoin'))
                        return;

                    if(Umi.Settings.get('seinfeld')) {
                        mami.playUrlSound(Seinfeld.getRandom());
                        break;
                    }

                    switch(Umi.Settings.get('minecraft')) {
                        case 'yes':
                            mami.playLibrarySound('minecraft:door:open');
                            break;

                        case 'old':
                            mami.playLibrarySound('minecraft:door:open-old');
                            break;

                        default:
                            sndPackPlay.playEvent('join');
                            break;
                    }
                    break;

                case 'leave':
                    if(!Umi.Settings.get('soundEnableLeave'))
                        return;

                    switch(Umi.Settings.get('minecraft')) {
                        case 'yes':
                            mami.playLibrarySound('minecraft:door:close');
                            break;

                        case 'old':
                            mami.playLibrarySound('minecraft:door:close-old');
                            break;

                        default:
                            sndPackPlay.playEvent('leave');
                            break;
                    }
                    break;

                case 'error':
                    if(!Umi.Settings.get('soundEnableError'))
                        return;

                    sndPackPlay.playEvent('error');
                    break;

                case 'server':
                    if(!Umi.Settings.get('soundEnableServer'))
                        return;

                    sndPackPlay.playEvent('server');
                    break;

                case 'unban':
                    if(!Umi.Settings.get('soundEnableServer'))
                        return;

                    sndPackPlay.playEvent(['unban', 'server']);
                    break;

                case 'incoming':
                    if(!Umi.Settings.get('soundEnableIncoming'))
                        return;
                    
                    if(Umi.Settings.get('windowsLiveMessenger')) {
                        mami.playLibrarySound('msn:incoming');
                    } else {
                        sndPackPlay.playEvent('incoming');
                    }
                    break;

                case 'outgoing':
                    if(!Umi.Settings.get('soundEnableOutgoing'))
                        return;

                    sndPackPlay.playEvent('outgoing');
                    break;

                case 'private':
                case 'incoming-priv':
                    if(!Umi.Settings.get('soundEnablePrivate'))
                        return;

                    sndPackPlay.playEvent(['incoming-priv', 'incoming']);
                    break;

                case 'flood':
                    if(!Umi.Settings.get('soundEnableForceLeave'))
                        return;

                    sndPackPlay.playEvent(['flood', 'kick', 'leave']);
                    break;

                case 'timeout':
                    if(!Umi.Settings.get('soundEnableForceLeave'))
                        return;

                    sndPackPlay.playEvent(['timeout', 'leave']);
                    break;

                case 'kick':
                case 'forceLeave':
                    if(!Umi.Settings.get('soundEnableForceLeave'))
                        return;

                    sndPackPlay.playEvent(['kick', 'leave']);
                    break;
            }
        },
    };
})();
