"use client"; import { useEffect, useCallback } from "react"; import { Loader2 } from "lucide-react"; import { useScriptExtraction } from "./script-extraction/useScriptExtraction"; interface ScriptExtractionModalProps { isOpen: boolean; onClose: () => void; onApply?: (text: string) => void; } export default function ScriptExtractionModal({ isOpen, onClose, onApply, }: ScriptExtractionModalProps) { const { isLoading, script, rewrittenScript, error, doRewrite, step, dragActive, selectedFile, activeTab, inputUrl, setDoRewrite, setActiveTab, setInputUrl, handleDrag, handleDrop, handleFileChange, handleExtract, copyToClipboard, resetToConfig, clearSelectedFile, clearInputUrl, } = useScriptExtraction({ isOpen }); // 快捷键:ESC 关闭,Enter 提交(仅在 config 步骤) const canExtract = (activeTab === "file" && selectedFile) || (activeTab === "url" && inputUrl.trim()); const handleKeyDown = useCallback((e: KeyboardEvent) => { if (e.key === "Escape") { onClose(); } else if (e.key === "Enter" && !e.shiftKey && step === "config" && canExtract && !isLoading) { e.preventDefault(); handleExtract(); } }, [onClose, step, canExtract, isLoading, handleExtract]); useEffect(() => { if (!isOpen) return; document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); }, [isOpen, handleKeyDown]); if (!isOpen) return null; const handleApplyAndClose = (text: string) => { onApply?.(text); onClose(); }; const handleExtractNext = () => { resetToConfig(); clearSelectedFile(); clearInputUrl(); }; return (
{/* Header */}

📜 文案提取助手

{/* Content */}
{step === "config" && (
{/* Tabs */}
{/* URL Input Area */} {activeTab === "url" && (
setInputUrl(e.target.value)} placeholder="请粘贴抖音、B站等主流平台视频链接..." className="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-4 text-white placeholder-gray-500 focus:outline-none focus:border-purple-500 transition-colors" /> {inputUrl && ( )}

支持抖音、B站、微博、小红书等主流平台视频链接

)} {/* File Upload Area */} {activeTab === "file" && (
{selectedFile ? (

{selectedFile.name}

{(selectedFile.size / 1024 / 1024).toFixed(2)} MB

) : (
📁

拖放视频/音频文件到此处,或

支持 MP4, MOV, AVI, MP3, WAV, M4A

)}
)} {/* Options */}
{/* Error */} {error && (

{error}

)} {/* Action Button */}
)} {step === "processing" && (

正在处理中...

{activeTab === "url" && "正在下载视频..."}
{doRewrite ? "正在进行语音识别和 AI 智能改写..." : "正在进行语音识别..."}
大文件可能需要几分钟,请不要关闭窗口

)} {step === "result" && (
{rewrittenScript && (

✨ AI 洗稿结果{" "} (推荐)

{onApply && ( )}

{rewrittenScript}

)}

🎙️ 原始识别结果

{onApply && ( )}

{script}

)}
); }