var button_open_menager = document.getElementById("select_images_add");
var button_close_menager = document.getElementById("x");
var menager_file = document.getElementById("menager_file");
var buttons_select_fold = document.getElementsByClassName("fold_select");
var selects_file = document.getElementsByClassName("select_file");
var file_select = document.querySelectorAll('input[name="filedir"]');
var img_select = document.getElementsByClassName('img_post');

select_fold(0);
whoselect();

for (let i = 0; i < buttons_select_fold.length; i++){
    buttons_select_fold[i].addEventListener('click', function () { select_fold(i) });
}

for (let i = 0; i < file_select.length; i++){
    file_select[i].addEventListener('click', function () { whoselect() });
}

button_open_menager.addEventListener('click' ,function(){ menager_file.classList.toggle("active")});
button_close_menager.addEventListener('click' ,function(){ menager_file.classList.toggle("active")});

function select_fold(fold_number) {
    folds = document.getElementsByClassName("folder_in_view");
     for (i = 0; i < buttons_select_fold.length; i++){
        buttons_select_fold[i].classList.remove("active");
    }
    buttons_select_fold[fold_number].classList.add("active");
    for (i = 0; i < folds.length; i++){
        folds[i].classList.remove("active");
    }
    document.getElementById(buttons_select_fold[fold_number].innerText).classList.add("active");
}

function whoselect() {
    select_name = document.querySelector('input[name="filedir"]:checked');
    if (select_name != null) {
        for (i = 0; i < selects_file.length; i++) {
            selects_file[i].innerText = select_name.value ;
            img_select[0].src = "../../assets/img"+select_name.value ;
        }
    } else {
        for (i = 0; i < selects_file.length; i++) {
            selects_file[i].innerText = "nie wybrales pliku";
        }
    }

}