"use client" import { type MouseEvent as ReactMouseEvent, type ReactNode, useEffect, useMemo, useRef, useState } from "react" import { createPortal } from "react-dom" import { BookOpen, Check, Copy, Database, Download, Edit3, FileText, Image as ImageIcon, Loader2, Package, Plus, Search, Sparkles, Trash2, Upload, Video, X, } from "lucide-react" import { toast } from "sonner" import { MediaAssetTile } from "@/components/media-asset-tile" import { type AssetLibraryItem, type AssetLibraryKind, type ImageRef, type PromptLibraryCategory, type PromptLibraryItem, type ResourceLibraryRecentItem, apiAssetUrl, copyAssetLibraryToJob, createAssetLibraryItem, createPromptLibraryItem, deleteAssetLibraryItem, deletePromptLibraryItem, getAssetLibraryRefs, getResourceLibraryRecent, listAssetLibrary, listPromptLibrary, usePromptLibraryItem, } from "@/lib/api" type LibraryTab = "prompts" | "assets" type LibraryApplyTarget = "copy_only" | "product_pool" type LibraryDrawerProps = { open: boolean currentJobId?: string onClose: () => void onApplyAsset?: (kind: AssetLibraryKind, ref: ImageRef, target: LibraryApplyTarget, item: AssetLibraryItem) => Promise | void } const DRAWER_STORAGE_KEY = "skg-resource-library-drawer" const PROMPT_COLUMNS: Array<{ category: PromptLibraryCategory; label: string; desc: string }> = [ { category: "scene_desc", label: "场景描述", desc: "首尾帧、场景图、环境描述" }, { category: "video_desc", label: "视频描述", desc: "视频生成动作、镜头语言" }, { category: "subject_desc", label: "主体描述", desc: "人物、透明骨架、角色 brief" }, { category: "skg_script", label: "SKG 文案", desc: "口播、卖点、作者意图" }, { category: "product_angle", label: "产品角度", desc: "视角、佩戴、结构约束" }, ] const ASSET_COLUMNS: Array<{ kind: AssetLibraryKind; label: string; icon: ReactNode }> = [ { kind: "subjects", label: "主体", icon: }, { kind: "products", label: "产品", icon: }, { kind: "scenes", label: "场景", icon: }, { kind: "videos", label: "视频", icon: