package solutions.tretter.mindmachine.session

import java.util.Locale

fun formatDuration(totalSec: Int): String {
    val sec = totalSec.coerceAtLeast(0)
    val totalMinutes = sec / 60f

    return if (totalMinutes <= 60f) {
        "${totalMinutes.toInt()} min"
    } else {
        val hours = totalMinutes / 60f
        "${formatMaxTwoDecimals(hours)} h"
    }
}

private fun formatMaxTwoDecimals(value: Float): String =
    String.format(Locale.US, "%.2f", value).trimEnd('0').trimEnd('.')
