import { useRef } from 'react'; import fp from '../../utils/fp.js'; import { useVideoPlay } from '../useVideoPlay/useVideoPlay'; const useVideoMove = (options = {}) => { const { enableLogging = false, logPrefix = '[useVideoMove]' } = options; const { playVideo, restartVideo } = useVideoPlay(options); const log = (message) => enableLogging && console.log(`${logPrefix} ${message}`); const timerRef = useRef(null); const playByTransition = (queue = []) => { log(`playByTransition 시작: queue = ${JSON.stringify(queue)}`); const q = fp.defaultTo([])(queue); if (q.length === 0) { log('빈 큐: Promise.resolve 반환'); return Promise.resolve(); } if (q[0] === 'banner0' || q[0] === 'banner1') { timerRef.current = setTimeout(() => { if (window.restoreVideoSize) { window.restoreVideoSize(); } }, 1000); log(`banner0/1 케이스: playVideo(${q[0]}) 호출`); return playVideo(q[0]); } else if (q[0] === 'banner2' || q[0] === 'banner3') { if (q[1] === 'banner0' || q[1] === 'banner1') { log(`banner2/3 → banner0/1: 동영상 유지 (재생하지 않음)`); return Promise.resolve(); // 동영상 유지 } else if (q[1] === 'icons') { log(`icons → banner2/3: restartVideo 호출 (${q[0]})`); timerRef.current = setTimeout(() => { if (window.restoreVideoSize) { window.restoreVideoSize(); } }, 1000); return restartVideo(); } } else if (q[0] === 'icons') { log('icons 케이스: 비디오 숨김 (소리 유지)'); if (window.hideModalVideo) { window.hideModalVideo(); } return Promise.resolve(true); } log('기본 케이스: Promise.resolve 반환'); return Promise.resolve(); }; const cleanup = () => { // log('cleanup: 타이머 정리'); if (timerRef.current) { clearTimeout(timerRef.current); timerRef.current = null; } }; return { playByTransition, cleanup }; }; export { useVideoMove };