import { useMemo } from 'react' ; import { VideoSource , VideoSrcProp } from '../HoverVideoPlayer.types' ; function param { VideoSrcProp } videoSrc param { number } playbackRangeStart param { number } playbackRangeEnd returns { VideoSource [ ] } export default function useFormatVideoSrc ( videoSrc , playbackRangeStart ? , playbackRangeEnd ? ) { return useMemo ( ( ) => { const formattedVideoSources = [ ] ; if ( videoSrc == null ) { console . error ( "Error: 'videoSrc' prop is required for HoverVideoPlayer component" ) ; } else { const rawVideoSources = Array . isArray ( videoSrc ) ? videoSrc : [ videoSrc ] ; for ( let i = 0 , numSources = rawVideoSources . length ; i < numSources ; i += 1 ) { const source = rawVideoSources [ i ] ; const hasPlaybackRangeStart = playbackRangeStart !== null ; const hasPlaybackRangeEnd = playbackRangeEnd !== null ; const playbackRangeMediaFragmentIdentifier = hasPlaybackRangeStart || hasPlaybackRangeEnd ? `#t=${ hasPlaybackRangeStart ? playbackRangeStart : '' }${ hasPlaybackRangeEnd ? `,${ playbackRangeEnd }` : '' }` : '' ; if ( typeof source === 'string' ) { formattedVideoSources . push ( { src : `${ source }${ playbackRangeMediaFragmentIdentifier }` , } ) ; } else if ( source && source . src ) { formattedVideoSources . push ( { src : `${ source . src }${ playbackRangeMediaFragmentIdentifier }` , type : source . type , } ) ; } else { console . error ( "Error: invalid value provided to HoverVideoPlayer prop 'videoSrc':" , source ) ; } } } return formattedVideoSources ; } , [ videoSrc , playbackRangeStart , playbackRangeEnd ] ) ; }