import  SetConfig from "./set_config_class.js";
import $ from "./jquery.module.js";
import * as audio from "./audio.js";
import {playAudioFile, setAudioFile} from "./audio.js";
const set_config = new SetConfig() ;

// Use the values assigned in the end_game_config.js file in the options object ;
set_config.configPromise.then(function(config){

    let loc =  config.options.completionURL ;
    $("#problem").html(config.options.text1) ;

    // Sets background image source and al attributes for scene in level up page ;
    $("#level_up_img").attr("src",config.options.bkImage).attr("alt",config.options.bkImageAlt) ;
    $("#play_button").on("click", function() {
        // Plays sound when level changes ;
        setAudioFile(config.options.level_up_sound) ;
        playAudioFile(config.options.level_up_sound);
        $('body').fadeOut(3000, new_page);

    });
    function new_page() {
        window.location.href = loc ;
    }

    if(config.options.credits === true)
    {
        $("#credits").removeClass('d-none').on("click", function() {
            $('body').fadeOut(3000, new_page);
        });
        let new_div = "<ul>" ;
        for (let i = 0; i < config.options.credit_lines.length ; i++) {
            new_div += "<li>" + config.options.credit_lines[i].credit + " : " + config.options.credit_lines[i].names + "</li>";
        }
        new_div += "</ul>" ;
        $("#contributors").append(new_div) ;

    }



});

export {
    set_config
}