export function formatDuration(seconds) {
  const mins = Math.floor(seconds / 60);
  const secs = Math.floor(seconds % 60);
  return `${mins}:${secs.toString().padStart(2, '0')}`;
}

export function scaleTimelineSegments(tracks, newDuration, minimumDuration = 30) {
  let contentEnd = 0;
  for (const track of tracks) {
    for (const segment of track.segments) {
      contentEnd = Math.max(contentEnd, segment.end);
    }
  }
  if (contentEnd === 0) return { changed: false, contentEnd, scale: 1 };

  const targetDuration = Math.max(minimumDuration, newDuration);
  const scale = targetDuration / contentEnd;
  for (const track of tracks) {
    for (const segment of track.segments) {
      segment.start *= scale;
      segment.end *= scale;
    }
  }
  return { changed: true, contentEnd, targetDuration, scale };
}
