import React, { useState, useRef } from 'react'; import { motion } from 'framer-motion'; import { Check, X, CircleAlert } from 'lucide-react'; import { cn } from '@/public/lib/utils'; // 定义类型 interface Shot { id: string; videoUrl?: string; thumbnailUrl: string; isGenerating: boolean; isSelected: boolean; } interface Item { id: string; name: string; avatarUrl: string; } interface ReplacePanelProps { title: string; shots: Shot[]; item: Item; showAddToLibrary?: boolean; addToLibraryText?: string; onClose: () => void; onConfirm: (selectedShots: string[], addToLibrary: boolean) => void; } export function ReplacePanel({ title, shots, item, showAddToLibrary = false, addToLibraryText = "同步添加至库", onClose, onConfirm, }: ReplacePanelProps) { const [selectedShots, setSelectedShots] = useState( shots.filter(shot => shot.isSelected).map(shot => shot.id) ); const [addToLibrary, setAddToLibrary] = useState(true); const [hoveredVideoId, setHoveredVideoId] = useState(null); const videoRefs = useRef<{ [key: string]: HTMLVideoElement }>({}); const handleShotToggle = (shotId: string) => { setSelectedShots(prev => prev.includes(shotId) ? prev.filter(id => id !== shotId) : [...prev, shotId] ); }; const handleSelectAllShots = (checked: boolean) => { setSelectedShots(checked ? shots.map(shot => shot.id) : []); }; const handleMouseEnter = (shotId: string) => { setHoveredVideoId(shotId); if (videoRefs.current[shotId]) { videoRefs.current[shotId].play(); } }; const handleMouseLeave = (shotId: string) => { setHoveredVideoId(null); if (videoRefs.current[shotId]) { videoRefs.current[shotId].pause(); videoRefs.current[shotId].currentTime = 0; } }; const handleConfirm = () => { onConfirm(selectedShots, addToLibrary); }; return (
{/* 标题 */}
{title}
{/* 提示信息 */}
该内容出现在 {shots.length} 个分镜中,替换后将影响如下分镜
handleSelectAllShots(e.target.checked)} className="w-4 h-4 rounded border-white/20" />
{/* 分镜展示区 */}
选择需要替换的分镜:
{shots.map((shot) => ( handleShotToggle(shot.id)} onMouseEnter={() => handleMouseEnter(shot.id)} onMouseLeave={() => handleMouseLeave(shot.id)} whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.98 }} > {shot.videoUrl && ( ))}
{/* 预览信息 */}
{item.name}
{item.name}
{/* 同步到库选项 */} {showAddToLibrary && (
setAddToLibrary(e.target.checked)} className="w-4 h-4 rounded border-white/20" />
)} {/* 操作按钮 */}
); }