{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dropbox-upload",
  "type": "registry:block",
  "title": "Dropbox Upload",
  "files": [
    {
      "path": "components/uui/dropbox-upload/dropbox-upload.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { motion, AnimatePresence } from 'motion/react';\nimport { Upload, CheckCircle2, ChevronDown, ChevronUp, RefreshCw, AlertCircle } from 'lucide-react';\n\ninterface UploadItem {\n  id: string;\n  file: File;\n  progress: number;\n  status: 'uploading' | 'complete' | 'error';\n}\n\nexport interface DropboxUploadProps {\n  className?: string;\n  onUploadStart?: (files: File[]) => void;\n  onUploadComplete?: (file: File) => void;\n  simulateDelay?: number;\n  maxFiles?: number;\n}\n\nexport function DropboxUpload({\n  className,\n  onUploadStart,\n  onUploadComplete,\n  simulateDelay = 300,\n  maxFiles,\n}: DropboxUploadProps) {\n  const [uploads, setUploads] = React.useState<UploadItem[]>([]);\n  const [isDragOver, setIsDragOver] = React.useState(false);\n  const [isPanelOpen, setIsPanelOpen] = React.useState(false);\n  const [isMinimized, setIsMinimized] = React.useState(false);\n  const [filter, setFilter] = React.useState<'all' | 'completed' | 'skipped' | 'failed'>('all');\n\n  const dragCounter = React.useRef(0);\n  const cancelFns = React.useRef<Map<string, () => void>>(new Map());\n  const fileInputRef = React.useRef<HTMLInputElement>(null);\n\n  const addUpload = React.useCallback(\n    (files: FileList | File[]) => {\n      const fileArray = Array.from(files);\n      let items = fileArray.map(\n        (file): UploadItem => ({\n          id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,\n          file,\n          progress: 0,\n          status: 'uploading',\n        }),\n      );\n\n      if (maxFiles) {\n        items = items.slice(0, maxFiles);\n      }\n\n      setUploads((prev) => [...prev, ...items]);\n      setIsPanelOpen(true);\n      setIsMinimized(false); // Auto-expand when new uploads start\n      onUploadStart?.(items.map((i) => i.file));\n\n      for (const item of items) {\n        let progress = 0;\n        const interval = setInterval(() => {\n          const increment = Math.random() * 15 + 5;\n          progress = Math.min(100, progress + increment);\n          const p = Math.round(progress);\n          setUploads((prev) => prev.map((u) => (u.id === item.id ? { ...u, progress: p } : u)));\n          if (progress >= 100) {\n            clearInterval(interval);\n            cancelFns.current.delete(item.id);\n            setUploads((prev) => prev.map((u) => (u.id === item.id ? { ...u, status: 'complete' } : u)));\n            onUploadComplete?.(item.file);\n          }\n        }, simulateDelay);\n        cancelFns.current.set(item.id, () => clearInterval(interval));\n      }\n    },\n    [maxFiles, onUploadStart, onUploadComplete, simulateDelay],\n  );\n\n  const removeUpload = React.useCallback((id: string) => {\n    cancelFns.current.get(id)?.();\n    cancelFns.current.delete(id);\n    setUploads((prev) => prev.filter((u) => u.id !== id));\n  }, []);\n\n  const cancelAll = React.useCallback(() => {\n    uploads.forEach((u) => {\n      if (u.status === 'uploading') {\n        cancelFns.current.get(u.id)?.();\n        cancelFns.current.delete(u.id);\n      }\n    });\n    setUploads([]);\n    setIsPanelOpen(false);\n  }, [uploads]);\n\n  const clearAll = React.useCallback(() => {\n    setUploads([]);\n    setIsPanelOpen(false);\n  }, []);\n\n  const handleDragEnter = React.useCallback((e: React.DragEvent) => {\n    e.preventDefault();\n    e.stopPropagation();\n    dragCounter.current++;\n    if (e.dataTransfer.items && e.dataTransfer.items.length > 0) {\n      setIsDragOver(true);\n    }\n  }, []);\n\n  const handleDragLeave = React.useCallback((e: React.DragEvent) => {\n    e.preventDefault();\n    e.stopPropagation();\n    dragCounter.current--;\n    if (dragCounter.current === 0) {\n      setIsDragOver(false);\n    }\n  }, []);\n\n  const handleDrop = React.useCallback(\n    (e: React.DragEvent) => {\n      e.preventDefault();\n      e.stopPropagation();\n      setIsDragOver(false);\n      dragCounter.current = 0;\n      if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {\n        addUpload(e.dataTransfer.files);\n      }\n    },\n    [addUpload],\n  );\n\n  // Filtered uploads logic\n  const filteredUploads = React.useMemo(() => {\n    return uploads.filter((u) => {\n      if (filter === 'all') return true;\n      if (filter === 'completed') return u.status === 'complete';\n      if (filter === 'failed') return u.status === 'error';\n      return false; // 'skipped' or fallback\n    });\n  }, [uploads, filter]);\n\n  // Statistics for the blue footer bar\n  const uploadingItems = React.useMemo(() => uploads.filter((u) => u.status === 'uploading'), [uploads]);\n  const uploadingCount = uploadingItems.length;\n\n  const secondsLeft = React.useMemo(() => {\n    if (uploadingCount === 0) return 0;\n    const avgProgress = uploadingItems.reduce((acc, curr) => acc + curr.progress, 0) / uploadingCount;\n    const pctRemaining = 100 - avgProgress;\n    // Each step is simulateDelay (ms) and averages ~10% progress increment\n    const stepsLeft = pctRemaining / 10;\n    return Math.max(1, Math.round((stepsLeft * simulateDelay) / 1000));\n  }, [uploadingItems, uploadingCount, simulateDelay]);\n\n  return (\n    <div\n      className={`relative h-svh w-full flex flex-col items-center justify-center bg-[#0a0a0a] ${className ?? ''}`}\n      onDragEnter={handleDragEnter}\n      onDragLeave={handleDragLeave}\n      onDragOver={(e) => {\n        e.preventDefault();\n        e.stopPropagation();\n      }}\n      onDrop={handleDrop}\n    >\n      {/* Hidden File Input */}\n      <input\n        type=\"file\"\n        ref={fileInputRef}\n        onChange={(e) => {\n          if (e.target.files && e.target.files.length > 0) {\n            addUpload(e.target.files);\n          }\n        }}\n        multiple\n        className=\"hidden\"\n      />\n\n      {/* Main Drop Zone */}\n      <div\n        onClick={() => fileInputRef.current?.click()}\n        className={`\n          relative flex flex-col items-center justify-center gap-4\n          w-full max-w-lg h-64 rounded-2xl border-2 border-dashed\n          transition-all duration-300 cursor-pointer select-none\n          ${isDragOver\n            ? 'border-blue-500 bg-blue-500/5 scale-[1.02] shadow-[0_0_20px_rgba(59,130,246,0.15)]'\n            : 'border-zinc-800 hover:border-zinc-700 hover:bg-zinc-900/50'\n          }\n        `}\n      >\n        <motion.div\n          animate={isDragOver ? { scale: 1.1, y: -4 } : { scale: 1, y: 0 }}\n          transition={{ type: 'spring', bounce: 0, duration: 0.3 }}\n        >\n          <Upload className={`size-12 ${isDragOver ? 'text-blue-500' : 'text-zinc-500'}`} />\n        </motion.div>\n        <div className=\"text-center\">\n          <p className={`text-sm font-semibold ${isDragOver ? 'text-blue-500' : 'text-zinc-300'}`}>\n            {isDragOver ? 'Drop files here' : 'Drag & drop files here'}\n          </p>\n          <p className=\"text-xs text-zinc-500 mt-1\">or click to browse</p>\n        </div>\n      </div>\n\n      {/* Uploads Panel (Popper) */}\n      <AnimatePresence>\n        {isPanelOpen && uploads.length > 0 && (\n          <motion.div\n            initial={{ opacity: 0, y: 20, scale: 0.95 }}\n            animate={{ opacity: 1, y: 0, scale: 1 }}\n            exit={{ opacity: 0, y: 20, scale: 0.95 }}\n            transition={{ type: 'spring', bounce: 0, duration: 0.3 }}\n            className=\"fixed bottom-4 right-4 z-50 w-96 bg-[#141414] text-[#f5f5f5] rounded-2xl shadow-[0_12px_40px_rgba(0,0,0,0.6)] border border-zinc-800/80 overflow-hidden flex flex-col font-sans\"\n          >\n            {!isMinimized && (\n              <>\n                {/* Header */}\n                <div className=\"flex items-center justify-between px-4 pt-4 pb-2\">\n                  <span className=\"text-base font-bold text-white\">Uploads</span>\n                  <div className=\"flex items-center gap-2\">\n                    <button\n                      onClick={uploadingCount > 0 ? cancelAll : clearAll}\n                      className=\"text-xs font-semibold px-3 py-1.5 rounded-full border border-zinc-800 hover:border-zinc-700 text-zinc-200 hover:text-white transition-colors bg-transparent cursor-pointer\"\n                    >\n                      {uploadingCount > 0 ? 'Cancel all' : 'Clear all'}\n                    </button>\n                    <button\n                      onClick={() => setIsMinimized(true)}\n                      className=\"text-zinc-400 hover:text-white p-1 hover:bg-zinc-800/50 rounded-full transition-colors cursor-pointer\"\n                      title=\"Minimize\"\n                    >\n                      <ChevronDown className=\"size-4.5\" />\n                    </button>\n                  </div>\n                </div>\n\n                {/* Filter Pills */}\n                <div className=\"flex gap-1.5 px-4 py-2 flex-wrap\">\n                  {(['all', 'completed', 'skipped', 'failed'] as const).map((tab) => {\n                    const label = {\n                      all: 'All uploads',\n                      completed: 'Completed',\n                      skipped: 'Skipped',\n                      failed: 'Failed',\n                    }[tab];\n\n                    const isActive = filter === tab;\n\n                    return (\n                      <button\n                        key={tab}\n                        onClick={() => setFilter(tab)}\n                        className={`text-xs px-3 py-1 rounded-full border transition-all cursor-pointer ${\n                          isActive\n                            ? 'border-white text-white font-semibold bg-transparent'\n                            : 'border-transparent bg-[#242424] text-zinc-400 hover:bg-[#2e2e2e] hover:text-zinc-200'\n                        }`}\n                      >\n                        {label}\n                      </button>\n                    );\n                  })}\n                </div>\n\n                {/* Upload Destination Link */}\n                <div className=\"px-4 py-1.5 text-xs text-zinc-400 font-medium\">\n                  Uploading to{' '}\n                  <span className=\"underline font-bold text-white cursor-pointer hover:text-blue-400 transition-colors\">\n                    Design Spells\n                  </span>\n                </div>\n\n                {/* Items List */}\n                <div className=\"max-h-72 overflow-y-auto mt-2 border-t border-zinc-900/60 divide-y divide-zinc-900/40\">\n                  {filteredUploads.length === 0 ? (\n                    <div className=\"flex flex-col items-center justify-center py-10 text-zinc-500 text-xs\">\n                      No uploads in this filter\n                    </div>\n                  ) : (\n                    filteredUploads.map((item) => {\n                      const extension = item.file.name.split('.').pop()?.toUpperCase() || 'FILE';\n                      const nameWithoutExtension =\n                        item.file.name.substring(0, item.file.name.lastIndexOf('.')) || item.file.name;\n\n                      return (\n                        <div\n                          key={item.id}\n                          className=\"relative flex flex-col pt-3.5 pb-4.5 group\"\n                        >\n                          <div className=\"flex items-start justify-between px-4 gap-3\">\n                            <div className=\"flex items-start gap-3 min-w-0 flex-1\">\n                              <div className=\"mt-0.5 shrink-0\">\n                                {item.status === 'complete' ? (\n                                  <CheckCircle2 className=\"size-4.5 text-emerald-500 fill-emerald-500/10\" />\n                                ) : item.status === 'error' ? (\n                                  <AlertCircle className=\"size-4.5 text-rose-500\" />\n                                ) : (\n                                  <motion.div\n                                    animate={{ rotate: 360 }}\n                                    transition={{ repeat: Infinity, duration: 1.8, ease: 'linear' }}\n                                    className=\"inline-block\"\n                                  >\n                                    <RefreshCw className=\"size-4.5 text-zinc-400\" />\n                                  </motion.div>\n                                )}\n                              </div>\n                              <div className=\"min-w-0 flex-1\">\n                                <span className=\"text-xs font-semibold text-white truncate block\">\n                                  {nameWithoutExtension}\n                                </span>\n                                <div className=\"flex items-center gap-1.5 mt-1\">\n                                  <span className=\"bg-[#242424] text-zinc-400 text-[10px] font-bold px-1.5 py-0.5 rounded leading-none\">\n                                    {extension}\n                                  </span>\n                                  <span className=\"text-[11px] text-zinc-400\">\n                                    {item.status === 'complete'\n                                      ? 'Complete'\n                                      : item.status === 'error'\n                                      ? 'Failed'\n                                      : item.progress > 90\n                                      ? 'Finalizing...'\n                                      : `${item.progress}%`}\n                                  </span>\n                                </div>\n                              </div>\n                            </div>\n\n                            {item.status === 'uploading' && (\n                              <button\n                                onClick={() => removeUpload(item.id)}\n                                className=\"text-zinc-400 hover:text-white bg-[#242424] hover:bg-[#2e2e2e] transition-colors shrink-0 text-xs px-3 py-1 rounded-full font-semibold cursor-pointer\"\n                              >\n                                Cancel\n                              </button>\n                            )}\n                          </div>\n\n                          {/* Item Progress Bar */}\n                          {item.status === 'uploading' && (\n                            <div className=\"absolute bottom-0 left-0 right-0 h-0.5 bg-zinc-900 overflow-hidden\">\n                              <motion.div\n                                className=\"h-full bg-[#0061FE]\"\n                                initial={{ width: 0 }}\n                                animate={{ width: `${item.progress}%` }}\n                                transition={{ type: 'spring', bounce: 0, duration: 0.3 }}\n                              />\n                            </div>\n                          )}\n                        </div>\n                      );\n                    })\n                  )}\n                </div>\n              </>\n            )}\n\n            {/* Blue Status Footer */}\n            <div\n              className={`bg-[#0061FE] text-white px-4 py-3 flex items-center justify-between transition-all select-none ${\n                isMinimized ? 'cursor-pointer hover:bg-[#0057e6]' : ''\n              }`}\n              onClick={() => {\n                if (isMinimized) {\n                  setIsMinimized(false);\n                }\n              }}\n            >\n              <div className=\"flex items-center gap-3\">\n                <div className=\"bg-[#0052d9] p-1.5 rounded-lg shrink-0\">\n                  {uploadingCount > 0 ? (\n                    <motion.div\n                      animate={{ rotate: 360 }}\n                      transition={{ repeat: Infinity, duration: 2, ease: 'linear' }}\n                      className=\"inline-block\"\n                    >\n                      <RefreshCw className=\"size-4 text-white\" />\n                    </motion.div>\n                  ) : (\n                    <Upload className=\"size-4 text-white\" />\n                  )}\n                </div>\n                <div>\n                  <p className=\"text-xs font-semibold\">\n                    {uploadingCount > 0\n                      ? `Uploading ${uploadingCount} item${uploadingCount > 1 ? 's' : ''}`\n                      : `${uploads.length} item${uploads.length > 1 ? 's' : ''} uploaded`}\n                  </p>\n                  <p className=\"text-[10px] text-blue-200\">\n                    {uploadingCount > 0 ? `${secondsLeft} second${secondsLeft !== 1 ? 's' : ''} left` : 'Finished'}\n                  </p>\n                </div>\n              </div>\n\n              <div className=\"flex items-center gap-2\" onClick={(e) => e.stopPropagation()}>\n                <button\n                  onClick={() => fileInputRef.current?.click()}\n                  className=\"bg-transparent hover:bg-white/10 text-white border border-white/20 hover:border-white/40 text-xs px-3 py-1.5 rounded-full font-semibold flex items-center gap-1 transition-all cursor-pointer\"\n                >\n                  Add <ChevronDown className=\"size-3\" />\n                </button>\n                {isMinimized && (\n                  <button\n                    onClick={() => setIsMinimized(false)}\n                    className=\"text-white/80 hover:text-white p-1 hover:bg-white/10 rounded-full transition-colors cursor-pointer\"\n                    title=\"Expand\"\n                  >\n                    <ChevronUp className=\"size-4\" />\n                  </button>\n                )}\n              </div>\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\n",
      "type": "registry:block",
      "target": "@components/uui/dropbox-upload/dropbox-upload.tsx"
    },
    {
      "path": "components/uui/dropbox-upload/example.tsx",
      "content": "'use client';\n\nimport { DropboxUpload } from './dropbox-upload';\n\nexport function DropboxUploadExample() {\n  return <DropboxUpload />;\n}\n\nexport { DropboxUpload } from './dropbox-upload';\n",
      "type": "registry:block",
      "target": "@components/uui/dropbox-upload/example.tsx"
    }
  ],
  "dependencies": [
    "motion"
  ]
}