import { t } from '@/i18n/index.js'
// Whole days and hours read better than "1440 min"; anything else stays minutes.
export function intervalText(seconds) {
if (seconds % 86400 === 0) return t('chat.infoRecallDays', { n: seconds / 86400 })
if (seconds % 3600 === 0) return t('chat.infoRecallHours', { n: seconds / 3600 })
return t('chat.infoRecallMinutes', { n: Math.round(seconds / 60) })
}
// "in 25 min" — recomputed on every tick, so an open dialog never shows a
// number captured at load. A countdown is approximate, so it picks the largest
// unit that still says something: "in 30 d", not "in 43230 min".
export function recallInText(triggerAt, now = Date.now()) {
const at = new Date(triggerAt).getTime()
if (!Number.isFinite(at)) return '—'
const ms = at - now
if (ms <= 0) return t('chat.recallDueNow')
if (ms < 60000) return t('chat.recallUnderAMinute')
const minutes = Math.round(ms / 60000)
if (minutes < 60) {
return t('chat.recallIn', { interval: t('chat.infoRecallMinutes', { n: minutes }) })
}
const hours = Math.round(ms / 3600000)
if (hours < 24) {
return t('chat.recallIn', { interval: t('chat.infoRecallHours', { n: hours }) })
}
const days = Math.round(ms / 86400000)
return t('chat.recallIn', { interval: t('chat.infoRecallDays', { n: days }) })
}