function loadTechData(n) {
    var r = zXmlHttp.createRequest(),
        t,
        i;
    return (
        r.open("get", `https://db.${__APP_DOMAIN__}/` + "Ajax/SoccerAjax?type=3&id=" + n, !1),
        r.send(null),
        (t = r.responseText),
        (i = ""),
        CheckEmpty(t) ||
        ((t = eval("(" + t + ")")), t.ErrCode == 0 && (i = t.Data)),
        TransLateLangue(i),
        i
    );
}

var currentRequest = null;

function loadTechDataPromise(n) {
    return new Promise((resolve, reject) => {
        if (currentRequest) {
            currentRequest.abort();
        }

        currentRequest = zXmlHttp.createRequest();

        currentRequest.open("GET", `https://db.${__APP_DOMAIN__}/Ajax/SoccerAjax?type=3&id=` + n, true);

        currentRequest.onreadystatechange = function() {
            if (currentRequest.readyState === 4) {
                if (currentRequest.status === 200) {
                    let t = currentRequest.responseText;
                    let i = "";

                    if (!CheckEmpty(t)) {
                        let response = JSON.parse(t);
                        if (response.ErrCode === 0) {
                            i = response.Data;
                        }
                    }
                    TransLateLangue(i);
                    resolve(i);
                } else {
                    reject(new Error('Failed to load data, status code: ' + currentRequest.status));
                }
            }
        };

        currentRequest.onerror = function() {
            reject(new Error('Network error occurred'));
        };

        currentRequest.send(null);
    });
}

function CheckEmpty(str) {
    if (typeof (str) == 'undefined' || str == 'undefined' || !str || !/[^\s]/.test(str)) {
        return true;
    } else {
        return false;
    }
}

function TransLateLangue(n) {
    n.HomeTeam.TechStat.forEach(function (n) {
        n.Title = TransLate(n.Title);
    });
    n.AwayTeam.TechStat.forEach(function (n) {
        n.Title = TransLate(n.Title);
    });
}


function TransLate(n) {
    return n === "Goal"
        ? _locModel.T.T_Pop_GoalRate
        : n === "Loss"
            ? _locModel.T.T_Pop_LossRate
            : n === "Corner Kicks"
                ? _locModel.T.T_Cbx_Corner
                : n === "Yellow Cards"
                    ? _locModel.T.T_Cbx_Yellow
                    : n === "Possession"
                        ? _locModel.T.T_Pop_Possession
                        : n;
}
