{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "export-center",
  "title": "Export center",
  "description": "Export jobs with format icons, animated progress, ready downloads that really save a file, failed and expired states with retry, delete with undo, scheduled exports with toggles and a new-export dialog with source, range, format and column picking.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/badge.json",
    "https://goodui.dev/r/button.json",
    "https://goodui.dev/r/checkbox.json",
    "https://goodui.dev/r/dialog.json",
    "https://goodui.dev/r/progress.json",
    "https://goodui.dev/r/select.json",
    "https://goodui.dev/r/switch.json"
  ],
  "files": [
    {
      "path": "registry/blocks/tables/export-center.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { CalendarClock, Check, Download, FileJson, FileSpreadsheet, FileText, Plus, RefreshCw, Trash2, Undo2, X } from \"lucide-react\"\nimport { Badge } from \"@/components/goodui/badge\"\nimport { Button } from \"@/components/goodui/button\"\nimport { Checkbox } from \"@/components/goodui/checkbox\"\nimport { Dialog } from \"@/components/goodui/dialog\"\nimport { Select } from \"@/components/goodui/select\"\nimport { Switch } from \"@/components/goodui/switch\"\nimport { Progress } from \"@/components/goodui/progress\"\nimport { cn } from \"@/lib/utils\"\n\n/* ---------- Demo data ---------- */\n\ntype Format = \"csv\" | \"xlsx\" | \"json\" | \"pdf\"\ntype Job = { id: string; name: string; source: string; format: Format; rows: number; size: string; status: \"queued\" | \"running\" | \"ready\" | \"failed\" | \"expired\"; progress: number; created: string; expires: string; columns: string[] }\ntype Schedule = { id: string; name: string; source: string; format: Format; cadence: string; to: string; enabled: boolean; next: string }\nconst FMT: Record<Format, { label: string; icon: React.ReactNode }> = {\n  csv: { label: \"CSV\", icon: <FileText /> },\n  xlsx: { label: \"Excel\", icon: <FileSpreadsheet /> },\n  json: { label: \"JSON\", icon: <FileJson /> },\n  pdf: { label: \"PDF\", icon: <FileText /> },\n}\nconst SOURCES = [\n  { value: \"bookings\", label: \"Bookings\" },\n  { value: \"clients\", label: \"Clients\" },\n  { value: \"payments\", label: \"Payments\" },\n  { value: \"reviews\", label: \"Reviews\" },\n]\nconst COLUMNS: Record<string, string[]> = {\n  bookings: [\"id\", \"client\", \"stylist\", \"service\", \"starts_at\", \"status\", \"total\", \"tip\", \"rating\"],\n  clients: [\"id\", \"name\", \"email\", \"phone\", \"tags\", \"lifetime_value\", \"last_visit\", \"consent_marketing\"],\n  payments: [\"id\", \"booking_id\", \"method\", \"amount\", \"fee\", \"net\", \"paid_at\"],\n  reviews: [\"id\", \"client\", \"rating\", \"source\", \"text\", \"reply\", \"created_at\"],\n}\nconst INITIAL_JOBS: Job[] = [\n  { id: \"e1\", name: \"Bookings · Feb 2026\", source: \"bookings\", format: \"xlsx\", rows: 2140, size: \"412 kB\", status: \"ready\", progress: 100, created: \"Today 09:12\", expires: \"in 6 days\", columns: COLUMNS.bookings! },\n  { id: \"e2\", name: \"Clients · marketing consent\", source: \"clients\", format: \"csv\", rows: 4810, size: \"—\", status: \"running\", progress: 46, created: \"Just now\", expires: \"—\", columns: [\"name\", \"email\", \"consent_marketing\"] },\n  { id: \"e3\", name: \"Payments · Q4 2025\", source: \"payments\", format: \"csv\", rows: 7980, size: \"1.1 MB\", status: \"ready\", progress: 100, created: \"Yesterday\", expires: \"in 5 days\", columns: COLUMNS.payments! },\n  { id: \"e4\", name: \"Reviews · all time\", source: \"reviews\", format: \"json\", rows: 0, size: \"—\", status: \"failed\", progress: 12, created: \"2 days ago\", expires: \"—\", columns: COLUMNS.reviews! },\n  { id: \"e5\", name: \"Bookings · Jan 2026\", source: \"bookings\", format: \"pdf\", rows: 1980, size: \"2.4 MB\", status: \"expired\", progress: 100, created: \"3 weeks ago\", expires: \"expired\", columns: COLUMNS.bookings! },\n]\nconst INITIAL_SCHEDULES: Schedule[] = [\n  { id: \"s1\", name: \"Weekly bookings to accountant\", source: \"bookings\", format: \"xlsx\", cadence: \"Every Monday 07:00\", to: \"books@studionine.com\", enabled: true, next: \"Mon 16 Mar\" },\n  { id: \"s2\", name: \"Monthly client list to Mailchimp\", source: \"clients\", format: \"csv\", cadence: \"1st of month\", to: \"SFTP · mailchimp-sync\", enabled: false, next: \"1 Apr\" },\n]\n\n/* ---------- Block ---------- */\n\nexport default function ExportCenter() {\n  const [jobs, setJobs] = React.useState(INITIAL_JOBS)\n  const [schedules, setSchedules] = React.useState(INITIAL_SCHEDULES)\n  const [newOpen, setNewOpen] = React.useState(false)\n  const [source, setSource] = React.useState(\"bookings\")\n  const [format, setFormat] = React.useState<Format>(\"csv\")\n  const [cols, setCols] = React.useState<string[]>(COLUMNS.bookings!)\n  const [range, setRange] = React.useState(\"30d\")\n  const [removed, setRemoved] = React.useState<{ job: Job; index: number } | null>(null)\n  const timers = React.useRef<number[]>([])\n  React.useEffect(() => () => timers.current.forEach((t) => window.clearTimeout(t)), [])\n\n  // Advance running exports.\n  React.useEffect(() => {\n    if (!jobs.some((j) => j.status === \"running\")) return\n    const t = window.setTimeout(() => {\n      setJobs((all) =>\n        all.map((j) => {\n          if (j.status !== \"running\") return j\n          const p = Math.min(100, j.progress + 9)\n          return p >= 100 ? { ...j, status: \"ready\", progress: 100, size: `${Math.round(j.rows * 0.09)} kB`, expires: \"in 7 days\" } : { ...j, progress: p }\n        }),\n      )\n    }, 450)\n    return () => window.clearTimeout(t)\n  }, [jobs])\n\n  const download = (j: Job) => {\n    const body = j.format === \"json\" ? JSON.stringify([{ id: \"demo\", note: \"sample export\" }], null, 2) : `${j.columns.join(\",\")}\\n${j.columns.map(() => \"sample\").join(\",\")}`\n    const url = URL.createObjectURL(new Blob([body], { type: j.format === \"json\" ? \"application/json\" : \"text/csv\" }))\n    const a = document.createElement(\"a\")\n    a.href = url\n    a.download = `${j.name.replace(/[^\\w]+/g, \"-\").toLowerCase()}.${j.format === \"xlsx\" ? \"csv\" : j.format}`\n    a.click()\n    URL.revokeObjectURL(url)\n  }\n  const retry = (id: string) => setJobs((all) => all.map((j) => (j.id === id ? { ...j, status: \"running\", progress: 5, rows: 1120 } : j)))\n  const remove = (j: Job) => {\n    const index = jobs.findIndex((x) => x.id === j.id)\n    setRemoved({ job: j, index })\n    setJobs(jobs.filter((x) => x.id !== j.id))\n    timers.current.push(window.setTimeout(() => setRemoved((r) => (r?.job.id === j.id ? null : r)), 6000))\n  }\n  const create = () => {\n    const src = SOURCES.find((s) => s.value === source)!\n    setJobs([{ id: `n${jobs.length}-${cols.length}`, name: `${src.label} · ${range === \"30d\" ? \"last 30 days\" : range === \"90d\" ? \"last 90 days\" : \"all time\"}`, source, format, rows: range === \"all\" ? 18420 : range === \"90d\" ? 5410 : 1860, size: \"—\", status: \"running\", progress: 3, created: \"Just now\", expires: \"—\", columns: cols }, ...jobs])\n    setNewOpen(false)\n  }\n  const changeSource = (v: string | null) => {\n    if (!v) return\n    setSource(v)\n    setCols(COLUMNS[v] ?? [])\n  }\n\n  return (\n    <div className=\"p-4 md:p-6\">\n      <div className=\"mx-auto max-w-5xl\">\n        <div className=\"flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"font-heading text-xl font-semibold tracking-tight\">Export center</h2>\n            <p className=\"text-sm text-muted-foreground\">Files are ready in under a minute and kept for 7 days.</p>\n          </div>\n          <Button size=\"sm\" iconLeft={<Plus />} onClick={() => setNewOpen(true)}>\n            New export\n          </Button>\n        </div>\n\n        <div aria-live=\"polite\" className=\"mt-3\">\n          {removed && (\n            <div className=\"flex items-center justify-between rounded-xl border border-dashed px-3 py-2 text-sm\">\n              Deleted “{removed.job.name}”.\n              <Button\n                size=\"xs\"\n                variant=\"soft\"\n                tone=\"neutral\"\n                iconLeft={<Undo2 />}\n                onClick={() => {\n                  const next = [...jobs]\n                  next.splice(removed.index, 0, removed.job)\n                  setJobs(next)\n                  setRemoved(null)\n                }}\n              >\n                Undo\n              </Button>\n            </div>\n          )}\n        </div>\n\n        {/* Jobs */}\n        <ul className=\"mt-3 space-y-2\">\n          {jobs.map((j) => (\n            <li key={j.id} className={cn(\"flex flex-wrap items-center gap-3 rounded-2xl border bg-card px-4 py-3 shadow-xs\", j.status === \"expired\" && \"saturate-50 bg-muted/40 [&_.text-muted-foreground]:text-foreground/70\")}>\n              <span className={cn(\"flex size-10 shrink-0 items-center justify-center rounded-xl [&_svg]:size-5\", j.format === \"xlsx\" ? \"bg-emerald-500/15 text-emerald-800 dark:text-emerald-300\" : j.format === \"json\" ? \"bg-amber-500/15 text-amber-800 dark:text-amber-300\" : j.format === \"pdf\" ? \"bg-rose-500/15 text-rose-800 dark:text-rose-300\" : \"bg-sky-500/15 text-sky-800 dark:text-sky-300\")}>{FMT[j.format].icon}</span>\n              <div className=\"min-w-0 flex-1 basis-56\">\n                <div className=\"flex flex-wrap items-center gap-2\">\n                  <span className=\"truncate font-medium\">{j.name}</span>\n                  <Badge variant=\"outline\" tone=\"neutral\" size=\"xs\">\n                    {FMT[j.format].label}\n                  </Badge>\n                  {j.status === \"failed\" && (\n                    <Badge variant=\"soft\" tone=\"danger\" size=\"xs\">\n                      Failed\n                    </Badge>\n                  )}\n                  {j.status === \"expired\" && (\n                    <Badge variant=\"soft\" tone=\"neutral\" size=\"xs\">\n                      Expired\n                    </Badge>\n                  )}\n                </div>\n                <div className=\"text-xs text-muted-foreground\">\n                  {j.rows ? `${j.rows.toLocaleString(\"en-US\")} rows · ` : \"\"}\n                  {j.columns.length} columns · {j.created}\n                  {j.status === \"ready\" && ` · ${j.size} · expires ${j.expires}`}\n                </div>\n                {j.status === \"running\" && <Progress value={j.progress} size=\"sm\" className=\"mt-2 max-w-xs\" label=\"Exporting\" showValue />}\n                {j.status === \"failed\" && <p className=\"mt-1 text-xs text-rose-800 dark:text-rose-400\">Timed out reading reviews.text — try a smaller date range.</p>}\n              </div>\n              <div className=\"flex items-center gap-1.5\">\n                {j.status === \"ready\" && (\n                  <Button size=\"sm\" variant=\"soft\" tone=\"primary\" iconLeft={<Download />} onClick={() => download(j)}>\n                    Download\n                  </Button>\n                )}\n                {(j.status === \"failed\" || j.status === \"expired\") && (\n                  <Button size=\"sm\" variant=\"outline\" tone=\"neutral\" iconLeft={<RefreshCw />} onClick={() => retry(j.id)}>\n                    {j.status === \"failed\" ? \"Retry\" : \"Regenerate\"}\n                  </Button>\n                )}\n                {j.status === \"running\" && (\n                  <Button size=\"sm\" variant=\"ghost\" tone=\"neutral\" iconLeft={<X />} onClick={() => setJobs(jobs.filter((x) => x.id !== j.id))}>\n                    Cancel\n                  </Button>\n                )}\n                <Button size=\"xs\" variant=\"ghost\" tone=\"danger\" iconOnly aria-label={`Delete ${j.name}`} onClick={() => remove(j)}>\n                  <Trash2 />\n                </Button>\n              </div>\n            </li>\n          ))}\n        </ul>\n\n        {/* Schedules */}\n        <h3 className=\"mt-6 flex items-center gap-2 text-sm font-medium\">\n          <CalendarClock className=\"size-4\" /> Scheduled exports\n        </h3>\n        <ul className=\"mt-2 space-y-2\">\n          {schedules.map((s) => (\n            <li key={s.id} className={cn(\"flex flex-wrap items-center gap-3 rounded-2xl border bg-card px-4 py-3 shadow-xs transition-opacity\", !s.enabled && \"saturate-50 bg-muted/40 [&_.text-muted-foreground]:text-foreground/70\")}>\n              <Switch size=\"sm\" checked={s.enabled} onCheckedChange={(v) => setSchedules(schedules.map((x) => (x.id === s.id ? { ...x, enabled: v } : x)))} aria-label={`${s.name} enabled`} />\n              <div className=\"min-w-0 flex-1 basis-56\">\n                <div className=\"truncate font-medium\">{s.name}</div>\n                <div className=\"text-xs text-muted-foreground\">\n                  {s.cadence} · {FMT[s.format].label} · to {s.to}\n                </div>\n              </div>\n              <span className=\"text-xs text-muted-foreground\">{s.enabled ? `Next ${s.next}` : \"Paused\"}</span>\n            </li>\n          ))}\n        </ul>\n      </div>\n\n      <Dialog open={newOpen} onOpenChange={setNewOpen} title=\"New export\" description=\"Pick the data, columns and format.\" icon={<Download />} size=\"lg\" mobile=\"sheet\" onConfirm={create} confirmText=\"Start export\">\n        <div className=\"grid gap-4\">\n          <div className=\"grid gap-3 sm:grid-cols-2\">\n            <div>\n              <label htmlFor=\"exp-source\" className=\"mb-1.5 block text-sm font-medium\">\n                Data\n              </label>\n              <Select id=\"exp-source\" options={SOURCES} value={source} onValueChange={changeSource} />\n            </div>\n            <div>\n              <label htmlFor=\"exp-range\" className=\"mb-1.5 block text-sm font-medium\">\n                Range\n              </label>\n              <Select id=\"exp-range\" options={[{ value: \"30d\", label: \"Last 30 days\" }, { value: \"90d\", label: \"Last 90 days\" }, { value: \"all\", label: \"All time\" }]} value={range} onValueChange={(v) => v && setRange(v)} />\n            </div>\n          </div>\n          <div>\n            <div className=\"mb-1.5 text-sm font-medium\">Format</div>\n            <div className=\"grid grid-cols-4 gap-2\">\n              {(Object.keys(FMT) as Format[]).map((f) => (\n                <button key={f} type=\"button\" aria-pressed={format === f} onClick={() => setFormat(f)} className={cn(\"flex flex-col items-center gap-1 rounded-xl border p-3 text-xs font-medium transition-colors [&_svg]:size-5\", format === f ? \"border-primary bg-primary/5 ring-1 ring-primary\" : \"hover:bg-muted\")}>\n                  {FMT[f].icon}\n                  {FMT[f].label}\n                </button>\n              ))}\n            </div>\n          </div>\n          <div>\n            <div className=\"mb-1.5 flex items-center justify-between text-sm\">\n              <span className=\"font-medium\">\n                Columns <span className=\"text-muted-foreground\">({cols.length})</span>\n              </span>\n              <button type=\"button\" onClick={() => setCols(cols.length === (COLUMNS[source]?.length ?? 0) ? [] : (COLUMNS[source] ?? []))} className=\"text-xs text-primary hover:underline\">\n                {cols.length === (COLUMNS[source]?.length ?? 0) ? \"Clear all\" : \"Select all\"}\n              </button>\n            </div>\n            <div className=\"grid grid-cols-2 gap-x-4 gap-y-1 sm:grid-cols-3\">\n              {(COLUMNS[source] ?? []).map((c) => (\n                <Checkbox key={c} size=\"sm\" checked={cols.includes(c)} onCheckedChange={(v) => setCols(v ? [...cols, c] : cols.filter((x) => x !== c))} label={<code className=\"font-mono text-xs\">{c}</code>} />\n              ))}\n            </div>\n          </div>\n          <p className=\"flex items-center gap-1.5 rounded-lg bg-muted px-3 py-2 text-xs text-muted-foreground\">\n            <Check className=\"size-3.5\" /> PII columns are masked unless you have the Owner role.\n          </p>\n        </div>\n      </Dialog>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/export-center.tsx"
    }
  ],
  "categories": [
    "tables"
  ],
  "type": "registry:block"
}
