

search_link = "http://3.6.247.166:8000/search/";
$(document).ready(function(){
    //search_api();     //Function for showing recently added images from API
    showResult();       //Function for showing recently added images from Array
});

function searchImages_api(){
    const searchedText = document.getElementById('search_input_id').value;
    console.log('searchedText', searchedText);
    if(searchedText != '' )
        createImgDiv_searchImages();
}

function createImgDiv_searchImages(){
    const imageData = ['bg_1.png', 'Replay_1.png','board_1.png', 'Sound_1.png', 'credits_1.png', 'coverPage_1.png', 'option_Sound_1.png', 'game skin.png', 'Home_1.png', 'Next_1.png', 'imageBox_1.png', 'logo.png', 'Play_1.png', 'bg_1.png', 'Replay_1.png','board_1.png', 'Sound_1.png', 'credits_1.png', 'coverPage_1.png', 'option_Sound_1.png', 'game skin.png', 'Home_1.png', 'Next_1.png', 'imageBox_1.png', 'logo.png', 'Play_1.png',];

    $('#search_images_div').empty();
    $('#counts').css('display','none');
    $('#portfolio').css('display','none');
    $('#search_images').css('display','block');
    $('#search_images_div').addClass('portfolio-container')
    for(i=0; i<=imageData.length - 1; i++){
        var div = document.createElement('div');
        $(div).prop('id', 'search_imgDiv'+(i+1));
        // $(div).css('position', 'unset');
        $(div).prop('class', 'col-lg-3 col-md-4 imgDivCss portfolio-item');
        $('.imgDivCss').click(function(){
            window.open('./portfolio-details.html')
        })

        var img = document.createElement('img');
        $(img).prop('id', 'search_img'+(i+1));
        $(img).prop('class', 'img-fluid noPadding imgCss');
        $(img).prop('alt', '');
        $(img).prop('src', 'assets/img/portfolio/' + imageData[i]);
        $(div).append(img);

        $('#search_images_div').append(div);
    }
}

function showResult()
{
    console.log('Showing recently added images');
    createImgDiv();
}

const createImgDiv = () => {
    const imageData = ['bg.png','blue_pach.png', 'board.png', 'credits.png', 'Home.png', 'logo.png', 'Next.png', 'option_Sound.png', 'Pictionary_L1_HI_KN.png', 'Play.png', 'Replay.png', 'Sound.png'];

    for(i=0; i<=imageData.length - 1; i++){
        var div = document.createElement('div');
        $(div).prop('id', 'imgDiv'+(i+1));
        $(div).css('position', 'unset');
        $(div).prop('class', 'col-lg-3 col-md-4 imgDivCss portfolio-item');
        // $('div').click(showPortfolioDetails());
        $('.imgDivCss').click(function(){
            window.open('./portfolio-details.html')
        })
        
        $('#portfolioDiv').append(div);

        var img = document.createElement('img');
        $(img).prop('id', 'img'+(i+1));
        $(img).prop('class', 'img-fluid noPadding imgCss');
        $(img).prop('alt', '');
        $(img).prop('src', 'assets/img/portfolio/' + imageData[i]);
        $(div).append(img);
    }
} 

/* Show desclaimer box to download the image */
function show_disclaimer(){ 
    document.getElementById('modalTextDiv').style.display = 'block';
    document.getElementById('modalTextDiv').style.zIndex = '1';
    document.getElementById('portfolio-container').style.opacity = '0.3';
    document.getElementById('exampleCheck1').checked = false;
}

/* Clicked on desclaimer box - cancel button */
function cancel_download(){
    document.getElementById('modalTextDiv').style.display = 'none';
    document.getElementById('portfolio-container').style.opacity = '1';
    document.getElementById('exampleCheck1').checked = true;
    document.getElementById('download-btn').style.display = 'none';
    document.getElementById('cancel_btn').style.marginLeft = '0vw';
}


/* Download Image page - When checked the checkbox of disclaimer div */
// document.getElementById('exampleCheck1').addEventListener('change', () => {
function check_download_disclaimer_box(){
    let checkbox = document.getElementById('exampleCheck1');
    let download_btn = document.getElementById('download-btn');
    if(checkbox.checked){
        download_btn.style.display = 'block';
        document.getElementById('cancel_btn').style.marginLeft = '1vw';
        document.getElementById('cancel_btn').addClass = 'offset-1';
    }    
    else{
        download_btn.style.display = 'none';
        document.getElementById('cancel_btn').style.marginLeft = '0vw';
    }
}

/* Upload image page -  */
function yes_upload_Image(){
    document.getElementById('uploadModalTextDiv').style.display = 'none';
    document.getElementById('no_btn').style.marginLeft = '1vw';
    document.getElementById('form_id').style.pointerEvents = 'auto';
    document.getElementById('form_id').style.opacity = '1';
}