package com.ponzischeme89.memby.ui.alerts

/**
 * The wording and the counting behind My Alerts, kept pure so the badge a viewer sees in the
 * user picker and the summary line on the page itself are the same arithmetic tested once.
 *
 * The badge answers "is there anything waiting for me", which is why it counts *alerts* and
 * not unread ones: an alert that has been read but not dismissed is still sitting there, and
 * a badge that cleared itself the moment somebody glanced at the page would be a badge that
 * never agreed with the list underneath it.
 */

/** Above this the badge stops counting and says so, or the pill grows wider than its row. */
internal const val AlertBadgeMax = 9

internal fun alertBadgeLabel(count: Int): String? = when {
    count <= 0 -> null
    count > AlertBadgeMax -> "$AlertBadgeMax+"
    else -> count.toString()
}

/**
 * The line under the page heading. "New" is the unread half — worth naming, since it is the
 * only thing distinguishing two otherwise identical rows — but it is never claimed on its
 * own, because a page saying "2 new" above three alerts reads as having lost one.
 */
internal fun alertsSummary(total: Int, unread: Int): String = when {
    total <= 0 -> "Nothing waiting for you"
    unread <= 0 -> if (total == 1) "1 alert" else "$total alerts"
    else -> {
        val alerts = if (total == 1) "1 alert" else "$total alerts"
        "$alerts · $unread new"
    }
}
