import { ImageOff } from "lucide-react"; import { useState } from "react"; import { cn } from "@/lib/utils"; const DEFAULT_UNAVAILABLE_LABEL = "预览不可用,素材可能已删除"; export function MediaPreview({ src, kind, alt = "", className, fallbackClassName, fallbackLabel = DEFAULT_UNAVAILABLE_LABEL, controls = false, loading, width, height, onUnavailable, }: { src: string; kind: "image" | "video"; alt?: string; className?: string; fallbackClassName?: string; fallbackLabel?: string; controls?: boolean; loading?: "eager" | "lazy"; width?: number; height?: number; onUnavailable?: () => void; }) { const [failedSrc, setFailedSrc] = useState(""); const unavailable = failedSrc === src; const handleUnavailable = () => { setFailedSrc(src); onUnavailable?.(); }; if (unavailable) { return ( ); } if (kind === "video") { return