{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-upload-1",
  "dependencies": [
    "lucide-react",
    "react-icons"
  ],
  "registryDependencies": [
    "badge",
    "button",
    "card",
    "progress"
  ],
  "files": [
    {
      "path": "src/components/watermelon-ui/file-upload-1.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport {\n  Card,\n  CardContent,\n  CardFooter,\n  CardHeader,\n} from \"@/components/ui/card\";\nimport { Button } from \"@/components/ui/button\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Progress } from \"@/components/ui/progress\";\nimport {\n  FaFilePdf,\n  FaFileImage,\n  FaFileVideo,\n  FaFileAlt,\n  FaFileCode,\n  FaCloudUploadAlt,\n  FaTimes,\n  FaCheckCircle,\n  FaExclamationCircle,\n  FaShieldAlt,\n  FaArrowRight,\n} from \"react-icons/fa\";\n\nexport type FileStatus = \"queued\" | \"uploading\" | \"done\" | \"error\";\n\nexport interface UploadedFile {\n  id: string;\n  file: File;\n  progress: number;\n  status: FileStatus;\n}\n\nexport interface FileUploaderProps {\n  /** Card heading */\n  title?: string;\n  /** Card sub-heading */\n  description?: string;\n  /** Maximum number of files allowed */\n  maxFiles?: number;\n  /** Maximum individual file size in MB */\n  maxSizeMB?: number;\n  /** Human-readable label for accepted formats */\n  acceptedLabel?: string;\n  /** Submit button label */\n  submitLabel?: string;\n  /** Cancel / discard button label */\n  cancelLabel?: string;\n  /** Fired when the user clicks submit (receives only \"done\" files) */\n  onSubmit?: (files: File[]) => void;\n  /** Fired when the user clicks cancel */\n  onCancel?: () => void;\n}\n\nfunction generateId(): string {\n  return Math.random().toString(36).slice(2, 9);\n}\n\nfunction formatBytes(bytes: number): string {\n  if (bytes === 0) return \"0 B\";\n  const k = 1024;\n  const sizes = [\"B\", \"KB\", \"MB\", \"GB\"] as const;\n  const i = Math.floor(Math.log(bytes) / Math.log(k));\n  return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;\n}\n\nfunction FileIcon({ file }: { file: File }): React.ReactElement {\n  const type = file.type;\n  const ext = file.name.split(\".\").pop()?.toLowerCase() ?? \"\";\n\n  if (type.startsWith(\"image/\")) return <FaFileImage className=\"size-4\" />;\n  if (type.startsWith(\"video/\")) return <FaFileVideo className=\"size-4\" />;\n  if (type === \"application/pdf\" || ext === \"pdf\")\n    return <FaFilePdf className=\"size-4\" />;\n  if (\n    [\"js\", \"ts\", \"tsx\", \"jsx\", \"py\", \"go\", \"json\", \"yaml\", \"yml\"].includes(ext)\n  )\n    return <FaFileCode className=\"size-4\" />;\n  return <FaFileAlt className=\"size-4\" />;\n}\n\nexport function FileUploader({\n  title = \"Submit Your Report\",\n  description = \"Attach supporting documents to complete your submission.\",\n  maxFiles = 6,\n  maxSizeMB = 25,\n  acceptedLabel = \"PDF, DOCX, XLSX, CSV · up to 25 MB each\",\n  submitLabel = \"Submit Report\",\n  cancelLabel = \"Discard\",\n  onSubmit,\n  onCancel,\n}: FileUploaderProps) {\n  const [files, setFiles] = React.useState<UploadedFile[]>([]);\n  const [isDragging, setIsDragging] = React.useState(false);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const dragCounter = React.useRef(0);\n\n  const totalSize = files.reduce((acc, f) => acc + f.file.size, 0);\n  const allDone = files.length > 0 && files.every((f) => f.status === \"done\");\n  const hasUploading = files.some(\n    (f) => f.status === \"uploading\" || f.status === \"queued\",\n  );\n  const isAtLimit = files.length >= maxFiles;\n\n  function simulateUpload(id: string): void {\n    let progress = 0;\n\n    setFiles((prev) =>\n      prev.map((f) => (f.id === id ? { ...f, status: \"uploading\" } : f)),\n    );\n\n    const interval = setInterval(() => {\n      progress += Math.random() * 18 + 4;\n\n      if (progress >= 100) {\n        clearInterval(interval);\n        setFiles((prev) =>\n          prev.map((f) =>\n            f.id === id ? { ...f, progress: 100, status: \"done\" } : f,\n          ),\n        );\n      } else {\n        setFiles((prev) =>\n          prev.map((f) =>\n            f.id === id ? { ...f, progress: Math.min(progress, 99) } : f,\n          ),\n        );\n      }\n    }, 180);\n  }\n\n  function addFiles(incoming: FileList | File[]): void {\n    const fileArray = Array.from(incoming);\n    const remaining = maxFiles - files.length;\n\n    const toAdd: UploadedFile[] = fileArray\n      .filter((f) => f.size <= maxSizeMB * 1024 * 1024)\n      .slice(0, remaining)\n      .map((file) => ({\n        id: generateId(),\n        file,\n        progress: 0,\n        status: \"queued\",\n      }));\n\n    setFiles((prev) => [...prev, ...toAdd]);\n    toAdd.forEach((f) => {\n      setTimeout(() => simulateUpload(f.id), 80);\n    });\n  }\n\n  function removeFile(id: string): void {\n    setFiles((prev) => prev.filter((f) => f.id !== id));\n  }\n\n  function clearAll(): void {\n    setFiles([]);\n    if (inputRef.current) inputRef.current.value = \"\";\n  }\n\n  function handleDragEnter(e: React.DragEvent): void {\n    e.preventDefault();\n    dragCounter.current += 1;\n    setIsDragging(true);\n  }\n\n  function handleDragLeave(e: React.DragEvent): void {\n    e.preventDefault();\n    dragCounter.current -= 1;\n    if (dragCounter.current === 0) setIsDragging(false);\n  }\n\n  function handleDragOver(e: React.DragEvent): void {\n    e.preventDefault();\n  }\n\n  function handleDrop(e: React.DragEvent): void {\n    e.preventDefault();\n    dragCounter.current = 0;\n    setIsDragging(false);\n    if (e.dataTransfer.files.length) addFiles(e.dataTransfer.files);\n  }\n\n  function handleInputChange(e: React.ChangeEvent<HTMLInputElement>): void {\n    if (e.target.files?.length) addFiles(e.target.files);\n  }\n\n  function handleSubmit(): void {\n    onSubmit?.(files.filter((f) => f.status === \"done\").map((f) => f.file));\n  }\n\n  return (\n    <Card className=\"mx-auto w-full mt-14 max-w-md shadow-[0px_0px_0px_1px_rgba(0,0,0,0.06),0px_1px_2px_-1px_rgba(0,0,0,0.06),0px_2px_4px_0px_rgba(0,0,0,0.04)] ring-0\">\n      <CardHeader>\n        <div className=\"flex items-start justify-between gap-3\">\n          <div className=\"flex flex-col gap-1\">\n            <h2 className=\"text-foreground text-base leading-snug font-semibold tracking-tight\">\n              {title}\n            </h2>\n            <p className=\"text-muted-foreground text-sm leading-relaxed\">\n              {description}\n            </p>\n          </div>\n\n          {files.length > 0 && (\n            <Badge variant=\"secondary\" className=\"shrink-0 tabular-nums\">\n              {files.length}&nbsp;/&nbsp;{maxFiles}\n            </Badge>\n          )}\n        </div>\n      </CardHeader>\n\n      <CardContent className=\"flex flex-col gap-4\">\n        {!isAtLimit && (\n          <button\n            type=\"button\"\n            id=\"file-upload-drop-zone\"\n            aria-label=\"Drag and drop files or click to browse\"\n            className={[\n              \"focus-visible:ring-ring relative flex w-full cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed py-8 transition-all duration-200 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none\",\n              isDragging\n                ? \"border-primary bg-primary/5\"\n                : \"border-border bg-muted/40 hover:border-primary/50 hover:bg-muted/60\",\n            ].join(\" \")}\n            onClick={() => inputRef.current?.click()}\n            onDragEnter={handleDragEnter}\n            onDragLeave={handleDragLeave}\n            onDragOver={handleDragOver}\n            onDrop={handleDrop}\n          >\n            <div\n              className={[\n                \"flex size-11 items-center justify-center rounded-xl border transition-colors duration-200\",\n                isDragging\n                  ? \"border-primary/30 bg-primary/10 text-primary\"\n                  : \"border-border bg-background text-muted-foreground\",\n              ].join(\" \")}\n            >\n              <FaCloudUploadAlt className=\"size-5\" />\n            </div>\n\n            <div className=\"flex flex-col items-center gap-1 text-center\">\n              <p className=\"text-foreground text-sm font-medium\">\n                {isDragging\n                  ? \"Release to add files\"\n                  : \"Drag & drop or click to browse\"}\n              </p>\n              <p className=\"text-muted-foreground text-xs\">{acceptedLabel}</p>\n            </div>\n          </button>\n        )}\n\n        {files.length > 0 && (\n          <div className=\"flex flex-col gap-2\">\n            {files.map((uf) => (\n              <div\n                key={uf.id}\n                className=\"bg-muted/40 border-border flex flex-col gap-2 rounded-lg border px-3 py-2.5\"\n              >\n                <div className=\"flex items-center gap-3\">\n                  <span\n                    className={[\n                      \"shrink-0\",\n                      uf.status === \"error\"\n                        ? \"text-destructive\"\n                        : uf.status === \"done\"\n                          ? \"text-primary\"\n                          : \"text-muted-foreground\",\n                    ].join(\" \")}\n                  >\n                    <FileIcon file={uf.file} />\n                  </span>\n\n                  <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                    <p className=\"text-foreground truncate text-sm leading-none font-medium\">\n                      {uf.file.name}\n                    </p>\n                    <p className=\"text-muted-foreground text-xs\">\n                      {formatBytes(uf.file.size)}\n                    </p>\n                  </div>\n\n                  <div className=\"flex shrink-0 items-center gap-2\">\n                    {uf.status === \"done\" && (\n                      <FaCheckCircle className=\"text-primary size-3.5\" />\n                    )}\n                    {uf.status === \"error\" && (\n                      <FaExclamationCircle className=\"text-destructive size-3.5\" />\n                    )}\n                    {(uf.status === \"uploading\" || uf.status === \"queued\") && (\n                      <span className=\"text-muted-foreground text-xs tabular-nums\">\n                        {Math.round(uf.progress)}%\n                      </span>\n                    )}\n\n                    <button\n                      type=\"button\"\n                      id={`remove-file-${uf.id}`}\n                      aria-label={`Remove ${uf.file.name}`}\n                      onClick={() => removeFile(uf.id)}\n                      className=\"text-muted-foreground hover:text-destructive transition-colors duration-150\"\n                    >\n                      <FaTimes className=\"size-3.5\" />\n                    </button>\n                  </div>\n                </div>\n\n                {(uf.status === \"uploading\" || uf.status === \"queued\") && (\n                  <Progress value={uf.progress} className=\"h-1\" />\n                )}\n              </div>\n            ))}\n          </div>\n        )}\n\n        {files.length > 0 && (\n          <div className=\"flex items-center justify-between\">\n            <span className=\"text-muted-foreground text-xs\">\n              {files.length} file{files.length !== 1 ? \"s\" : \"\"}&nbsp;·&nbsp;\n              {formatBytes(totalSize)} total\n            </span>\n            {!hasUploading && (\n              <button\n                type=\"button\"\n                id=\"file-upload-clear-all\"\n                onClick={clearAll}\n                className=\"text-muted-foreground hover:text-foreground text-xs transition-colors duration-150\"\n              >\n                Clear all\n              </button>\n            )}\n          </div>\n        )}\n      </CardContent>\n\n      <CardFooter className=\"flex items-center justify-between gap-3\">\n        <div className=\"text-muted-foreground flex items-center gap-1.5\">\n          <FaShieldAlt className=\"size-3\" />\n          <span className=\"text-xs\">256-bit encrypted</span>\n        </div>\n\n        <div className=\"flex items-center gap-2\">\n          <Button\n            id=\"file-upload-cancel\"\n            variant=\"outline\"\n            size=\"sm\"\n            onClick={onCancel ?? clearAll}\n          >\n            {cancelLabel}\n          </Button>\n\n          <Button\n            id=\"file-upload-submit\"\n            variant=\"default\"\n            size=\"sm\"\n            disabled={!allDone}\n            onClick={handleSubmit}\n            className=\"gap-1.5\"\n          >\n            {submitLabel}\n            <FaArrowRight className=\"size-3\" />\n          </Button>\n        </div>\n      </CardFooter>\n\n      <input\n        ref={inputRef}\n        id=\"file-upload-input\"\n        type=\"file\"\n        multiple\n        className=\"sr-only\"\n        onChange={handleInputChange}\n        aria-hidden=\"true\"\n      />\n    </Card>\n  );\n}\n\nexport default FileUploader;\n",
      "type": "registry:ui",
      "target": "components/ui/file-upload-1.tsx"
    }
  ],
  "type": "registry:ui"
}
