"use client" import { useState } from "react" import { Card, CardContent } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Label } from "@/components/ui/label" import { Input } from "@/components/ui/input" import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs" import { ScrollArea } from "@/components/ui/scroll-area" import { Checkbox } from "@/components/ui/checkbox" import { Search, Users, User, MessageCircle, AlertCircle } from "lucide-react" import { Alert, AlertDescription } from "@/components/ui/alert" import Image from "next/image" import type { ContentLibraryFormData } from "../page" interface SourceSelectionProps { formData: ContentLibraryFormData updateFormData: (field: string, value: any) => void onNext: () => void onPrevious: () => void } // 模拟数据 const mockFriends = [ { id: "f1", name: "张三", type: "friend", avatar: "/placeholder.svg?height=40&width=40" }, { id: "f2", name: "李四", type: "friend", avatar: "/placeholder.svg?height=40&width=40" }, { id: "f3", name: "王五", type: "friend", avatar: "/placeholder.svg?height=40&width=40" }, { id: "f4", name: "赵六", type: "friend", avatar: "/placeholder.svg?height=40&width=40" }, { id: "f5", name: "钱七", type: "friend", avatar: "/placeholder.svg?height=40&width=40" }, ] const mockGroups = [ { id: "g1", name: "产品讨论群", type: "group", avatar: "/placeholder.svg?height=40&width=40" }, { id: "g2", name: "市场营销群", type: "group", avatar: "/placeholder.svg?height=40&width=40" }, { id: "g3", name: "技术交流群", type: "group", avatar: "/placeholder.svg?height=40&width=40" }, { id: "g4", name: "客户服务群", type: "group", avatar: "/placeholder.svg?height=40&width=40" }, ] const mockOfficialAccounts = [ { id: "o1", name: "科技前沿", type: "official", avatar: "/placeholder.svg?height=40&width=40" }, { id: "o2", name: "营销之道", type: "official", avatar: "/placeholder.svg?height=40&width=40" }, { id: "o3", name: "数据分析", type: "official", avatar: "/placeholder.svg?height=40&width=40" }, ] export function SourceSelection({ formData, updateFormData, onNext, onPrevious }: SourceSelectionProps) { const [activeTab, setActiveTab] = useState( formData.type === "friends" ? "friends" : formData.type === "groups" ? "groups" : "all", ) const [searchQuery, setSearchQuery] = useState("") const [selectedSources, setSelectedSources] = useState< { id: string name: string type: string avatar?: string }[] >(formData.sources) // 根据内容库类型和当前标签过滤可选来源 const getFilteredSources = () => { let sources = [] if (activeTab === "friends" || activeTab === "all") { sources = [...sources, ...mockFriends] } if (activeTab === "groups" || activeTab === "all") { sources = [...sources, ...mockGroups] } if (activeTab === "official" || activeTab === "all") { sources = [...sources, ...mockOfficialAccounts] } // 应用搜索过滤 if (searchQuery) { sources = sources.filter((source) => source.name.toLowerCase().includes(searchQuery.toLowerCase())) } return sources } const handleSourceToggle = (source: any) => { const isSelected = selectedSources.some((s) => s.id === source.id) if (isSelected) { setSelectedSources(selectedSources.filter((s) => s.id !== source.id)) } else { setSelectedSources([...selectedSources, source]) } } const handleNext = () => { updateFormData("sources", selectedSources) onNext() } const filteredSources = getFilteredSources() const isFormValid = selectedSources.length > 0 return (

来源选择

选择内容库的来源,可以是微信好友、微信群或公众号

{formData.type !== "mixed" && ( {formData.type === "friends" ? "您已选择微信好友类型的内容库,请选择需要收集内容的微信好友。" : formData.type === "groups" ? "您已选择微信群类型的内容库,请选择需要收集内容的微信群。" : "您已选择朋友圈类型的内容库,请选择需要收集内容的来源。"} )}
setSearchQuery(e.target.value)} className="pl-9" />
全部 好友 群组 公众号
可选来源 已选择 {selectedSources.length} 个来源
{filteredSources.length > 0 ? ( filteredSources.map((source) => { const isSelected = selectedSources.some((s) => s.id === source.id) return (
handleSourceToggle(source)} />
{source.name}

{source.name}

{source.type === "friend" ? "微信好友" : source.type === "group" ? "微信群" : "公众号"}

) }) ) : (

未找到匹配的来源

请尝试其他搜索关键词

)}
{selectedSources.length > 0 && (
{selectedSources.map((source) => (
{source.name}
{source.name}
))}
)}
) }