"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createProgress = exports.setProgressState = exports.setStatusState = exports.lerp = void 0;
exports.capitalizeFirstLetter = capitalizeFirstLetter;
exports.formatUptime = formatUptime;
exports.delay = delay;
var morphux_1 = require("morphux");
/**
 * A linear interpolation helper function.
 * @param a The start value.
 * @param b The end value.
 * @param t The interpolation factor (0 to 1).
 * @returns The interpolated value.
 */
var lerp = function (a, b, t) {
    return a + (b - a) * t;
};
exports.lerp = lerp;
var setStatusState = function (statusElement, state) {
    statusElement.classList.remove('ntsh_status-green', 'ntsh_status-yellow', 'ntsh_status-red', 'ntsh_status-gray');
    statusElement.classList.add("ntsh_status-".concat(state));
};
exports.setStatusState = setStatusState;
var setProgressState = function (progressElement, value, min, max, unit) {
    var percentage = (value - min) / (max - min);
    var progressValue = progressElement.querySelector('.ntsh_progress-value');
    progressValue.style.width = "".concat(percentage * 100, "%");
    var label = progressElement.querySelector('.ntsh_progress-label');
    label.innerText = "".concat(value).concat(unit);
};
exports.setProgressState = setProgressState;
var createProgress = function (value, min, max, unit) {
    var progress = (0, morphux_1.ce)('div', 'ntsh_progress');
    progress.appendChild((0, morphux_1.ce)('div', 'ntsh_progress-value'));
    progress.appendChild((0, morphux_1.ce)('div', 'ntsh_progress-label'));
    (0, exports.setProgressState)(progress, value, min, max, unit);
    return progress;
};
exports.createProgress = createProgress;
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
function formatUptime(seconds) {
    if (seconds < 0)
        return '';
    var days = Math.floor(seconds / 86400);
    seconds %= 86400;
    var hours = Math.floor(seconds / 3600);
    seconds %= 3600;
    var minutes = Math.floor(seconds / 60);
    seconds = Math.floor(seconds % 60);
    var parts = [];
    if (days > 0)
        parts.push("".concat(days, "d"));
    parts.push("".concat(hours.toString().padStart(2, '0'), ":").concat(minutes
        .toString()
        .padStart(2, '0'), ":").concat(seconds.toString().padStart(2, '0')));
    return parts.join(' ');
}
function delay(duration) {
    return new Promise(function (resolve) { return setTimeout(resolve, duration); });
}
//# sourceMappingURL=utils.js.map