var inputNumber = document.getElementsByClassName('input-group-field');

if (window.location.pathname.includes("/warenkorb.html")) {
    document.addEventListener("DOMContentLoaded", function () {
        $(window).on('load',function() {
                for(var y = 0;y<inputNumber.length;y++)
                {
                    showValue(inputNumber[y]);
                }




                var minusButton = document.getElementsByClassName("fa fa-minus");

                var plusButton = document.getElementsByClassName("fa fa-plus");


//Dieser Code Block gehört zur Warenkorb Datei
                for(var i = 0;i<plusButton.length;i++)
                {

                    var button = plusButton[i]

                    button.addEventListener('click', incrmenetValue)


                }

                for(var j = 0;j<minusButton.length;j++)
                {
                    var button1 = minusButton[j]

                    button1.addEventListener('click', decrmenetValue)


                }
            }


        );
    });
}

//<input class="input-group-field" type="number" name="quantity" value="1">
//var addItemButton = document.getElementsByClassName("input-group-field");

function showValue(event)
{

    var shopItem = event.parentElement.parentElement.parentElement

    var title = shopItem.getElementsByTagName('h3')[0].innerHTML
    var getValue = localStorage.getItem(title) || 0;
    shopItem.getElementsByClassName('input-group-field')[0].value = getValue;

}

function incrmenetValue(event)
{


    var buttony = event.target
    var shopItem = buttony.parentElement.parentElement.parentElement.parentElement.parentElement
    var title = shopItem.getElementsByTagName('h3')[0].innerHTML
    var getValue= localStorage.getItem(title) || 0;
    // var getValue = shopItem.getElementsByClassName('input-group-field')[0].value;
    if(getValue < 10){
        getValue++;
    }
    shopItem.getElementsByClassName('input-group-field')[0].value = getValue;
    localStorage.setItem(title, getValue)


}
function decrmenetValue(event)
{
    var buttony = event.target
    var shopItem = buttony.parentElement.parentElement.parentElement.parentElement.parentElement
    var title = shopItem.getElementsByTagName('h3')[0].innerHTML
    var getValue= localStorage.getItem(title) || 0;
    if(getValue > 0){
        getValue--;
    }
    shopItem.getElementsByClassName('input-group-field')[0].value = getValue;
    localStorage.setItem(title, getValue)


}
