"use strict";
function isNullOrWhiteSpace(str) {
    return str === null || str.match(/^ *$/) !== null;
}
function invertColors(ids, hex) {
    if (hex === "")
        return;
    let color = invertColor(hex);
    ids.forEach(function (x) {
        var els = document.getElementsByClassName(x);
        for (let el of els) {
            var elByID = document.getElementById(el.id);
            if (elByID === null)
                return;
            elByID.style.color = color;
        }
    });
}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
function invertColor(hex) {
    if (hex.indexOf('#') === 0) {
        hex = hex.slice(1);
    }
    // convert 3-digit hex to 6-digits.
    if (hex.length === 3) {
        hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
    }
    if (hex.length !== 6) {
        throw new Error('Invalid HEX color.');
    }
    // invert color components
    var r = (255 - parseInt(hex.slice(0, 2), 16)).toString(16), g = (255 - parseInt(hex.slice(2, 4), 16)).toString(16), b = (255 - parseInt(hex.slice(4, 6), 16)).toString(16);
    // pad each with zeros and return
    return '#' + padZero(r, null) + padZero(g, null) + padZero(b, null);
}
function padZero(str, len) {
    len = len || 2;
    var zeros = new Array(len).join('0');
    return (zeros + str).slice(-len);
}
function unfade(element, interval) {
    var op = 0.1;
    interval = interval || 75;
    element.style.display = 'block';
    var timer = setInterval(function () {
        if (op >= 1) {
            clearInterval(timer);
        }
        element.style.opacity = op;
        element.style.filter = 'alpha(opacity)' + op * 100 + ")";
        op += op * 0.1;
    }, interval);
}
function fade(element, interval) {
    var op = 1;
    var timer = setInterval(function () {
        if (op <= 0.1) {
            clearInterval(timer);
            element.style.display = 'none';
        }
        element.style.opacity = op;
        element.style.filter = 'alpha(opacity=' + op * 100 + ")";
        op -= op * 0.1;
    }, interval);
}
function setBackground(base64String) {
    if (isNullOrWhiteSpace(base64String))
        return;
    $(document.body).css("background-image", "url('" + base64String + "')");
}
function hexToRgb(hex) {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result ? {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16)
    } : null;
}

function componentToHex(c) {
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b) {
    return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function postToURL(uri, o, dataType) {
    $.ajax({
        url: uri,
        type: 'POST',
        contentType: false,
        data: JSON.stringify(o),
        dataType: dataType || 'html',
        success: function (result) {
            $("#renderedBodyContainer").html(result);
        }
    });
}
function goToURL(url, queryParameters) {
    var Parameters = buildSearchParams(queryParameters);
    window.location.href = Parameters ? url + "?" +  Parameters.toString() : url;
}
function goToAction(action, queryParameters) {
    var Parameters = buildSearchParams(queryParameters);
    var url = location.protocol + '//' + location.host + '/' + getCurrentControllerName() + '/' + action + "?" + Parameters.toString();
    window.location.href = url;
}
function goToControler(controller, action, queryParameters) {
    var Parameters = buildSearchParams(queryParameters);
    var parameterLessUrl = location.protocol + '//' + location.host + '/' + controller + '/' + action;
    var url = Parameters ? parameterLessUrl + "?" + Parameters.toString() : parameterLessUrl;
    window.location.href = url;
}
function buildSearchParams(queryParameters) {
    if (!queryParameters)
        return null;
    var Parameters = new URLSearchParams();
    Object.keys(queryParameters).forEach(e => Parameters.append(e, queryParameters[e]));
    return Parameters;
}
function getCurrentControllerName() {
    var url = window.location.pathname.split("/");
    return url[1];
}
function updateQueryParameter(parameterName, parameterValue) {
    var currentUrl = window.location.href.split(parameterName).join("");
    if (currentUrl.includes('?') && currentUrl.indexOf('?') < (currentUrl.length -1)) {
        window.location.href = currentUrl + '&' + parameterName + '=' + parameterValue;
    }
    else {
        window.location.href = currentUrl + '?' + parameterToAdd;
    }
}
//# sourceMappingURL=GeneralHelpers.js.map