
const createImgDiv = (imageData) => {

    for(i=0; i<=11; 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 noPadding portfolio-item');
        $(div).css('pointer-events', 'none');
        $('#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', imageData[i].thumb_url);
        $(div).append(img);

        /* $('.portfolio-item').on('mouseover mouseenter mouseleave mouseup mousedown', function() {
            return false
         }); */

        /* var anchor = document.createElement('a');
        anchor.href = search_link+imageData[i].id;
        anchor.target = "_blank";
        $(anchor).append(div); */
    }
} 

function search_api(){
    //imgName = $('input[name = search]').val();
    imgName = 'dog';
    $.ajax({
        type:'GET',
        url:search_link,
        data:{
            keyword: imgName,
            csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
        },
        success:function(response){
            $('select').prop('disabled',false);
            console.log(response);
            imageData = JSON.parse(response);
            showResult(imageData);
        },
        error:function(){
            alert('Error');
        }
    });
}

function showResult(imageData)
{
    console.log('showing recently added images');
    //$('#portfolioDiv').empty();
    createImgDiv(imageData);
    console.log(imageData.length);
}
