"use client" import { useState } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent } from "@/components/ui/card" import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Input } from "@/components/ui/input" import { Search, Plus, Trash2 } from "lucide-react" import { ScrollArea } from "@/components/ui/scroll-area" export interface ContentTarget { id: string avatar: string name?: string } export interface ContentLibrary { id: string name: string type?: string count?: number targets?: ContentTarget[] } export interface ContentSelectorProps { /** 已选择的内容库 */ selectedLibraries: ContentLibrary[] /** 内容库变更回调 */ onLibrariesChange: (libraries: ContentLibrary[]) => void /** 上一步回调 */ onPrevious?: () => void /** 下一步回调 */ onNext?: () => void /** 保存回调 */ onSave?: () => void /** 取消回调 */ onCancel?: () => void /** 自定义内容库列表,不传则使用模拟数据 */ contentLibraries?: ContentLibrary[] /** 自定义类名 */ className?: string /** 是否使用卡片包装 */ withCard?: boolean } /** * 统一的内容选择器组件 */ export function ContentSelector({ selectedLibraries = [], onLibrariesChange, onPrevious, onNext, onSave, onCancel, contentLibraries: propContentLibraries, className, withCard = true, }: ContentSelectorProps) { const [isDialogOpen, setIsDialogOpen] = useState(false) const [searchTerm, setSearchTerm] = useState("") // 模拟内容库数据 const defaultContentLibraries: ContentLibrary[] = [ { id: "1", name: "卡若朋友圈", type: "朋友圈", count: 307, targets: [{ id: "t1", avatar: "/placeholder.svg?height=40&width=40&query=avatar1" }], }, { id: "2", name: "业务推广内容", type: "朋友圈", count: 156, targets: [ { id: "t2", avatar: "/placeholder.svg?height=40&width=40&query=avatar2" }, { id: "t3", avatar: "/placeholder.svg?height=40&width=40&query=avatar3" }, ], }, { id: "3", name: "产品介绍", type: "群发", count: 42, targets: [ { id: "t4", avatar: "/placeholder.svg?height=40&width=40&query=avatar4" }, { id: "t5", avatar: "/placeholder.svg?height=40&width=40&query=avatar5" }, ], }, ] const contentLibraries = propContentLibraries || defaultContentLibraries const handleAddLibrary = (library: ContentLibrary) => { if (!selectedLibraries.some((l) => l.id === library.id)) { onLibrariesChange([...selectedLibraries, library]) } setIsDialogOpen(false) } const handleRemoveLibrary = (libraryId: string) => { onLibrariesChange(selectedLibraries.filter((library) => library.id !== libraryId)) } const filteredLibraries = contentLibraries.filter((library) => library.name.toLowerCase().includes(searchTerm.toLowerCase()), ) const ContentSelectorContent = () => (