/** Fixed resolution for HTML range seek inputs - avoids 1-second steps when max = duration. */
export const MEDIA_SEEK_SLIDER_STEPS = 10_000;

export function mediaSeekSliderValue(currentTimeSeconds: number, durationSeconds: number): number {
  if (!Number.isFinite(durationSeconds) || durationSeconds <= 0)
    return 0;

  const clampedTime = Math.max(0, Math.min(durationSeconds, currentTimeSeconds));

  return (clampedTime / durationSeconds) * MEDIA_SEEK_SLIDER_STEPS;
}

export function mediaSeekTimeFromSliderValue(sliderValue: number, durationSeconds: number): number {
  if (!Number.isFinite(durationSeconds) || durationSeconds <= 0)
    return 0;

  const clampedValue = Math.max(0, Math.min(MEDIA_SEEK_SLIDER_STEPS, sliderValue));

  return (clampedValue / MEDIA_SEEK_SLIDER_STEPS) * durationSeconds;
}
