"use client"; import { useMemo } from "react"; import { useTranslation } from "react-i18next"; import { CheckCircle2, Circle, LoaderCircle } from "lucide-react"; import { useTaskStore } from "@/store/task"; import { cn } from "@/utils/style"; type StepState = "completed" | "active" | "pending"; interface WorkflowStep { id: string; label: string; completed: boolean; state: StepState; } function StepIcon({ state }: { state: StepState }) { if (state === "completed") { return ; } else if (state === "active") { return ; } else { return ; } } function WorkflowProgress() { const { t } = useTranslation(); const { question, questions, reportPlan, tasks, finalReport } = useTaskStore(); const completedTaskCount = useMemo(() => { return tasks.filter((task) => task.state === "completed").length; }, [tasks]); const collectionDone = tasks.length > 0 && completedTaskCount === tasks.length; const steps = useMemo(() => { const rawSteps: Omit[] = [ { id: "topic", label: t("research.workflow.topic"), completed: question.trim().length > 0, }, { id: "questions", label: t("research.workflow.questions"), completed: questions.trim().length > 0, }, { id: "plan", label: t("research.workflow.plan"), completed: reportPlan.trim().length > 0, }, { id: "collection", label: t("research.workflow.collection"), completed: collectionDone, }, { id: "report", label: t("research.workflow.report"), completed: finalReport.trim().length > 0, }, ]; const activeIndex = rawSteps.findIndex((step) => !step.completed); return rawSteps.map((step, idx) => ({ ...step, state: step.completed || activeIndex === -1 ? "completed" : idx === activeIndex ? "active" : "pending", })) as WorkflowStep[]; }, [collectionDone, finalReport, question, questions, reportPlan, t]); const completedStages = useMemo(() => { return steps.filter((step) => step.completed).length; }, [steps]); const progress = Math.round((completedStages / steps.length) * 100); function getStepDescription(step: WorkflowStep): string { if (step.id === "collection" && tasks.length > 0) { return t("research.workflow.collectionDetail", { completed: completedTaskCount, total: tasks.length, }); } if (step.state === "completed") { return t("research.workflow.done"); } else if (step.state === "active") { return t("research.workflow.active"); } else { return t("research.workflow.pending"); } } return ( {t("research.workflow.title")} {t("research.workflow.summary", { progress, completed: completedStages, total: steps.length, })} {steps.map((step) => ( {step.label} {getStepDescription(step)} ))} ); } export default WorkflowProgress;
{step.label}
{getStepDescription(step)}