{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "import-progress",
  "title": "Import progress",
  "description": "Live CSV import screen with a rolling row counter, striped progress, stage checklist, just-imported feed, auto-fixed warnings with a CSV report download, pause/resume and a cancel confirmation.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/badge.json",
    "https://goodui.dev/r/button.json",
    "https://goodui.dev/r/dialog.json",
    "https://goodui.dev/r/number-flow.json",
    "https://goodui.dev/r/progress.json",
    "https://goodui.dev/r/success-check.json"
  ],
  "files": [
    {
      "path": "registry/blocks/onboarding/import-progress.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AlertTriangle, Check, Download, FileSpreadsheet, Loader2, Pause, Play, RotateCcw, Users, X } from \"lucide-react\"\nimport { Badge } from \"@/components/goodui/badge\"\nimport { Button } from \"@/components/goodui/button\"\nimport { Dialog } from \"@/components/goodui/dialog\"\nimport { NumberFlow } from \"@/components/goodui/number-flow\"\nimport { Progress } from \"@/components/goodui/progress\"\nimport { SuccessCheck } from \"@/components/goodui/success-check\"\nimport { cn } from \"@/lib/utils\"\n\n/* ---------- Demo data ---------- */\n\nconst TOTAL = 1240\nconst STAGES = [\n  { id: \"read\", label: \"Reading clients.csv\", at: 0 },\n  { id: \"validate\", label: \"Validating rows\", at: 0.12 },\n  { id: \"dedupe\", label: \"Merging duplicates\", at: 0.35 },\n  { id: \"import\", label: \"Importing clients\", at: 0.5 },\n  { id: \"history\", label: \"Attaching visit history\", at: 0.82 },\n  { id: \"index\", label: \"Rebuilding search\", at: 0.95 },\n]\nconst WARNINGS = [\n  { row: 118, issue: \"Phone number missing a country code\", fix: \"Assumed +1\" },\n  { row: 342, issue: \"Email “maya@@lumen.co” is invalid\", fix: \"Left empty\" },\n  { row: 507, issue: \"Duplicate of row 211 (same phone)\", fix: \"Merged\" },\n  { row: 913, issue: \"Last visit date in the future\", fix: \"Cleared\" },\n]\nconst NAMES = [\"Grace Kim\", \"Daniel Ortiz\", \"Mia Rossi\", \"Noah Fischer\", \"Aisha Rahman\", \"Leo Park\", \"Priya Nair\", \"Sam Okafor\", \"Lena Weber\", \"Omar Haddad\", \"Chloé Bernard\", \"Ethan Brooks\"]\n\n/* ---------- Block ---------- */\n\nexport default function ImportProgress() {\n  const [count, setCount] = React.useState(0)\n  const [running, setRunning] = React.useState(true)\n  const [cancelAsk, setCancelAsk] = React.useState(false)\n  const [cancelled, setCancelled] = React.useState(false)\n  const [run, setRun] = React.useState(0)\n\n  const pct = Math.min(100, Math.round((count / TOTAL) * 100))\n  const done = count >= TOTAL\n  const stageIdx = STAGES.reduce((acc, s, i) => (count / TOTAL >= s.at ? i : acc), 0)\n  const warnings = WARNINGS.filter((w) => w.row <= count)\n  const merged = count > 507 ? 18 : count > 211 ? 6 : 0\n  const recent = NAMES.slice(0, Math.min(NAMES.length, Math.floor(count / 100) + 1)).slice(-4).reverse()\n\n  React.useEffect(() => {\n    if (!running || done || cancelled) return\n    const id = window.setInterval(() => setCount((c) => Math.min(TOTAL, c + 7 + ((c * 13) % 9))), 60)\n    return () => window.clearInterval(id)\n  }, [running, done, cancelled])\n\n  const restart = () => {\n    setCount(0)\n    setCancelled(false)\n    setRunning(true)\n    setRun((r) => r + 1)\n  }\n  const downloadReport = () => {\n    const csv = [\"row,issue,fix\", ...WARNINGS.map((w) => `${w.row},\"${w.issue}\",\"${w.fix}\"`)].join(\"\\n\")\n    const url = URL.createObjectURL(new Blob([csv], { type: \"text/csv\" }))\n    const a = document.createElement(\"a\")\n    a.href = url\n    a.download = \"import-warnings.csv\"\n    a.click()\n    URL.revokeObjectURL(url)\n  }\n\n  return (\n    <div className=\"p-4 md:p-6\">\n      <section className=\"mx-auto max-w-4xl overflow-hidden rounded-3xl border bg-card\">\n        <div className=\"flex items-center gap-3 border-b px-5 py-4\">\n          <span className=\"flex size-10 items-center justify-center rounded-xl bg-emerald-500/15 text-emerald-700 dark:text-emerald-300\"><FileSpreadsheet className=\"size-5\" /></span>\n          <div className=\"min-w-0 flex-1\">\n            <div className=\"flex items-center gap-2 text-sm font-semibold\">clients.csv <Badge size=\"xs\" variant=\"soft\" tone=\"neutral\">{TOTAL.toLocaleString(\"en-US\")} rows · 212 KB</Badge></div>\n            <div className=\"text-xs text-muted-foreground\">{cancelled ? \"Import cancelled. Nothing was changed.\" : done ? \"Import finished\" : running ? `${STAGES[stageIdx]?.label}…` : \"Paused\"}</div>\n          </div>\n          {!done && !cancelled && (\n            <div className=\"flex gap-1.5\">\n              <Button size=\"sm\" variant=\"outline\" tone=\"neutral\" iconLeft={running ? <Pause /> : <Play />} onClick={() => setRunning((r) => !r)}>{running ? \"Pause\" : \"Resume\"}</Button>\n              <Button size=\"sm\" variant=\"ghost\" tone=\"danger\" iconLeft={<X />} onClick={() => setCancelAsk(true)}>Cancel</Button>\n            </div>\n          )}\n          {(done || cancelled) && <Button size=\"sm\" variant=\"outline\" tone=\"neutral\" iconLeft={<RotateCcw />} onClick={restart}>Run again</Button>}\n        </div>\n\n        <div className=\"grid gap-6 p-5 sm:p-6 lg:grid-cols-[1fr_280px]\">\n          <div className=\"flex flex-col gap-6\">\n            <div className=\"flex items-end justify-between gap-4\">\n              <div>\n                <div className=\"text-xs text-muted-foreground\">Imported</div>\n                <div className=\"flex items-baseline gap-1 text-4xl font-semibold tracking-tight tabular-nums\">\n                  <NumberFlow value={count} /> <span className=\"text-base text-muted-foreground\">/ {TOTAL.toLocaleString(\"en-US\")}</span>\n                </div>\n              </div>\n              <div className=\"text-end\">\n                <div className=\"text-xs text-muted-foreground\">{done ? \"Took\" : \"Time left\"}</div>\n                <div className=\"text-lg font-medium tabular-nums\">{done ? \"1m 12s\" : cancelled ? \"—\" : `${Math.max(1, Math.round(((TOTAL - count) / TOTAL) * 72))}s`}</div>\n              </div>\n            </div>\n            <Progress value={pct} variant={done || cancelled ? \"determinate\" : \"striped\"} showValue size=\"lg\" label=\"Overall progress\" indicatorClassName={cn(done && \"bg-emerald-500\", cancelled && \"bg-muted-foreground\")} />\n            <ol className=\"grid gap-2 sm:grid-cols-2\">\n              {STAGES.map((s, i) => {\n                const state = cancelled && i > stageIdx ? \"skipped\" : done || i < stageIdx ? \"done\" : i === stageIdx ? (running && !cancelled ? \"active\" : \"paused\") : \"todo\"\n                return (\n                  <li key={s.id} className={cn(\"flex items-center gap-2.5 rounded-xl border px-3 py-2 text-sm transition-colors\", state === \"active\" && \"border-primary/40 bg-primary/5\", state === \"done\" && \"text-muted-foreground\")}>\n                    <span className={cn(\"flex size-6 shrink-0 items-center justify-center rounded-full\", state === \"done\" ? \"bg-emerald-500 text-white\" : state === \"active\" ? \"bg-primary text-primary-foreground\" : \"bg-muted text-muted-foreground\")}>\n                      {state === \"done\" ? <Check className=\"size-3.5\" /> : state === \"active\" ? <Loader2 className=\"size-3.5 animate-spin motion-reduce:animate-none\" /> : <span className=\"text-[11px]\">{i + 1}</span>}\n                    </span>\n                    <span className={cn(state === \"done\" && \"line-through decoration-muted-foreground/40\")}>{s.label}</span>\n                  </li>\n                )\n              })}\n            </ol>\n            {done && (\n              <div className=\"flex animate-in items-center gap-4 rounded-2xl border border-emerald-500/30 bg-emerald-500/5 p-4 fade-in slide-in-from-bottom-2\">\n                <SuccessCheck size={44} />\n                <div className=\"text-sm\">\n                  <div className=\"font-semibold\">{(TOTAL - merged).toLocaleString(\"en-US\")} clients imported</div>\n                  <div className=\"text-muted-foreground\">{merged} duplicates merged, {WARNINGS.length} rows fixed automatically.</div>\n                </div>\n                <Button size=\"sm\" className=\"ms-auto\" iconLeft={<Users />} onClick={restart}>Open clients</Button>\n              </div>\n            )}\n          </div>\n\n          <div className=\"flex flex-col gap-4\">\n            <div className=\"rounded-2xl border bg-muted/30 p-3\">\n              <div className=\"flex items-center justify-between text-xs font-medium\"><span>Just imported</span><span className=\"text-muted-foreground tabular-nums\">{merged} merged</span></div>\n              <ul className=\"mt-2 flex min-h-[7.5rem] flex-col gap-1.5\" aria-live=\"polite\" key={run}>\n                {recent.map((n) => (\n                  <li key={n} className=\"flex animate-in items-center gap-2 rounded-lg bg-card px-2 py-1.5 text-xs shadow-xs fade-in slide-in-from-top-1\">\n                    <span className=\"flex size-5 items-center justify-center rounded-full bg-primary/10 text-[10px] font-semibold text-primary\">{n.split(\" \").map((p) => p[0]).join(\"\")}</span>\n                    {n}\n                  </li>\n                ))}\n              </ul>\n            </div>\n            <div className=\"rounded-2xl border p-3\">\n              <div className=\"flex items-center justify-between text-xs font-medium\">\n                <span className=\"flex items-center gap-1.5\"><AlertTriangle className=\"size-3.5 text-amber-500\" /> Fixed on the way</span>\n                <Badge size=\"xs\" variant=\"soft\" tone=\"warning\">{warnings.length}</Badge>\n              </div>\n              <ul className=\"mt-2 flex flex-col gap-1.5 text-xs\">\n                {warnings.length ? warnings.map((w) => (\n                  <li key={w.row} className=\"animate-in rounded-lg bg-muted/50 px-2 py-1.5 fade-in\">\n                    <span className=\"font-mono text-muted-foreground\">Row {w.row}</span> · {w.issue} <span className=\"text-emerald-700 dark:text-emerald-300\">→ {w.fix}</span>\n                  </li>\n                )) : <li className=\"text-muted-foreground\">Nothing so far.</li>}\n              </ul>\n              {warnings.length > 0 && <Button size=\"xs\" variant=\"ghost\" tone=\"neutral\" className=\"mt-2\" iconLeft={<Download />} onClick={downloadReport}>Download report</Button>}\n            </div>\n          </div>\n        </div>\n      </section>\n\n      <Dialog\n        open={cancelAsk}\n        onOpenChange={setCancelAsk}\n        role=\"alertdialog\"\n        tone=\"danger\"\n        title=\"Cancel the import?\"\n        description={`${count.toLocaleString(\"en-US\")} rows have been read. Nothing is saved until the import finishes, so cancelling leaves your clients exactly as they were.`}\n        confirmText=\"Cancel import\"\n        cancelText=\"Keep going\"\n        confirmTone=\"danger\"\n        size=\"sm\"\n        onConfirm={() => { setCancelled(true); setRunning(false) }}\n      />\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/import-progress.tsx"
    }
  ],
  "categories": [
    "onboarding"
  ],
  "type": "registry:block"
}
