import type { Cost } from '~/types/game' type Translate = (key: string, values?: Record) => string /** A route's interval in real time: "2 h 30 min", "45 min", "1 d 2 h". */ export function formatInterval(seconds: number, t: Translate) { const m = Math.round(Math.max(0, seconds) / 60) const days = Math.floor(m / 1440) const hours = Math.floor((m % 1440) / 60) const minutes = m % 60 if (days) return hours ? t('market.interval.dh', { d: days, h: hours }) : t('market.interval.d', { d: days }) if (hours && minutes) return t('market.interval.hm', { h: hours, m: minutes }) if (hours) return t('market.interval.h', { h: hours }) return t('market.interval.m', { m: minutes }) } /** The resources of a cargo with an amount above zero, in wood, clay, iron order. */ export const cargoRows = (cargo: Cost | null | undefined) => (['wood', 'clay', 'iron'] as const).filter((r) => (cargo?.[r] ?? 0) > 0).map((r) => [r, cargo![r]] as const)