import React, { useState, useEffect, useRef, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { getVideosList, deleteVideo } from '../../utils/api'; import { VideoListItem } from '../../types/api'; import SocialPostingModal from '../../components/SocialPostingModal'; import VideoDetailModal from '../../components/VideoDetailModal'; import { useTutorial } from '../../components/Tutorial/useTutorial'; import { TUTORIAL_KEYS } from '../../components/Tutorial/tutorialSteps'; const VideoPreviewCard: React.FC<{ src: string; className?: string }> = ({ src, className }) => { const videoRef = useRef(null); const isPlayingRef = useRef(false); const pendingPlayRef = useRef(false); useEffect(() => { const video = videoRef.current; if (!video) return; const observer = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting) { video.preload = 'auto'; } else { video.preload = 'none'; } }, { threshold: 0.1 } ); observer.observe(video); return () => observer.disconnect(); }, []); const safePlay = useCallback((video: HTMLVideoElement) => { const playPromise = video.play(); if (playPromise !== undefined) { playPromise .then(() => { isPlayingRef.current = true; }) .catch((error) => { if (error.name !== 'AbortError') console.error(error); }); } }, []); const handleCanPlay = useCallback(() => { if (!pendingPlayRef.current || !videoRef.current) return; pendingPlayRef.current = false; safePlay(videoRef.current); }, [safePlay]); const handleMouseEnter = useCallback(() => { const video = videoRef.current; if (!video) return; if (video.readyState >= 3) { safePlay(video); } else { pendingPlayRef.current = true; } }, [safePlay]); const handleMouseLeave = useCallback(() => { const video = videoRef.current; if (!video) return; pendingPlayRef.current = false; if (isPlayingRef.current) { video.pause(); video.currentTime = 0; isPlayingRef.current = false; } }, []); return (