export const getLabelText = function (k) {
    let translatedValue = Translation[k];

    var res = translatedValue ? translatedValue : k;

    if (res.includes("&")) {
        var doc = new DOMParser().parseFromString(res, "text/html");
        res = doc.documentElement.textContent;
        doc = null;
    }

    return res;
}

export const getAmount = function (cs, n) {
    return cs + ' ' + RoundTo2(n);
}

export const getShortDate = function (d) {
    //console.log(d, datePattern);
    //let formattedDate = moment(d, datePattern);
    return new Intl.DateTimeFormat(locale).format(Date.parse(d));
}

export const sleep = function (seconds) {
    if (!seconds)
        seconds = 1;
    let e = new Date().getTime() + (seconds * 1000);
    while (new Date().getTime() <= e);
}

export const getStatusString = function (s) {

    return this.getLabelText(accountStatusList.items.find(i => i.value == s).text);

    //let st = parseInt(s);

    //if (st == 1)
    //    return this.getLabelText('GN0000222');
    //else if (st == 2)
    //    return this.getLabelText('GN0000302');
    //else if (st == 3)
    //    return this.getLabelText('GN00001545');
    //else if (st == 4)
    //    return this.getLabelText('GN0000348');
    //else if (st == 5)
    //    return this.getLabelText('GN00001546');
    //else if (st == 6)
    //    return this.getLabelText('GN0000861');
    //else if (st == 7)
    //    return this.getLabelText('SPT002056');
    //else if (st == 8)
    //    return this.getLabelText('SPT002057');
    //else if (st == 9)
    //    return this.getLabelText('SPT002058');
    //else if (st == 10)
    //    return this.getLabelText('SPT002059');
}

export const getSubscriptionURL = function (pTId, aId, IsAddOn) {
    let PackageTypeId = parseInt(pTId);
    let AccountId = parseInt(aId);

    if (PackageTypeId == 1)
        return "/RCC/Clients/SH.aspx?Id=" + AccountId + (IsAddOn ? "&TI=2" : "");
    else if (PackageTypeId == 2)
        return "/RCC/Clients/NH.aspx?Id=" + AccountId + (IsAddOn ? "&TI=2" : "");
    else if (PackageTypeId == 3)
        return "/RCC/Clients/AD.aspx?SubId=" + AccountId + (IsAddOn ? "&TIndex=2" : "");
    else if (PackageTypeId == 5)
        return "/RCC/Clients/DH.aspx?Id=" + AccountId;
    else if (PackageTypeId == 8)
        return "/RCC/Clients/SSL.aspx?Id=" + AccountId;
    else if (PackageTypeId == 10)
        return "/RCC/Clients/Domain.aspx?Id=" + AccountId + (IsAddOn ? "&TI=2" : "");
    else if (PackageTypeId == 14)
        return "/RCC/Clients/CRM.aspx?SubId=" + AccountId + (IsAddOn ? "&TI=2" : "");
    else if (PackageTypeId == 16)
        return "/RCC/Clients/ExH.aspx?SubId=" + AccountId + (IsAddOn ? "&TI=2" : "");
    else if (PackageTypeId == 17)
        return "/RCC/Clients/SP.aspx?SubId=" + AccountId + (IsAddOn ? "&TI=2" : "");
    else if (PackageTypeId == 18)
        return "/RCC/Clients/OCS.aspx?SubId=" + AccountId + (IsAddOn ? "&TI=2" : "");
    else if (PackageTypeId == 19)
        return "/RCC/Clients/VPS.aspx?SubId=" + AccountId + (IsAddOn ? "&TI=3" : "");
    else if (PackageTypeId == 21)
        return "/RCC/O365/O365Sub.aspx?SubId=" + AccountId + (IsAddOn ? "&Tab=2" : "");
    else if (PackageTypeId == 22)
        return "/RCC/RDS/Manage.aspx?subId=" + AccountId + (IsAddOn ? "&TIndex=1" : "");
    else if (PackageTypeId == 23)
        return "/RCC/Clients/WFH.aspx?SubId=" + AccountId + (IsAddOn ? "&TIndex=2" : "");
    else if (PackageTypeId == 24)
        return "/RCC/Voice/Manage.aspx?SubId=" + AccountId + (IsAddOn ? "&TIndex=2" : "");

}

export const getFileContentsFromInput = function (file) {
    if (!file) {
        alert(this.getLabelText("FAM0038"));
        return;
    }

    return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.onload = () => resolve(reader.result.split(",")[1]);
        reader.onerror = (error) => reject(error);
        reader.readAsDataURL(file);
    });
}
