document.addEventListener("DOMContentLoaded", function() {
    var c = document.getElementById("configure-folder");
    var d = document.getElementById("register-link");
    c.addEventListener("click", function(a) {
        a.preventDefault();
        chrome.tabs.create({
            url: 'chrome://settings/downloads'
        })
    });
    d.addEventListener("click", function(a) {
        a.preventDefault();
        window.open("https:demo.vcrxol.com", "_blank")
    });
    var b = document.getElementById("boton1");
    var e = document.getElementById("texto");
    b.addEventListener("click", function() {
        b.disabled = !0;
        chrome.tabs.query({
            active: true,
            currentWindow: true
        }, function(a) {
            chrome.tabs.sendMessage(a[0].id, {
                action: "descargarRecibidos"
            }, function(f) {
                f ? (e.textContent = f.message,
                b.textContent = "En proceso...") : (e.textContent = "Lo sentimos, ocurri\u00f3 un error. Asegurese de estar en la p\u00e1gina correcta y recargue nuevamente",
                b.textContent = "Iniciar Descarga",
                b.disabled = !1)
            })
        })
    });
    document.getElementById("eliminarHistorial").addEventListener("click", function() {
        chrome.tabs.query({
            active: true,
            currentWindow: true
        }, function(a) {
            chrome.tabs.sendMessage(a[0].id, {
                action: "eliminarRecibidos"
            }, function() {})
        })
    })
});
setInterval(function() {
    chrome.runtime.sendMessage({
        action: "obtenerRegistros"
    }, function(c) {
        var d = c.m || [];
        var b = c.o || [];
        var e = c.s || [];
        var a = document.getElementById("registros-container");
        var f = document.getElementById("texto");
        var k = document.getElementById("texto_correctos");
        var l = document.getElementById("texto_error");
        a.innerHTML = "";
        d.forEach(function(g) {
            var h = document.createElement("tr");
            f.textContent = " " + d.length + " registros analizados";
            k.textContent = " " + b.length + " comprobantes descargados";
            l.textContent = " " + e.length + " errores o no descargados";
            h.textContent = "N\u00b0 " + g.nro + " | Comprobante: " + g.serie + " | " + g.msg + " |  Descarga : " + g.descargada;
            a.appendChild(h)
        })
    })
}, 500);
