import { AlignedLyric } from '../types';
import $getCharacterSpanRects from './getCharacterSpanRects';
import { getPlaintextLyrics } from './getPlaintextLyrics';
import splitLyrics from './splitLyrics';

export default function $getSecondsSpanRects(
  alignedLyrics: AlignedLyric[],
  startSeconds: number,
  endSeconds: number
) {
  const [lyricsBefore, lyricsInRange] = splitLyrics(
    alignedLyrics,
    startSeconds,
    endSeconds
  );

  const startChars = getPlaintextLyrics(lyricsBefore).length;
  const endChars = getPlaintextLyrics(lyricsInRange).length + startChars;
  return $getCharacterSpanRects(startChars, endChars);
}
