// Compact German duration formatting shared by the Quick-Start-Wizard's
// Ergebnis step (vsm-quick-start-wizard.tsx) and the Timeline-Leiter v2
// (vsm-timeline-ladder.tsx) — both display engine seconds (Takt, DLZ,
// per-category ladder times) that can range from single-digit seconds (a
// short cycle time) to multi-day totals (accumulated inventory coverage),
// which lib/stopwatch/evaluation.ts's `formatSeconds` (built for
// cycle-time-scale tooltips/axes, always "X,XX s") is not designed to read
// well at ("432000,00 s" for 5 days of coverage). Numeric-only — callers
// handle `null` ("nicht berechenbar") themselves, contextually (the reason
// differs per metric and the MetricExplain `exclusions` already say why).

/** Formats whole seconds as the largest-appropriate single unit pair
 * (Tage+Std / Std+Min / Min+s / s) — never fabricates sub-second precision,
 * never shows more than two units at once (progressive disclosure, not a
 * full "1d 2h 3m 4s" breakdown). */
export function formatDurationDe(totalSec: number): string {
  const sign = totalSec < 0 ? '-' : ''
  const sec = Math.abs(Math.round(totalSec))
  const days = Math.floor(sec / 86400)
  const hours = Math.floor((sec % 86400) / 3600)
  const minutes = Math.floor((sec % 3600) / 60)
  const seconds = sec % 60

  if (days > 0) return `${sign}${days} Tag${days === 1 ? '' : 'e'} ${hours} Std.`
  if (hours > 0) return `${sign}${hours} Std. ${minutes} Min.`
  if (minutes > 0) return `${sign}${minutes} Min. ${seconds} s`
  return `${sign}${seconds} s`
}
