{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-upload-3",
  "dependencies": [
    "lucide-react",
    "react-icons"
  ],
  "registryDependencies": [
    "button",
    "card",
    "utils"
  ],
  "files": [
    {
      "path": "src/components/watermelon-ui/file-upload-3.tsx",
      "content": "\"use client\";\n\nimport React, { useRef, useState, useCallback } from \"react\";\nimport {\n  FaCloudUploadAlt,\n  FaFileAlt,\n  FaFileImage,\n  FaFilePdf,\n  FaFileVideo,\n  FaFileArchive,\n  FaTrashAlt,\n  FaCheckCircle,\n  FaExclamationCircle,\n  FaFileCode,\n} from \"react-icons/fa\";\nimport {\n  Card,\n  CardContent,\n  CardHeader,\n  CardTitle,\n  CardDescription,\n} from \"@/components/ui/card\";\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/utils\";\n\nexport type FileState = \"queued\" | \"uploading\" | \"completed\" | \"failed\";\n\nexport interface FileEntry {\n  id: string;\n  file: File;\n  progress: number;\n  state: FileState;\n  error?: string;\n}\n\nexport interface FileUploadAreaProps extends Omit<\n  React.HTMLAttributes<HTMLDivElement>,\n  \"onDrop\"\n> {\n  title?: string;\n  description?: string;\n  maxFiles?: number;\n  maxSizeMB?: number;\n  accept?: string;\n  files: FileEntry[];\n  onFilesSelect: (files: File[]) => void;\n  onFileRemove: (id: string) => void;\n}\n\nfunction formatBytes(bytes: number): string {\n  if (bytes === 0) return \"0 Bytes\";\n  const k = 1024;\n  const sizes = [\"Bytes\", \"KB\", \"MB\", \"GB\"];\n  const i = Math.floor(Math.log(bytes) / Math.log(k));\n  return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + \" \" + sizes[i];\n}\n\nfunction FileIcon({ type, name }: { type: string; name: string }) {\n  const ext = name.split(\".\").pop()?.toLowerCase() || \"\";\n\n  if (type.startsWith(\"image/\")) return <FaFileImage className=\"h-5 w-5\" />;\n  if (type.startsWith(\"video/\")) return <FaFileVideo className=\"h-5 w-5\" />;\n  if (type === \"application/pdf\" || ext === \"pdf\")\n    return <FaFilePdf className=\"h-5 w-5\" />;\n  if ([\"zip\", \"rar\", \"tar\", \"gz\", \"7z\"].includes(ext))\n    return <FaFileArchive className=\"h-5 w-5\" />;\n  if ([\"js\", \"ts\", \"jsx\", \"tsx\", \"py\", \"json\", \"html\", \"css\"].includes(ext))\n    return <FaFileCode className=\"h-5 w-5\" />;\n  return <FaFileAlt className=\"h-5 w-5\" />;\n}\n\nfunction CircularProgress({ progress }: { progress: number }) {\n  const radius = 14;\n  const circumference = 2 * Math.PI * radius;\n  const strokeDashoffset = circumference - (progress / 100) * circumference;\n\n  return (\n    <div className=\"relative inline-flex items-center justify-center\">\n      <svg className=\"h-8 w-8 -rotate-90 transform\">\n        <circle\n          className=\"text-muted\"\n          strokeWidth=\"3\"\n          stroke=\"currentColor\"\n          fill=\"transparent\"\n          r={radius}\n          cx=\"16\"\n          cy=\"16\"\n        />\n        <circle\n          className=\"text-primary transition-all duration-300 ease-in-out\"\n          strokeWidth=\"3\"\n          strokeDasharray={circumference}\n          strokeDashoffset={strokeDashoffset}\n          strokeLinecap=\"round\"\n          stroke=\"currentColor\"\n          fill=\"transparent\"\n          r={radius}\n          cx=\"16\"\n          cy=\"16\"\n        />\n      </svg>\n      <div className=\"text-muted-foreground absolute flex items-center justify-center text-[8px] font-bold tabular-nums\">\n        {Math.round(progress)}\n      </div>\n    </div>\n  );\n}\n\nexport function FileUploadArea({\n  title = \"Media Library\",\n  description = \"Upload and manage your project files.\",\n  maxFiles = 5,\n  maxSizeMB = 10,\n  accept,\n  files,\n  onFilesSelect,\n  onFileRemove,\n  className,\n  ...props\n}: FileUploadAreaProps) {\n  const [isDragging, setIsDragging] = useState(false);\n  const fileInputRef = useRef<HTMLInputElement>(null);\n\n  const handleDragOver = useCallback((e: React.DragEvent<HTMLDivElement>) => {\n    e.preventDefault();\n    e.stopPropagation();\n    setIsDragging(true);\n  }, []);\n\n  const handleDragLeave = useCallback((e: React.DragEvent<HTMLDivElement>) => {\n    e.preventDefault();\n    e.stopPropagation();\n    setIsDragging(false);\n  }, []);\n\n  const handleDrop = useCallback(\n    (e: React.DragEvent<HTMLDivElement>) => {\n      e.preventDefault();\n      e.stopPropagation();\n      setIsDragging(false);\n\n      if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {\n        onFilesSelect(Array.from(e.dataTransfer.files));\n      }\n    },\n    [onFilesSelect],\n  );\n\n  const handleFileSelect = useCallback(\n    (e: React.ChangeEvent<HTMLInputElement>) => {\n      if (e.target.files && e.target.files.length > 0) {\n        onFilesSelect(Array.from(e.target.files));\n      }\n      if (fileInputRef.current) {\n        fileInputRef.current.value = \"\";\n      }\n    },\n    [onFilesSelect],\n  );\n\n  return (\n    <Card\n      className={cn(\"mx-auto my-auto w-full max-w-lg rounded-none\", className)}\n      {...props}\n    >\n      <CardHeader className=\"border-border bg-muted rounded-none border-b pt-2\">\n        <CardTitle className=\"text-md text-foreground font-medium tracking-tight\">\n          {title}\n        </CardTitle>\n        <CardDescription className=\"text-muted-foreground text-xs\">\n          {description}\n        </CardDescription>\n      </CardHeader>\n      <CardContent className=\"space-y-5\">\n        <div\n          className={cn(\n            \"focus-visible:ring-ring relative flex cursor-pointer flex-col items-center justify-between gap-4 rounded-none border-2 border-dashed p-6 transition-all duration-300 outline-none focus-visible:ring-2 sm:flex-row\",\n            isDragging\n              ? \"border-primary bg-primary/5\"\n              : \"border-border hover:border-primary/40 bg-muted/10 hover:bg-muted/30\",\n          )}\n          onDragOver={handleDragOver}\n          onDragLeave={handleDragLeave}\n          onDrop={handleDrop}\n          onClick={() => fileInputRef.current?.click()}\n          role=\"button\"\n          tabIndex={0}\n          onKeyDown={(e) => {\n            if (e.key === \"Enter\" || e.key === \" \") {\n              fileInputRef.current?.click();\n            }\n          }}\n        >\n          <input\n            type=\"file\"\n            ref={fileInputRef}\n            className=\"hidden\"\n            multiple={maxFiles > 1}\n            accept={accept}\n            onChange={handleFileSelect}\n            aria-hidden=\"true\"\n          />\n          <div className=\"flex flex-col items-center gap-5 text-center sm:flex-row sm:text-left\">\n            <div\n              className={cn(\n                \"rounded p-4 transition-colors duration-300\",\n                isDragging\n                  ? \"bg-primary/20 text-primary\"\n                  : \"bg-background text-muted-foreground group-hover:text-primary border shadow-xs\",\n              )}\n            >\n              <FaCloudUploadAlt className=\"h-6 w-6\" />\n            </div>\n            <div>\n              <p className=\"text-foreground text-base font-medium\">\n                Drop files here or click to browse\n              </p>\n              <p className=\"text-muted-foreground mt-1 text-sm\">\n                Up to {maxFiles} files, {maxSizeMB}MB each\n              </p>\n            </div>\n          </div>\n          <Button\n            type=\"button\"\n            variant=\"default\"\n            className=\"pointer-events-none shrink-0 shadow-[0px_0px_4px_1px_rgba(0,0,0,0.05),inset_0_0px_4px_1px_rgba(255,255,255,0.45),inset_0_1px_0px_0px_rgba(255,255,255,0.35)]\"\n          >\n            Select Files\n          </Button>\n        </div>\n\n        {files.length > 0 && (\n          <div className=\"space-y-2\">\n            {files.map((f) => (\n              <div\n                key={f.id}\n                className=\"text-card-foreground flex items-center gap-4 p-2 transition-all\"\n              >\n                <div\n                  className={cn(\n                    \"flex h-12 w-12 shrink-0 items-center justify-center rounded-none\",\n                    f.state === \"failed\"\n                      ? \"bg-destructive/10 text-destructive\"\n                      : f.state === \"completed\"\n                        ? \"bg-primary/10 text-primary\"\n                        : \"bg-muted text-muted-foreground\",\n                  )}\n                >\n                  <FileIcon type={f.file.type} name={f.file.name} />\n                </div>\n\n                <div className=\"min-w-0 flex-1\">\n                  <p className=\"text-foreground truncate text-sm font-semibold\">\n                    {f.file.name}\n                  </p>\n                  <div className=\"mt-0.5 flex items-center gap-2 text-xs\">\n                    <span className=\"text-muted-foreground font-medium\">\n                      {formatBytes(f.file.size)}\n                    </span>\n                    {f.error && (\n                      <>\n                        <span className=\"text-muted-foreground\">•</span>\n                        <span className=\"text-destructive truncate font-medium\">\n                          {f.error}\n                        </span>\n                      </>\n                    )}\n                  </div>\n                </div>\n\n                <div className=\"flex shrink-0 items-center gap-1\">\n                  {f.state === \"uploading\" && (\n                    <CircularProgress progress={f.progress} />\n                  )}\n                  {f.state === \"completed\" && (\n                    <FaCheckCircle className=\"text-primary size-6\" />\n                  )}\n                  {f.state === \"failed\" && (\n                    <FaExclamationCircle className=\"text-destructive h-6 w-6\" />\n                  )}\n\n                  <div className=\"bg-border ml-2 h-6 w-px\" />\n\n                  <Button\n                    type=\"button\"\n                    variant=\"ghost\"\n                    size=\"icon\"\n                    onClick={(e) => {\n                      e.stopPropagation();\n                      onFileRemove(f.id);\n                    }}\n                    className=\"text-muted-foreground hover:text-destructive hover:bg-destructive/10\"\n                    aria-label={`Remove ${f.file.name}`}\n                  >\n                    <FaTrashAlt className=\"h-4 w-4\" />\n                  </Button>\n                </div>\n              </div>\n            ))}\n          </div>\n        )}\n      </CardContent>\n    </Card>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/file-upload-3.tsx"
    }
  ],
  "type": "registry:ui"
}
