{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "upload-queue-panel",
  "title": "Upload Queue Panel",
  "description": "An upload manager for many files: drag in or browse real files, two uploads at a time with the rest queued, per-file progress with time left, pause, resume, cancel and retry, a total bar with speed, filters for in progress, done and failed, clear done, and a minimize-to-pill mode with a progress ring.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/upload-queue-panel/upload-queue-panel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype Status = \"queued\" | \"uploading\" | \"paused\" | \"done\" | \"failed\";\ntype Kind = \"image\" | \"pdf\" | \"video\" | \"doc\" | \"zip\";\nexport interface UploadItem {\n  id: string;\n  name: string;\n  size: number; // bytes\n  uploaded: number;\n  status: Status;\n  /** Demo: fail once when progress passes this fraction. */\n  failAt?: number;\n  error?: string;\n}\n\nexport interface UploadQueuePanelProps {\n  items?: UploadItem[];\n  concurrency?: number;\n  onFilesAdded?: (files: File[]) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", panel: \"#121212\", border: \"rgba(255,255,255,0.09)\", track: \"rgba(255,255,255,0.08)\", hover: \"rgba(255,255,255,0.05)\", drop: \"rgba(96,165,250,0.08)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", accent: \"#60A5FA\", green: \"#4ADE80\", red: \"#F87171\", amber: \"#FBBF24\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#F4F4F1\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.4)\", panel: \"#FFFFFF\", border: \"rgba(10,10,10,0.09)\", track: \"rgba(10,10,10,0.07)\", hover: \"rgba(10,10,10,0.04)\", drop: \"rgba(37,99,235,0.06)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", accent: \"#2563EB\", green: \"#15803D\", red: \"#DC2626\", amber: \"#B45309\", ring: \"rgba(10,10,10,0.5)\" },\n};\nconst KIND: Record<Kind, { color: string; label: string }> = { image: { color: \"#A78BFA\", label: \"IMG\" }, pdf: { color: \"#F87171\", label: \"PDF\" }, video: { color: \"#F472B6\", label: \"MP4\" }, doc: { color: \"#60A5FA\", label: \"DOC\" }, zip: { color: \"#FBBF24\", label: \"ZIP\" } };\nconst MB = 1024 * 1024;\nconst ITEMS: UploadItem[] = [\n  { id: \"u1\", name: \"brand-guidelines.pdf\", size: 4.1 * MB, uploaded: 4.1 * MB, status: \"done\" },\n  { id: \"u2\", name: \"hero-photo@2x.jpg\", size: 6.8 * MB, uploaded: 6.8 * MB, status: \"done\" },\n  { id: \"u3\", name: \"product-demo.mp4\", size: 48 * MB, uploaded: 14 * MB, status: \"uploading\" },\n  { id: \"u4\", name: \"q4-forecast.xlsx\", size: 2.4 * MB, uploaded: 0.9 * MB, status: \"uploading\", failAt: 0.62 },\n  { id: \"u5\", name: \"press-kit.zip\", size: 22 * MB, uploaded: 0, status: \"queued\" },\n  { id: \"u6\", name: \"team-offsite.png\", size: 3.2 * MB, uploaded: 0, status: \"queued\" },\n];\nconst kindOf = (name: string): Kind => {\n  const ext = name.split(\".\").pop()?.toLowerCase() ?? \"\";\n  if ([\"png\", \"jpg\", \"jpeg\", \"gif\", \"webp\", \"svg\", \"heic\"].includes(ext)) return \"image\";\n  if (ext === \"pdf\") return \"pdf\";\n  if ([\"mp4\", \"mov\", \"webm\", \"mkv\"].includes(ext)) return \"video\";\n  if ([\"zip\", \"rar\", \"7z\", \"gz\", \"tar\"].includes(ext)) return \"zip\";\n  return \"doc\";\n};\nconst size = (b: number) => (b >= MB ? `${(b / MB).toFixed(b >= 10 * MB ? 0 : 1)} MB` : `${Math.max(1, Math.round(b / 1024))} KB`);\nconst speedOf = (id: string) => (1.6 + ([...id].reduce((s, c) => s + c.charCodeAt(0), 0) % 7) * 0.45) * MB; // bytes / second, stable per file\nconst eta = (s: number) => (s < 60 ? `${Math.max(1, Math.round(s))}s left` : `${Math.ceil(s / 60)} min left`);\n\nexport function UploadQueuePanel({ items: initial = ITEMS, concurrency = 2, onFilesAdded, theme = \"dark\", className }: UploadQueuePanelProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [items, setItems] = React.useState(initial);\n  const [filter, setFilter] = React.useState<\"all\" | \"active\" | \"done\" | \"failed\">(\"all\");\n  const [dragging, setDragging] = React.useState(false);\n  const [minimized, setMinimized] = React.useState(false);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const counter = React.useRef(0);\n\n  // Upload engine: every tick, fill free slots from the queue and advance active uploads.\n  const busy = items.some((i) => i.status === \"uploading\" || i.status === \"queued\");\n  React.useEffect(() => {\n    if (!busy) return;\n    const step = 0.2;\n    const id = setInterval(() => {\n      setItems((list) => {\n        let active = list.filter((i) => i.status === \"uploading\").length;\n        return list.map((i) => {\n          if (i.status === \"queued\" && active < concurrency) {\n            active++;\n            return { ...i, status: \"uploading\" as Status };\n          }\n          if (i.status !== \"uploading\") return i;\n          const uploaded = Math.min(i.size, i.uploaded + speedOf(i.id) * step * (reduce ? 4 : 1));\n          if (i.failAt && uploaded / i.size >= i.failAt) return { ...i, uploaded, status: \"failed\" as Status, error: \"Connection lost\", failAt: undefined };\n          return { ...i, uploaded, status: uploaded >= i.size ? (\"done\" as Status) : i.status };\n        });\n      });\n    }, step * 1000);\n    return () => clearInterval(id);\n  }, [busy, concurrency, reduce]);\n\n  const add = (files: File[]) => {\n    if (!files.length) return;\n    onFilesAdded?.(files);\n    setItems((list) => [...list, ...files.map((f) => ({ id: `f${++counter.current}-${f.name}`, name: f.name, size: Math.max(f.size, 40 * 1024), uploaded: 0, status: \"queued\" as Status }))]);\n    setFilter(\"all\");\n  };\n  const patch = (id: string, fn: (i: UploadItem) => UploadItem | null) => setItems((list) => list.flatMap((i) => (i.id === id ? (fn(i) ?? []) : [i])));\n\n  const total = items.reduce((s, i) => s + i.size, 0);\n  const done = items.filter((i) => i.status === \"done\");\n  const failed = items.filter((i) => i.status === \"failed\");\n  const active = items.filter((i) => i.status === \"uploading\" || i.status === \"queued\" || i.status === \"paused\");\n  const sent = items.reduce((s, i) => s + i.uploaded, 0);\n  const pct = total ? sent / total : 0;\n  const rate = items.filter((i) => i.status === \"uploading\").reduce((s, i) => s + speedOf(i.id), 0);\n  const remaining = active.reduce((s, i) => s + (i.size - i.uploaded), 0);\n  const shown = items.filter((i) => (filter === \"all\" ? true : filter === \"active\" ? active.includes(i) : filter === \"done\" ? i.status === \"done\" : i.status === \"failed\"));\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.panel } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const iconBtn = cn(\"grid h-7 w-7 shrink-0 cursor-pointer place-items-center rounded-md border-0 bg-transparent hover:bg-[var(--h)]\", focus);\n  const svg = (d: string, size = 14) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={d} />\n    </svg>\n  );\n  const headline = busy || items.some((i) => i.status === \"paused\") ? `Uploading ${active.length} ${active.length === 1 ? \"file\" : \"files\"}` : failed.length ? `${failed.length} upload${failed.length > 1 ? \"s\" : \"\"} failed` : `${done.length} ${done.length === 1 ? \"file\" : \"files\"} uploaded`;\n\n  return (\n    <section className={cn(\"@container relative min-h-[640px] w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-2xl px-4 py-10 @[640px]:px-6\">\n        {/* Drop zone */}\n        <div\n          onDragOver={(e) => {\n            e.preventDefault();\n            setDragging(true);\n          }}\n          onDragLeave={() => setDragging(false)}\n          onDrop={(e) => {\n            e.preventDefault();\n            setDragging(false);\n            add([...e.dataTransfer.files]);\n          }}\n          className=\"relative flex flex-col items-center gap-2 rounded-2xl border-2 border-dashed px-6 py-8 text-center transition-colors\"\n          style={{ borderColor: dragging ? p.accent : p.border, background: dragging ? p.drop : \"transparent\" }}\n        >\n          <motion.span className=\"grid h-11 w-11 place-items-center rounded-xl border\" style={{ borderColor: p.border, color: dragging ? p.accent : p.muted }} animate={dragging && !reduce ? { y: -4 } : { y: 0 }}>\n            {svg(\"M12 16V4m0 0-4 4m4-4 4 4M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3\", 18)}\n          </motion.span>\n          <p className=\"m-0 text-[14px] font-medium\">{dragging ? \"Drop to add to the queue\" : \"Drag files here\"}</p>\n          <p className=\"m-0 text-[12.5px]\" style={{ color: p.faint }}>\n            or{\" \"}\n            <button type=\"button\" onClick={() => inputRef.current?.click()} className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 text-[12.5px] font-medium underline underline-offset-2\", focus)} style={{ color: p.text, ...ring }}>\n              browse\n            </button>{\" \"}\n            · up to 2 GB per file\n          </p>\n          <input\n            ref={inputRef}\n            type=\"file\"\n            multiple\n            className=\"sr-only\"\n            tabIndex={-1}\n            aria-hidden=\"true\"\n            onChange={(e) => {\n              add([...(e.target.files ?? [])]);\n              e.target.value = \"\";\n            }}\n          />\n        </div>\n\n        {/* Queue panel */}\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {!minimized ? (\n            <motion.div key=\"panel\" layout={!reduce} initial={reduce ? false : { opacity: 0, y: 16, scale: 0.98 }} animate={{ opacity: 1, y: 0, scale: 1 }} exit={reduce ? undefined : { opacity: 0, y: 24, scale: 0.9 }} transition={{ type: \"spring\", stiffness: 420, damping: 36 }} className=\"mt-5 overflow-hidden rounded-2xl border\" style={{ background: p.panel, borderColor: p.border }} aria-labelledby={`${uid}-h`} role=\"region\">\n              <div className=\"px-4 pt-4 pb-3\">\n                <div className=\"flex items-center gap-2\">\n                  <h2 id={`${uid}-h`} className=\"m-0 flex-1 text-[14.5px] font-semibold\" aria-live=\"polite\">\n                    {headline}\n                  </h2>\n                  {done.length > 0 && (\n                    <button type=\"button\" onClick={() => setItems((l) => l.filter((i) => i.status !== \"done\"))} className={cn(\"h-7 cursor-pointer rounded-md border-0 bg-transparent px-2 text-[12px] hover:bg-[var(--h)]\", focus)} style={{ color: p.muted, [\"--h\" as string]: p.hover, ...ring }}>\n                      Clear done\n                    </button>\n                  )}\n                  <button type=\"button\" onClick={() => setMinimized(true)} aria-label=\"Minimize\" className={iconBtn} style={{ color: p.muted, [\"--h\" as string]: p.hover, ...ring }}>\n                    {svg(\"M5 12h14\")}\n                  </button>\n                </div>\n                <p className=\"m-0 mt-1 text-[12.5px] tabular-nums\" style={{ color: p.muted }}>\n                  {size(sent)} of {size(total)}\n                  {busy && rate > 0 ? ` · ${size(rate)}/s · ${eta(remaining / rate)}` : \"\"}\n                </p>\n                <div className=\"mt-3 h-1.5 overflow-hidden rounded-full\" style={{ background: p.track }} role=\"progressbar\" aria-label=\"Total upload progress\" aria-valuenow={Math.round(pct * 100)} aria-valuemin={0} aria-valuemax={100}>\n                  <motion.div className=\"h-full rounded-full\" style={{ background: failed.length && !busy ? p.amber : p.accent }} animate={{ width: `${pct * 100}%` }} transition={{ duration: 0.2, ease: \"linear\" }} />\n                </div>\n                <div role=\"tablist\" aria-label=\"Filter uploads\" className=\"mt-4 flex gap-1\">\n                  {(\n                    [\n                      [\"all\", \"All\", items.length],\n                      [\"active\", \"In progress\", active.length],\n                      [\"done\", \"Done\", done.length],\n                      [\"failed\", \"Failed\", failed.length],\n                    ] as const\n                  ).map(([k, label, n]) => (\n                    <button key={k} type=\"button\" role=\"tab\" aria-selected={filter === k} onClick={() => setFilter(k)} className={cn(\"relative h-7 cursor-pointer rounded-full border-0 bg-transparent px-2.5 text-[12px]\", focus)} style={{ color: filter === k ? p.onText : k === \"failed\" && n ? p.red : p.muted, ...ring }}>\n                      {filter === k && <motion.span layoutId={`${uid}-f`} className=\"absolute inset-0 rounded-full\" style={{ background: p.on }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 38 }} />}\n                      <span className=\"relative\">\n                        {label} <span className=\"tabular-nums opacity-70\">{n}</span>\n                      </span>\n                    </button>\n                  ))}\n                </div>\n              </div>\n              <ul className=\"m-0 max-h-[360px] list-none overflow-y-auto border-t p-0\" style={{ borderColor: p.border }}>\n                <AnimatePresence initial={false}>\n                  {shown.map((i) => {\n                    const k = KIND[kindOf(i.name)];\n                    const f = i.size ? i.uploaded / i.size : 0;\n                    const color = i.status === \"failed\" ? p.red : i.status === \"done\" ? p.green : i.status === \"paused\" ? p.amber : p.accent;\n                    return (\n                      <motion.li key={i.id} layout={!reduce} initial={reduce ? false : { opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={reduce ? undefined : { opacity: 0, height: 0 }} className=\"overflow-hidden border-b last:border-b-0\" style={{ borderColor: p.border }}>\n                        <div className=\"flex items-center gap-3 px-4 py-3\">\n                          <span className=\"grid h-9 w-9 shrink-0 place-items-center rounded-lg text-[9.5px] font-bold tracking-[0.04em]\" style={{ background: `${k.color}22`, color: k.color }}>\n                            {k.label}\n                          </span>\n                          <div className=\"min-w-0 flex-1\">\n                            <div className=\"flex items-baseline justify-between gap-3\">\n                              <span className=\"truncate text-[13px] font-medium\">{i.name}</span>\n                              <span className=\"shrink-0 text-[11.5px] tabular-nums\" style={{ color: i.status === \"failed\" ? p.red : p.faint }}>\n                                {i.status === \"done\" ? size(i.size) : i.status === \"failed\" ? i.error : i.status === \"queued\" ? \"Waiting\" : i.status === \"paused\" ? `Paused · ${Math.round(f * 100)}%` : `${Math.round(f * 100)}% · ${eta((i.size - i.uploaded) / speedOf(i.id))}`}\n                              </span>\n                            </div>\n                            <div className=\"mt-1.5 h-1 overflow-hidden rounded-full\" style={{ background: p.track }} role=\"progressbar\" aria-label={`${i.name} progress`} aria-valuenow={Math.round(f * 100)} aria-valuemin={0} aria-valuemax={100}>\n                              <motion.div className=\"h-full rounded-full\" style={{ background: color }} animate={{ width: `${f * 100}%` }} transition={{ duration: 0.2, ease: \"linear\" }} />\n                            </div>\n                          </div>\n                          <div className=\"flex shrink-0 items-center\" style={{ [\"--h\" as string]: p.hover } as React.CSSProperties}>\n                            {i.status === \"done\" ? (\n                              <motion.span initial={reduce ? false : { scale: 0.5 }} animate={{ scale: 1 }} className=\"grid h-7 w-7 place-items-center\" style={{ color: p.green }} aria-label=\"Uploaded\">\n                                {svg(\"m5 12.5 4.5 4.5L19 7.5\")}\n                              </motion.span>\n                            ) : i.status === \"failed\" ? (\n                              <button type=\"button\" onClick={() => patch(i.id, (x) => ({ ...x, status: \"queued\", error: undefined }))} aria-label={`Retry ${i.name}`} className={iconBtn} style={{ color: p.text, ...ring }}>\n                                {svg(\"M20 11a8 8 0 0 0-14.6-4.5L4 8m0-4v4h4M4 13a8 8 0 0 0 14.6 4.5L20 16m0 4v-4h-4\")}\n                              </button>\n                            ) : i.status === \"uploading\" || i.status === \"paused\" ? (\n                              <button type=\"button\" onClick={() => patch(i.id, (x) => ({ ...x, status: x.status === \"paused\" ? \"queued\" : \"paused\" }))} aria-label={`${i.status === \"paused\" ? \"Resume\" : \"Pause\"} ${i.name}`} className={iconBtn} style={{ color: p.text, ...ring }}>\n                                {svg(i.status === \"paused\" ? \"M8 5v14l11-7z\" : \"M8 5v14M16 5v14\")}\n                              </button>\n                            ) : null}\n                            {i.status !== \"done\" && (\n                              <button type=\"button\" onClick={() => patch(i.id, () => null)} aria-label={`Cancel ${i.name}`} className={iconBtn} style={{ color: p.faint, ...ring }}>\n                                {svg(\"M6 6l12 12M18 6 6 18\")}\n                              </button>\n                            )}\n                          </div>\n                        </div>\n                      </motion.li>\n                    );\n                  })}\n                </AnimatePresence>\n                {!shown.length && (\n                  <li className=\"px-4 py-10 text-center text-[12.5px]\" style={{ color: p.faint }}>\n                    {filter === \"failed\" ? \"No failed uploads.\" : filter === \"active\" ? \"Nothing uploading right now.\" : \"No files yet. Drop some above.\"}\n                  </li>\n                )}\n              </ul>\n              {failed.length > 1 && (\n                <div className=\"flex justify-end border-t px-4 py-2.5\" style={{ borderColor: p.border }}>\n                  <button type=\"button\" onClick={() => setItems((l) => l.map((i) => (i.status === \"failed\" ? { ...i, status: \"queued\", error: undefined } : i)))} className={cn(\"h-7 cursor-pointer rounded-md border-0 px-2.5 text-[12px] font-medium\", focus)} style={{ background: p.on, color: p.onText, ...ring }}>\n                    Retry all\n                  </button>\n                </div>\n              )}\n            </motion.div>\n          ) : (\n            <motion.button\n              key=\"pill\"\n              type=\"button\"\n              layout={!reduce}\n              onClick={() => setMinimized(false)}\n              initial={reduce ? false : { opacity: 0, scale: 0.8, y: 16 }}\n              animate={{ opacity: 1, scale: 1, y: 0 }}\n              exit={reduce ? undefined : { opacity: 0, scale: 0.8 }}\n              transition={{ type: \"spring\", stiffness: 420, damping: 30 }}\n              className={cn(\"absolute right-4 bottom-4 flex cursor-pointer items-center gap-2.5 rounded-full border py-1.5 pr-4 pl-1.5 text-[12.5px] font-medium shadow-[0_12px_32px_-12px_rgba(0,0,0,0.5)] @[640px]:right-6 @[640px]:bottom-6\", focus)}\n              style={{ background: p.panel, borderColor: p.border, color: p.text, ...ring }}\n              aria-label={`${headline}, ${Math.round(pct * 100)}%. Expand`}\n            >\n              <span className=\"relative grid h-8 w-8 place-items-center\">\n                <svg width=\"32\" height=\"32\" viewBox=\"0 0 36 36\" className=\"absolute inset-0\" aria-hidden=\"true\">\n                  <circle cx=\"18\" cy=\"18\" r=\"15\" fill=\"none\" stroke={p.track} strokeWidth=\"3\" />\n                  <circle cx=\"18\" cy=\"18\" r=\"15\" fill=\"none\" stroke={failed.length && !busy ? p.amber : busy ? p.accent : p.green} strokeWidth=\"3\" strokeLinecap=\"round\" strokeDasharray={94.2} strokeDashoffset={94.2 * (1 - pct)} transform=\"rotate(-90 18 18)\" style={{ transition: \"stroke-dashoffset 200ms linear\" }} />\n                </svg>\n                <span className=\"text-[9.5px] font-semibold tabular-nums\">{Math.round(pct * 100)}</span>\n              </span>\n              {headline}\n            </motion.button>\n          )}\n        </AnimatePresence>\n      </div>\n    </section>\n  );\n}\n\nexport default UploadQueuePanel;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}