import getBufferListLength from '../audio/audioFunctions/getBufferListLength';
import { UndoStep } from '../types';

export const logUndoStep = (historyIndex: number, history: UndoStep[]) => {
  console.log(
    history
      .map(({ state, selectionBefore, selectionAfter }, index) => {
        const sampleRate = state.sampleRate;
        const trackSummary = state.tracks.map(
          ({ audioBuffers, title }) => `${title} (${(getBufferListLength(audioBuffers) / sampleRate).toFixed(2)})`
        ).join(', ')

        const selectionSummary = `${selectionBefore[0][0].toFixed(2)}-${selectionBefore[0][1].toFixed(2)} -> ${selectionAfter[0][0].toFixed(2)}-${selectionAfter[0][1].toFixed(2)}`;

        return `${index === historyIndex ? '> ' : '  '}${index}: {${trackSummary}} [${selectionSummary}]`
      })
      .join('\n')
  );
}

export const logUndo = () => console.log('/\\ #### Undo');
export const logRedo = () => console.log('\\/ #### Redo');
