const MamiSockChatModals = function(settings, msgbox, sound) {
    const strings = {
        'crchan': { text: 'Channel %0 has been created.' },
        'delchan': { text: 'Channel %0 has been deleted.' },
        'cpwdchan': { text: 'Channel password has been changed.' },
        'cprivchan': { text: 'Channel access level has been changed.' },
        'flwarn': { text: 'You are about to hit the flood limit! If you continue you will be kicked.' },
        'unban': { text: '%0 is no longer banned.', sound: ['unban', 'server'] },

        'generr': { text: 'Something unexpected happened.', error: true },
        'delerr': { text: 'You are not allowed to delete this message.', error: true },
        'notban': { text: '%0 is not banned.', error: true },
        'whoerr': { text: '%0 does not exist.', error: true },
        'cmdna': { text: 'You are not allowed to use %0.', error: true },
        'nocmd': { text: 'Command %0 does not exist.', error: true },
        'cmderr': { text: 'You did not use that command correctly.', error: true },
        'usernf': { text: '%0 is not logged in right now!', error: true },
        'kickna': { text: 'You are not allowed to kick %0.', error: true },
        'samechan': { text: 'You are already in channel %0.', error: true },
        'ipchan': { text: 'You are not allowed to join channel %0.', error: true },
        'nochan': { text: 'Channel %0 does not exist.', error: true },
        'nopwchan': { text: 'Channel %0 requires a password. Use /join %0 <password>', error: true },
        'ipwchan': { text: 'Wrong password for channel %0.', error: true },
        'inchan': { text: 'Channel name contains invalid characters.', error: true },
        'nischan': { text: 'A channel with the name %0 already exists.', error: true },
        'ndchan': { text: 'You are not allowed to deleted channel %0.', error: true },
        'namchan': { text: 'You are not allowed to edit channel %0.', error: true },
        'nameinuse': { text: 'Someone else is already using the name %0.', error: true },
        'rankerr': { text: 'You cannot set the access level of a channel higher than that of your own.', error: true },
    };

    const formatTemplate = (template, args) => {
        if(typeof template !== 'string')
            template = '';

        if(Array.isArray(args))
            for(let i = 0; i < args.length; ++i) {
                const arg = args[i] === undefined || args[i] === null ? '' : args[i].toString();
                template = template.replace(new RegExp(`%${i}`, 'g'), arg);
            }

        return template;
    };

    return {
        handled: type => type in strings,
        show: async (type, args) => {
            if(!(type in strings))
                throw 'type is not a registered string';

            const info = strings[type];
            const message = formatTemplate(info.text, args);

            if(settings.get(info.error ? 'soundEnableError' : 'soundEnableServer')) {
                let soundName;
                if('sound' in info)
                    soundName = sound.pack.getEventSound(info.sound);
                if(soundName === undefined)
                    soundName = sound.pack.getEventSound(info.error ? 'error' : 'server');

                sound.library.play(soundName);
            }

            await msgbox.show({ body: [message] });
        },
    };
};
