"use client" import { useEffect, useState } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Progress } from "@/components/ui/progress" import { Badge } from "@/components/ui/badge" import { ScrollArea } from "@/components/ui/scroll-area" import { GroupPreview } from "./group-preview" import { Alert, AlertDescription } from "@/components/ui/alert" import { AlertCircle, CheckCircle2 } from "lucide-react" interface GroupCreationProgressProps { planId: string onComplete: () => void } export function GroupCreationProgress({ planId, onComplete }: GroupCreationProgressProps) { const [groups, setGroups] = useState([]) const [currentGroupIndex, setCurrentGroupIndex] = useState(0) const [status, setStatus] = useState<"preparing" | "creating" | "completed">("preparing") const [error, setError] = useState(null) useEffect(() => { // 模拟获取分组数据 const mockGroups = Array.from({ length: 5 }).map((_, index) => ({ id: `group-${index}`, members: Array.from({ length: Math.floor(Math.random() * 10) + 30 }).map((_, mIndex) => ({ id: `member-${index}-${mIndex}`, nickname: `用户${mIndex + 1}`, wechatId: `wx_${mIndex}`, tags: [`标签${(mIndex % 3) + 1}`], })), })) setGroups(mockGroups) setStatus("creating") }, []) useEffect(() => { if (status === "creating" && currentGroupIndex < groups.length) { const timer = setTimeout(() => { if (currentGroupIndex === groups.length - 1) { setStatus("completed") onComplete() } else { setCurrentGroupIndex((prev) => prev + 1) } }, 3000) return () => clearTimeout(timer) } }, [status, currentGroupIndex, groups.length, onComplete]) const handleRetryGroup = (groupIndex: number) => { // 模拟重试逻辑 setGroups((prev) => prev.map((group, index) => { if (index === groupIndex) { return { ...group, members: [ ...group.members, { id: `retry-member-${Date.now()}`, nickname: `补充用户${group.members.length + 1}`, wechatId: `wx_retry_${Date.now()}`, tags: ["新加入"], }, ], } } return group }), ) } return (
建群进度 {status === "preparing" ? "准备中" : status === "creating" ? "创建中" : "已完成"}
{currentGroupIndex + 1}/{groups.length}组
{error && ( {error} )}
{groups.map((group, index) => ( handleRetryGroup(index)} /> ))}
{status === "completed" && ( 所有群组已创建完成 )}
) }