import { useState } from "react"; import { useTranslation } from "react-i18next"; import { ArrowRight, ChevronsDownUp, ChevronsUpDown, Search } from "lucide-react"; import { useCategoryTaxonomy } from "../../hooks/useCategoryTaxonomy"; import CategoryTaxonomyTree from "../categories/CategoryTaxonomyTree"; import type { TaxonomyNode } from "../../services/categoryTaxonomyService"; interface StepDiscoverProps { onNext: () => void; } function collectAllIds(nodes: TaxonomyNode[]): number[] { const ids: number[] = []; const walk = (n: TaxonomyNode) => { ids.push(n.id); n.children.forEach(walk); }; nodes.forEach(walk); return ids; } function countNodes(nodes: TaxonomyNode[]): { roots: number; subcategories: number; leaves: number; } { let roots = 0; let subcategories = 0; let leaves = 0; for (const root of nodes) { roots += 1; for (const child of root.children) { if (child.children.length === 0) leaves += 1; else { subcategories += 1; for (const leaf of child.children) { if (leaf.children.length === 0) leaves += 1; else subcategories += 1; } } } } return { roots, subcategories, leaves }; } /** * Step 1 — Discover: read-only navigation of the v1 taxonomy. Reuses the same * CategoryTaxonomyTree component as the standalone guide page (#117) so the * two surfaces stay visually consistent. */ export default function StepDiscover({ onNext }: StepDiscoverProps) { const { t } = useTranslation(); const { taxonomy } = useCategoryTaxonomy(); const [search, setSearch] = useState(""); const [expanded, setExpanded] = useState>(() => new Set()); const counts = countNodes(taxonomy.roots); const total = counts.roots + counts.subcategories + counts.leaves; const toggleNode = (id: number) => { setExpanded((prev) => { const next = new Set(prev); if (next.has(id)) next.delete(id); else next.add(id); return next; }); }; const handleExpandAll = () => { setExpanded(new Set(collectAllIds(taxonomy.roots))); }; const handleCollapseAll = () => setExpanded(new Set()); const allExpanded = expanded.size > 0; return (

{t("categoriesSeed.migration.discover.title")}

{t("categoriesSeed.migration.discover.subtitle")}

{t("categoriesSeed.migration.discover.intro.title")}

{t("categoriesSeed.migration.discover.intro.body")}

{t("categoriesSeed.guidePage.counter", { roots: counts.roots, subcategories: counts.subcategories, leaves: counts.leaves, total, })}

); }