/* eslint-disable spellcheck/spell-checker */
export const clampPercent = (value: number): number => Math.max(0, Math.min(100, Math.round(value)));

export const formatTime = (seconds: number): string => {
  if (!Number.isFinite(seconds) || seconds < 0) return '0:00';
  const totalSeconds = Math.floor(seconds);
  const hrs = Math.floor(totalSeconds / 3600);
  const mins = Math.floor((totalSeconds % 3600) / 60);
  const secs = (totalSeconds % 60).toString().padStart(2, '0');

  if (hrs > 0) {
    return `${hrs}:${mins.toString().padStart(2, '0')}:${secs}`;
  }
  return `${mins}:${secs}`;
};
