import { StudioProjectState } from './types';

// Prevent state changes that could break assumptions that the previewing system relies on.
// e.g. that the same clip will be selected, that the content of a track will not change, etc.
export function isValidStateChangeInPreview(
  prev: StudioProjectState,
  next: StudioProjectState
) {
  if (prev.selection.anchorBeats !== next.selection.anchorBeats) {
    return false;
  }

  if (prev.selection.focusBeats !== next.selection.focusBeats) {
    return false;
  }

  if (prev.selection.focusedTrackId !== next.selection.focusedTrackId) {
    return false;
  }

  const prevFocusedTrack = prev.tracks.find(
    (track) => track.id === prev.selection.focusedTrackId
  );
  const nextFocusedTrack = next.tracks.find(
    (track) => track.id === next.selection.focusedTrackId
  );

  if (prevFocusedTrack?.clips !== nextFocusedTrack?.clips) {
    return false;
  }
  return true;
}
