import {
  getLastClipBeforeSelection,
  getSelectedClips,
  getSelectionStartBeats,
} from '../selectors';
import { StudioProjectState } from '../types';

export default function getExtendFromBeats(state: StudioProjectState) {
  const selectedClips = getSelectedClips(state);
  const lastClipBeforeSelection = getLastClipBeforeSelection(state);
  if (selectedClips.length > 0 || !lastClipBeforeSelection) {
    return getSelectionStartBeats(state);
  } else {
    return lastClipBeforeSelection.endBeats;
  }
}
