let get_current_json = NaN
$(document).ready(async function() {
    get_name_logo = await eel.get_name_logo()()
    get_current_json = await eel.get_current_json()() 

    var name_soft = get_name_logo[0];

    if (get_current_json.Folder_Name_To_Title === "Yes"){
        current_folder = await eel.get_current_folder()()
        $('title').text(`${current_folder}`);
        $('.name_program').text(`${name_soft} [ ${current_folder} ]`);
    } else {
        $('title').text(name_soft);
        $('.name_program').text(name_soft);
    }
    $('.logo_program').append(get_name_logo[1]);

    // if (get_current_json.Disable_Snow === "No"){
    //     /* ------ СНЕГ ------ */
    //     $('head').append('<link rel="stylesheet" type="text/css" href="css/snow/snow.min.css">');
    //     $.getScript("css/snow/snow.min.js", function() { new Snow(); });
    //     /* ------ СНЕГ ------ */
    // }
});


$('#settings_copies').on('click', async function () {
    get_current_json = await eel.get_current_json()()
    $("#Open_Via_Website option[value='" + get_current_json.Open_Via_Website + "']").prop("selected", true);
    // $("#Disable_Snow option[value='" + get_current_json.Disable_Snow + "']").prop("selected", true);
    $("#Folder_Name_To_Title option[value='" + get_current_json.Folder_Name_To_Title + "']").prop("selected", true);
})

$('#settings_copies_save').on('click', async function () {
    get_current_json = await eel.get_current_json()() 
    var now_current_json = {};
    now_current_json["Open_Via_Website"] = $("#Open_Via_Website").val();
    // now_current_json["Disable_Snow"] = $("#Disable_Snow").val();
    now_current_json["Size_Window"] = get_current_json.Size_Window
    now_current_json["Size_Console"] = get_current_json.Size_Console
    now_current_json["Size_Console_Edit"] = get_current_json.Size_Console_Edit
    now_current_json["Folder_Name_To_Title"] = $("#Folder_Name_To_Title").val();
    now_current_json["Current_Port"] = get_current_json.Current_Port

    var jsonData = JSON.stringify(now_current_json, null, 4);
    await eel.set_current_json(jsonData)()
    success('Настройки сохранены!',"Внимание! Изменения в настройках вступят в силу после перезапуска программы.");
})


eel.expose(current_page);
function current_page() {
    current_page = document.location.pathname;
    console.log(current_page);
    return current_page.slice(1,)
}


eel.expose(redirect_page);
function redirect_page(page) {
    document.location.href = page;
};


eel.expose(err_activate);
function err_activate() {
    /* alert('Ключ ненправильный или истек срок действия'); */
    error('Ключ не работает или истек срок действия!');
    /* setTimeout(window.close, 1900); */
    return true
}

function error(text) {
    Swal.fire({
        position: 'center',
        icon: 'error',
        title: 'Ошибка',
        text: text,
        showConfirmButton: false,
        timer: 1900
    })
}

function success(massege, info){  
    Swal.fire({
        icon: 'success',
        text: info,
        title: massege,
        showConfirmButton: false,
        timer: 6000,
    });
  }