// tabsAction.discard(id);
function unhideSelectedTab(id) {
    tabsAction.show(id).then(successMsg, errMsg);
}

function hideSelectedTab(id)   {
    tabsAction.hide(id).then(successMsg, errMsg);
}

function successMsg(ev) { console.log("Tab is hidden..." + ev); }

function errMsg(ev) {
    var msg = "" + ev;
    if (msg.includes("extensions.webextensions.tabhide.enabled")) {
        var errText = document.createTextNode(msg);
        listZone.style.display   = "none";
        errHandler.style.display = "block";
        errHandler.appendChild(errText);
        setTimeout(function () {
            listZone.style.display   = "block";
            errHandler.style.display = "none";
            clearNodes(errHandler);
        }, 4000);
    }
}

function doAllTabs(doType) {
    // 0 == hide and 1 == unhide
    tabsAction.query({currentWindow: true}).then((tabs) => {
        var tabCollectionIDs = [];

        for (var i = 0; i < tabs.length; i++) {
            tabCollectionIDs.push(tabs[i].id);
        }

        if (doType == 0) {
            hideSelectedTab(tabCollectionIDs);
        } else {
            unhideSelectedTab(tabCollectionIDs);
        }
    }, doType);

    var imgs = document.querySelectorAll(".hiderImg");
    if (doType == 0) {
        for (var i = 0; i < imgs.length; i++) {
            imgs[i].parentElement.setAttribute("class", "block hiddenBGColor");
            imgs[i].src = "../icons/eyeClosed.png";
        }

        oldElm.querySelectorAll(".hiderImg")[0].src = "../icons/eyeOpen.png";
        oldElm.setAttribute("class", "block block-focused");
    } else {
        for (var i = 0; i < imgs.length; i++) {
            imgs[i].parentElement.setAttribute("class", "block");
            imgs[i].src = "../icons/eyeOpen.png";
        }

        oldElm.setAttribute("class", "block block-focused");
    }
}
