"use client" import { useState } from "react" import { X } from "lucide-react" import { Button } from "./ui/button" import { Card } from "./ui/card" interface AIRewriteModalProps { isOpen: boolean onClose: () => void originalContent: string } export function AIRewriteModal({ isOpen, onClose, originalContent }: AIRewriteModalProps) { const [rewrittenContent, setRewrittenContent] = useState("") const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const handleRewrite = async () => { try { setIsLoading(true) setError(null) // 调用实际的AI改写API const response = await fetch("/api/ai/rewrite", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ content: originalContent }), }) if (!response.ok) { throw new Error("AI改写请求失败") } const data = await response.json() setRewrittenContent(data.rewrittenContent) } catch (err) { setError(err instanceof Error ? err.message : "改写过程中发生错误") console.error("AI改写错误:", err) } finally { setIsLoading(false) } } if (!isOpen) return null return (

AI 内容改写

原始内容:

{originalContent}

改写后内容:

{rewrittenContent || '点击"开始改写"按钮生成内容'}

{error &&

{error}

}
) }