import { getm, mapDatasToFacet } from 'skandha';
import { VideoController } from 'src/moves/MoveState/facets/VideoController';
import { MoveT } from 'src/moves/types';
import { getVideoFromMove } from 'src/moves/utils';
import { Inputs } from 'src/video/CutVideoState/facets/Inputs';

export const initVideoStateFromCurrentMove = mapDatasToFacet(
  [VideoController, 'video'],
  [
    //
    getm([Inputs, 'move']),
    getm([Inputs, 'altLink']),
  ],
  (move: MoveT, altLink: string | undefined) => {
    return altLink
      ? {
          link: altLink,
          startTimeMs: undefined,
          endTimeMs: undefined,
        }
      : move && move.link
      ? getVideoFromMove(move)
      : null;
  }
);
