// Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.

// Write your JavaScript code.

$(function(){

    const qrCode = new QRCode(document.getElementById("qrcode"), "https://plugarii.com");
    const input = document.getElementById("qrcode-input");

    const remakeQRCode = (text)=>{
        qrCode.clear();
        qrCode.makeCode(text);
    }

    var text = input.value;

    const processChanges = debounceLeading(() => {
        text = input.value;
        remakeQRCode(text)
    });
    input.addEventListener("keydown",processChanges); 
});

function debounceLeading(func, timeout = 300){
    let timer;
    return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => {
        func.apply(this, args);
        }, timeout);
    };
}
    