import $ from "./jquery.module.js";
import * as caves_and_trees from "./caves_and_trees_lib.js";
import SetConfig from "./set_config_class.js";
// import * as audio from "./audio.js";
import {getMathProblemGenerator} from "./math_operation_problems.js";
import {questionAnswered, getCorrectAnswer} from "./caves_and_trees_lib.js";

let setConfigHandler = new SetConfig();
let correctAnswer;

function setConfig(config) {
    setConfigHandler.setConfig(config);
}


$(document).ready(async function () {
    let config = await setConfigHandler.configPromise;
    let easyProblem = getMathProblemGenerator(config.mathProblems.easy);
    let hardProblem = getMathProblemGenerator(config.mathProblems.hard);

    function getProb(difficulty) {
        let problem = (difficulty === "easy") ? easyProblem : hardProblem;
        $("#answerText").val("").focus();
        $("#output").hide7gen();
        $("#problemArea").show7gen();
        let problemText = problem.getProblem();
        $("#problem").html(problemText);
        return problem.correctAnswer;
    }

    $("#answer").on("click", function () {
        let ans = Number($("#answerText").val());
        $("#problemArea").hide7gen();
        let correctAnswer = Number(getCorrectAnswer());
        questionAnswered(correctAnswer === ans)
    });

    // $("#getProblem").on("click", function () {
    //     $("#getProblem").hide7gen();
    //     correctAnswer = getProb("easy");
    // });
    //
    // $("#getHardProblem").on("click", function () {
    //     $("#getHardProblem").hide7gen();
    //     correctAnswer = getProb("hard");
    // });

    // function getCorrectAnswer() {
    //     return correctAnswer;
    // }


    caves_and_trees.setConfig({config, easyProblem, hardProblem, getProb});


});

export {setConfig};