"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatMemory = exports.formatTimePercentage = exports.formatMS = exports.formatResourceName = void 0;
var color_1 = require("../utils/color");
function f(n) {
    return n.toFixed(2);
}
function formatResourceName(cell) {
    if (typeof cell === 'string') {
        var _a = __read(color_1.rgbForKey(cell), 3), r = _a[0], g = _a[1], b = _a[2];
        return "<span class=resource-name style=\"background:rgb(" + r + ", " + g + ", " + b + ")\">" + cell + "</span>";
    }
    return cell;
}
exports.formatResourceName = formatResourceName;
function formatMS(cell) {
    if (typeof cell === 'number') {
        if (cell <= 0.005) {
            return '—';
        }
        return cell.toFixed(2) + ' ms';
    }
    return cell;
}
exports.formatMS = formatMS;
function formatTimePercentage(cell) {
    if (typeof cell === 'number') {
        if (cell < 0.005) {
            return '—';
        }
        var intensityColor = "rgba(244, 5, 82, " + cell + ")";
        return "<span style=\"padding: 0 2px;border: solid 2px " + intensityColor + "\">" + (cell * 100).toFixed(2) + "%</span>";
    }
    return cell;
}
exports.formatTimePercentage = formatTimePercentage;
function formatMemory(postfix, mem) {
    if (typeof mem === 'number') {
        if (mem <= 0) {
            return '?';
        }
        switch (true) {
            case mem >= (Math.pow(1024, 3)): {
                return f(mem / (Math.pow(1024, 3))) + ' GiB' + postfix;
            }
            case mem >= (Math.pow(1024, 2)): {
                return f(mem / (Math.pow(1024, 2))) + ' MiB' + postfix;
            }
            case mem >= 1024: {
                return f(mem / 1024) + ' KiB' + postfix;
            }
            default: {
                return f(mem) + ' B' + postfix;
            }
        }
    }
    return mem;
}
exports.formatMemory = formatMemory;
//# sourceMappingURL=formatters.js.map