// 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 showHideTabsAction(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);

    if (doType == 0) {
        let tabs = document.querySelectorAll(".block");
        for (var i = 0; i < tabs.length; i++) {
            tabs[i].setAttribute("class", "block hiddenBGColor");
        }
        oldElm.setAttribute("class", "block block-focused");
    } else {
        let tabs = document.querySelectorAll(".hiddenBGColor");
        for (var i = 0; i < tabs.length; i++) {
            tabs[i].setAttribute("class", "block");
        }
        oldElm.setAttribute("class", "block block-focused");
    }

    if (hoverTarget) {
        if (hoverTarget.className == "block hiddenBGColor")
            document.getElementById("tabControls").querySelector("#hideTgglBttn").src = "../icons/eyeClosed.png";
        else
            document.getElementById("tabControls").querySelector("#hideTgglBttn").src = "../icons/eyeOpen.png";
    }
}
