{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "comp-551",
  "type": "registry:component",
  "title": "Comp 551",
  "description": "Comp 551",
  "files": [
    {
      "path": "registry/ui-basic/comp-551.tsx",
      "content": "\"use client\";\r\n\r\nimport { Button } from \"@/components/ui/button\";\r\nimport {\r\n\tTable,\r\n\tTableBody,\r\n\tTableCell,\r\n\tTableHead,\r\n\tTableHeader,\r\n\tTableRow,\r\n} from \"@/components/ui/table\";\r\nimport {\r\n\tAlertCircleIcon,\r\n\tDownloadIcon,\r\n\tFileArchiveIcon,\r\n\tFileIcon,\r\n\tFileSpreadsheetIcon,\r\n\tFileTextIcon,\r\n\tHeadphonesIcon,\r\n\tImageIcon,\r\n\tTrash2Icon,\r\n\tUploadCloudIcon,\r\n\tUploadIcon,\r\n\tVideoIcon,\r\n} from \"lucide-react\";\r\n\r\nimport { formatBytes, useFileUpload } from \"../utilities/usefileUpload\";\r\n\r\n// Create some dummy initial files\r\nconst initialFiles = [\r\n\t{\r\n\t\tname: \"document.pdf\",\r\n\t\tsize: 528737,\r\n\t\ttype: \"application/pdf\",\r\n\t\turl: \"https://originui.com\",\r\n\t\tid: \"document.pdf-1744638436563-8u5xuls\",\r\n\t},\r\n\t{\r\n\t\tname: \"intro.zip\",\r\n\t\tsize: 252873,\r\n\t\ttype: \"application/zip\",\r\n\t\turl: \"https://originui.com\",\r\n\t\tid: \"intro.zip-1744638436563-8u5xuls\",\r\n\t},\r\n\t{\r\n\t\tname: \"conclusion.xlsx\",\r\n\t\tsize: 352873,\r\n\t\ttype: \"application/xlsx\",\r\n\t\turl: \"https://originui.com\",\r\n\t\tid: \"conclusion.xlsx-1744638436563-8u5xuls\",\r\n\t},\r\n];\r\n\r\nconst getFileIcon = (file: { file: File | { type: string; name: string } }) => {\r\n\tconst fileType = file.file instanceof File ? file.file.type : file.file.type;\r\n\tconst fileName = file.file instanceof File ? file.file.name : file.file.name;\r\n\r\n\tif (\r\n\t\tfileType.includes(\"pdf\") ||\r\n\t\tfileName.endsWith(\".pdf\") ||\r\n\t\tfileType.includes(\"word\") ||\r\n\t\tfileName.endsWith(\".doc\") ||\r\n\t\tfileName.endsWith(\".docx\")\r\n\t) {\r\n\t\treturn <FileTextIcon className=\"size-4 opacity-60\" />;\r\n\t} else if (\r\n\t\tfileType.includes(\"zip\") ||\r\n\t\tfileType.includes(\"archive\") ||\r\n\t\tfileName.endsWith(\".zip\") ||\r\n\t\tfileName.endsWith(\".rar\")\r\n\t) {\r\n\t\treturn <FileArchiveIcon className=\"size-4 opacity-60\" />;\r\n\t} else if (\r\n\t\tfileType.includes(\"excel\") ||\r\n\t\tfileName.endsWith(\".xls\") ||\r\n\t\tfileName.endsWith(\".xlsx\")\r\n\t) {\r\n\t\treturn <FileSpreadsheetIcon className=\"size-4 opacity-60\" />;\r\n\t} else if (fileType.includes(\"video/\")) {\r\n\t\treturn <VideoIcon className=\"size-4 opacity-60\" />;\r\n\t} else if (fileType.includes(\"audio/\")) {\r\n\t\treturn <HeadphonesIcon className=\"size-4 opacity-60\" />;\r\n\t} else if (fileType.startsWith(\"image/\")) {\r\n\t\treturn <ImageIcon className=\"size-4 opacity-60\" />;\r\n\t}\r\n\treturn <FileIcon className=\"size-4 opacity-60\" />;\r\n};\r\n\r\nexport default function Component() {\r\n\tconst maxSize = 10 * 1024 * 1024; // 10MB default\r\n\tconst maxFiles = 10;\r\n\r\n\tconst [\r\n\t\t{ files, isDragging, errors },\r\n\t\t{\r\n\t\t\thandleDragEnter,\r\n\t\t\thandleDragLeave,\r\n\t\t\thandleDragOver,\r\n\t\t\thandleDrop,\r\n\t\t\topenFileDialog,\r\n\t\t\tremoveFile,\r\n\t\t\tclearFiles,\r\n\t\t\tgetInputProps,\r\n\t\t},\r\n\t] = useFileUpload({\r\n\t\tmultiple: true,\r\n\t\tmaxFiles,\r\n\t\tmaxSize,\r\n\t\tinitialFiles,\r\n\t});\r\n\r\n\treturn (\r\n\t\t<div className=\"flex flex-col gap-2\">\r\n\t\t\t{/* Drop area */}\r\n\t\t\t<div\r\n\t\t\t\tonDragEnter={handleDragEnter}\r\n\t\t\t\tonDragLeave={handleDragLeave}\r\n\t\t\t\tonDragOver={handleDragOver}\r\n\t\t\t\tonDrop={handleDrop}\r\n\t\t\t\tdata-dragging={isDragging || undefined}\r\n\t\t\t\tdata-files={files.length > 0 || undefined}\r\n\t\t\t\tclassName=\"border-input data-[dragging=true]:bg-accent/50 has-[input:focus]:border-ring has-[input:focus]:ring-ring/50 flex min-h-56 flex-col items-center rounded-xl border border-dashed p-4 transition-colors not-data-files:justify-center has-[input:focus]:ring-[3px] data-files:hidden\"\r\n\t\t\t>\r\n\t\t\t\t<input\r\n\t\t\t\t\t{...getInputProps()}\r\n\t\t\t\t\tclassName=\"sr-only\"\r\n\t\t\t\t\taria-label=\"Upload files\"\r\n\t\t\t\t/>\r\n\t\t\t\t<div className=\"flex flex-col items-center justify-center text-center\">\r\n\t\t\t\t\t<div\r\n\t\t\t\t\t\tclassName=\"bg-background mb-2 flex size-11 shrink-0 items-center justify-center rounded-full border\"\r\n\t\t\t\t\t\taria-hidden=\"true\"\r\n\t\t\t\t\t>\r\n\t\t\t\t\t\t<FileIcon className=\"size-4 opacity-60\" />\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<p className=\"mb-1.5 text-sm font-medium\">Upload files</p>\r\n\t\t\t\t\t<p className=\"text-muted-foreground text-xs\">\r\n\t\t\t\t\t\tMax {maxFiles} files ∙ Up to {formatBytes(maxSize)}\r\n\t\t\t\t\t</p>\r\n\t\t\t\t\t<Button\r\n\t\t\t\t\t\tvariant=\"outline\"\r\n\t\t\t\t\t\tclassName=\"mt-4\"\r\n\t\t\t\t\t\tonClick={openFileDialog}\r\n\t\t\t\t\t>\r\n\t\t\t\t\t\t<UploadIcon className=\"-ms-1 opacity-60\" aria-hidden=\"true\" />\r\n\t\t\t\t\t\tSelect files\r\n\t\t\t\t\t</Button>\r\n\t\t\t\t</div>\r\n\t\t\t</div>\r\n\t\t\t{files.length > 0 && (\r\n\t\t\t\t<>\r\n\t\t\t\t\t{/* Table with files */}\r\n\t\t\t\t\t<div className=\"flex items-center justify-between gap-2\">\r\n\t\t\t\t\t\t<h3 className=\"text-sm font-medium\">\r\n\t\t\t\t\t\t\tFiles ({files.length})\r\n\t\t\t\t\t\t</h3>\r\n\t\t\t\t\t\t<div className=\"flex gap-2\">\r\n\t\t\t\t\t\t\t<Button\r\n\t\t\t\t\t\t\t\tvariant=\"outline\"\r\n\t\t\t\t\t\t\t\tsize=\"sm\"\r\n\t\t\t\t\t\t\t\tonClick={openFileDialog}\r\n\t\t\t\t\t\t\t>\r\n\t\t\t\t\t\t\t\t<UploadCloudIcon\r\n\t\t\t\t\t\t\t\t\tclassName=\"-ms-0.5 size-3.5 opacity-60\"\r\n\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\r\n\t\t\t\t\t\t\t\t/>\r\n\t\t\t\t\t\t\t\tAdd files\r\n\t\t\t\t\t\t\t</Button>\r\n\t\t\t\t\t\t\t<Button variant=\"outline\" size=\"sm\" onClick={clearFiles}>\r\n\t\t\t\t\t\t\t\t<Trash2Icon\r\n\t\t\t\t\t\t\t\t\tclassName=\"-ms-0.5 size-3.5 opacity-60\"\r\n\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\r\n\t\t\t\t\t\t\t\t/>\r\n\t\t\t\t\t\t\t\tRemove all\r\n\t\t\t\t\t\t\t</Button>\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<div className=\"bg-background overflow-hidden rounded-md border\">\r\n\t\t\t\t\t\t<Table>\r\n\t\t\t\t\t\t\t<TableHeader className=\"text-xs\">\r\n\t\t\t\t\t\t\t\t<TableRow className=\"bg-muted/50\">\r\n\t\t\t\t\t\t\t\t\t<TableHead className=\"h-9 py-2\">Name</TableHead>\r\n\t\t\t\t\t\t\t\t\t<TableHead className=\"h-9 py-2\">Type</TableHead>\r\n\t\t\t\t\t\t\t\t\t<TableHead className=\"h-9 py-2\">Size</TableHead>\r\n\t\t\t\t\t\t\t\t\t<TableHead className=\"h-9 w-0 py-2 text-right\">\r\n\t\t\t\t\t\t\t\t\t\tActions\r\n\t\t\t\t\t\t\t\t\t</TableHead>\r\n\t\t\t\t\t\t\t\t</TableRow>\r\n\t\t\t\t\t\t\t</TableHeader>\r\n\t\t\t\t\t\t\t<TableBody className=\"text-[13px]\">\r\n\t\t\t\t\t\t\t\t{files.map((file) => (\r\n\t\t\t\t\t\t\t\t\t<TableRow key={file.id}>\r\n\t\t\t\t\t\t\t\t\t\t<TableCell className=\"max-w-48 py-2 font-medium\">\r\n\t\t\t\t\t\t\t\t\t\t\t<span className=\"flex items-center gap-2\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"shrink-0\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{getFileIcon(file)}\r\n\t\t\t\t\t\t\t\t\t\t\t\t</span>{\" \"}\r\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"truncate\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{file.file.name}\r\n\t\t\t\t\t\t\t\t\t\t\t\t</span>\r\n\t\t\t\t\t\t\t\t\t\t\t</span>\r\n\t\t\t\t\t\t\t\t\t\t</TableCell>\r\n\t\t\t\t\t\t\t\t\t\t<TableCell className=\"text-muted-foreground py-2\">\r\n\t\t\t\t\t\t\t\t\t\t\t{file.file.type.split(\"/\")[1]?.toUpperCase() ||\r\n\t\t\t\t\t\t\t\t\t\t\t\t\"UNKNOWN\"}\r\n\t\t\t\t\t\t\t\t\t\t</TableCell>\r\n\t\t\t\t\t\t\t\t\t\t<TableCell className=\"text-muted-foreground py-2\">\r\n\t\t\t\t\t\t\t\t\t\t\t{formatBytes(file.file.size)}\r\n\t\t\t\t\t\t\t\t\t\t</TableCell>\r\n\t\t\t\t\t\t\t\t\t\t<TableCell className=\"py-2 text-right whitespace-nowrap\">\r\n\t\t\t\t\t\t\t\t\t\t\t<Button\r\n\t\t\t\t\t\t\t\t\t\t\t\tsize=\"icon\"\r\n\t\t\t\t\t\t\t\t\t\t\t\tvariant=\"ghost\"\r\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"text-muted-foreground/80 hover:text-foreground size-8 hover:bg-transparent\"\r\n\t\t\t\t\t\t\t\t\t\t\t\taria-label={`Download ${file.file.name}`}\r\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() =>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\twindow.open(file.preview, \"_blank\")\r\n\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t>\r\n\t\t\t\t\t\t\t\t\t\t\t\t<DownloadIcon className=\"size-4\" />\r\n\t\t\t\t\t\t\t\t\t\t\t</Button>\r\n\t\t\t\t\t\t\t\t\t\t\t<Button\r\n\t\t\t\t\t\t\t\t\t\t\t\tsize=\"icon\"\r\n\t\t\t\t\t\t\t\t\t\t\t\tvariant=\"ghost\"\r\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"text-muted-foreground/80 hover:text-foreground size-8 hover:bg-transparent\"\r\n\t\t\t\t\t\t\t\t\t\t\t\taria-label={`Remove ${file.file.name}`}\r\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => removeFile(file.id)}\r\n\t\t\t\t\t\t\t\t\t\t\t>\r\n\t\t\t\t\t\t\t\t\t\t\t\t<Trash2Icon className=\"size-4\" />\r\n\t\t\t\t\t\t\t\t\t\t\t</Button>\r\n\t\t\t\t\t\t\t\t\t\t</TableCell>\r\n\t\t\t\t\t\t\t\t\t</TableRow>\r\n\t\t\t\t\t\t\t\t))}\r\n\t\t\t\t\t\t\t</TableBody>\r\n\t\t\t\t\t\t</Table>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</>\r\n\t\t\t)}\r\n\r\n\t\t\t{errors.length > 0 && (\r\n\t\t\t\t<div\r\n\t\t\t\t\tclassName=\"text-destructive flex items-center gap-1 text-xs\"\r\n\t\t\t\t\trole=\"alert\"\r\n\t\t\t\t>\r\n\t\t\t\t\t<AlertCircleIcon className=\"size-3 shrink-0\" />\r\n\t\t\t\t\t<span>{errors[0]}</span>\r\n\t\t\t\t</div>\r\n\t\t\t)}\r\n\r\n\t\t\t<p\r\n\t\t\t\taria-live=\"polite\"\r\n\t\t\t\trole=\"region\"\r\n\t\t\t\tclassName=\"text-muted-foreground mt-2 text-center text-xs\"\r\n\t\t\t>\r\n\t\t\t\tMultiple files uploader w/ table ∙{\" \"}\r\n\t\t\t\t<a\r\n\t\t\t\t\thref=\"https://github.com/origin-space/originui/tree/main/docs/use-file-upload.md\"\r\n\t\t\t\t\tclassName=\"hover:text-foreground underline\"\r\n\t\t\t\t>\r\n\t\t\t\t\tAPI\r\n\t\t\t\t</a>\r\n\t\t\t</p>\r\n\t\t</div>\r\n\t);\r\n}\r\n",
      "type": "registry:ui"
    },
    {
      "path": "components/ui/button.tsx",
      "content": "import * as React from \"react\";\r\n\r\nimport { cn } from \"@/registry/utilities/cn\";\r\nimport { Slot } from \"@radix-ui/react-slot\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\n\r\nconst buttonVariants = cva(\r\n\t\"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm text-white hover:text-gray-400 font-medium ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50\",\r\n\t{\r\n\t\tvariants: {\r\n\t\t\tvariant: {\r\n\t\t\t\tsimple:\r\n\t\t\t\t\t\"bg-secondary relative z-10 bg-transparent hover:border-secondary hover:bg-secondary/50  border border-transparent dark:text-white text-sm md:text-sm transition font-medium duration-200  rounded-md px-4 py-2  flex items-center justify-center\",\r\n\t\t\t\tdefault: \"bg-primary text-primary-foreground hover:bg-primary/90\",\r\n\t\t\t\tdestructive:\r\n\t\t\t\t\t\"bg-destructive text-destructive-foreground hover:bg-destructive/90\",\r\n\t\t\t\toutline:\r\n\t\t\t\t\t\"border border-input bg-background hover:bg-accent hover:text-accent-foreground\",\r\n\t\t\t\tsecondary:\r\n\t\t\t\t\t\"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\r\n\t\t\t\tghost: \"hover:bg-accent hover:text-black hover:stroke-black dark:text-white text-black\",\r\n\t\t\t\tlink: \"text-primary underline-offset-4 hover:underline\",\r\n\t\t\t},\r\n\t\t\tsize: {\r\n\t\t\t\tdefault: \"h-10 px-4 py-2\",\r\n\t\t\t\tsm: \"h-9 rounded-md px-3\",\r\n\t\t\t\tlg: \"h-11 rounded-md px-8\",\r\n\t\t\t\ticon: \"h-10 w-10\",\r\n\t\t\t},\r\n\t\t},\r\n\t\tdefaultVariants: {\r\n\t\t\tvariant: \"default\",\r\n\t\t\tsize: \"default\",\r\n\t\t},\r\n\t}\r\n);\r\n\r\nexport interface ButtonProps\r\n\textends React.ButtonHTMLAttributes<HTMLButtonElement>,\r\n\t\tVariantProps<typeof buttonVariants> {\r\n\tasChild?: boolean;\r\n}\r\n\r\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\r\n\t({ className, variant, size, asChild = false, ...props }, ref) => {\r\n\t\tconst Comp = asChild ? Slot : \"button\";\r\n\t\treturn (\r\n\t\t\t<Comp\r\n\t\t\t\tclassName={cn(buttonVariants({ variant, size, className }))}\r\n\t\t\t\tref={ref}\r\n\t\t\t\t{...props}\r\n\t\t\t/>\r\n\t\t);\r\n\t}\r\n);\r\nButton.displayName = \"Button\";\r\n\r\nexport { Button, buttonVariants };\r\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/utilities/cn.ts",
      "content": "import { ClassValue, clsx } from \"clsx\";\r\nimport { twMerge } from \"tailwind-merge\";\r\n\r\nexport function cn(...inputs: ClassValue[]) {\r\n\treturn twMerge(clsx(inputs));\r\n}\r\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/utilities/usefileUpload.ts",
      "content": "\"use client\"\r\n\r\nimport type React from \"react\"\r\nimport {\r\n    useCallback,\r\n    useRef,\r\n    useState,\r\n    type ChangeEvent,\r\n    type DragEvent,\r\n    type InputHTMLAttributes,\r\n} from \"react\"\r\n\r\nexport type FileMetadata = {\r\n    name: string\r\n    size: number\r\n    type: string\r\n    url: string\r\n    id: string\r\n}\r\n\r\nexport type FileWithPreview = {\r\n    file: File | FileMetadata\r\n    id: string\r\n    preview?: string\r\n}\r\n\r\nexport type FileUploadOptions = {\r\n    maxFiles?: number // Only used when multiple is true, defaults to Infinity\r\n    maxSize?: number // in bytes\r\n    accept?: string\r\n    multiple?: boolean // Defaults to false\r\n    initialFiles?: FileMetadata[]\r\n    onFilesChange?: (files: FileWithPreview[]) => void // Callback when files change\r\n    onFilesAdded?: (addedFiles: FileWithPreview[]) => void // Callback when new files are added\r\n}\r\n\r\nexport type FileUploadState = {\r\n    files: FileWithPreview[]\r\n    isDragging: boolean\r\n    errors: string[]\r\n}\r\n\r\nexport type FileUploadActions = {\r\n    addFiles: (files: FileList | File[]) => void\r\n    removeFile: (id: string) => void\r\n    clearFiles: () => void\r\n    clearErrors: () => void\r\n    handleDragEnter: (e: DragEvent<HTMLElement>) => void\r\n    handleDragLeave: (e: DragEvent<HTMLElement>) => void\r\n    handleDragOver: (e: DragEvent<HTMLElement>) => void\r\n    handleDrop: (e: DragEvent<HTMLElement>) => void\r\n    handleFileChange: (e: ChangeEvent<HTMLInputElement>) => void\r\n    openFileDialog: () => void\r\n    getInputProps: (\r\n        props?: InputHTMLAttributes<HTMLInputElement>\r\n    ) => InputHTMLAttributes<HTMLInputElement> & {\r\n        ref: React.Ref<HTMLInputElement>\r\n    }\r\n}\r\n\r\nexport const useFileUpload = (\r\n    options: FileUploadOptions = {}\r\n): [FileUploadState, FileUploadActions] => {\r\n    const {\r\n        maxFiles = Infinity,\r\n        maxSize = Infinity,\r\n        accept = \"*\",\r\n        multiple = false,\r\n        initialFiles = [],\r\n        onFilesChange,\r\n        onFilesAdded,\r\n    } = options\r\n\r\n    const [state, setState] = useState<FileUploadState>({\r\n        files: initialFiles.map((file) => ({\r\n            file,\r\n            id: file.id,\r\n            preview: file.url,\r\n        })),\r\n        isDragging: false,\r\n        errors: [],\r\n    })\r\n\r\n    const inputRef = useRef<HTMLInputElement>(null)\r\n\r\n    const validateFile = useCallback(\r\n        (file: File | FileMetadata): string | null => {\r\n            if (file instanceof File) {\r\n                if (file.size > maxSize) {\r\n                    return `File \"${file.name}\" exceeds the maximum size of ${formatBytes(maxSize)}.`\r\n                }\r\n            } else {\r\n                if (file.size > maxSize) {\r\n                    return `File \"${file.name}\" exceeds the maximum size of ${formatBytes(maxSize)}.`\r\n                }\r\n            }\r\n\r\n            if (accept !== \"*\") {\r\n                const acceptedTypes = accept.split(\",\").map((type) => type.trim())\r\n                const fileType = file instanceof File ? file.type || \"\" : file.type\r\n                const fileExtension = `.${file instanceof File ? file.name.split(\".\").pop() : file.name.split(\".\").pop()}`\r\n\r\n                const isAccepted = acceptedTypes.some((type) => {\r\n                    if (type.startsWith(\".\")) {\r\n                        return fileExtension.toLowerCase() === type.toLowerCase()\r\n                    }\r\n                    if (type.endsWith(\"/*\")) {\r\n                        const baseType = type.split(\"/\")[0]\r\n                        return fileType.startsWith(`${baseType}/`)\r\n                    }\r\n                    return fileType === type\r\n                })\r\n\r\n                if (!isAccepted) {\r\n                    return `File \"${file instanceof File ? file.name : file.name}\" is not an accepted file type.`\r\n                }\r\n            }\r\n\r\n            return null\r\n        },\r\n        [accept, maxSize]\r\n    )\r\n\r\n    const createPreview = useCallback(\r\n        (file: File | FileMetadata): string | undefined => {\r\n            if (file instanceof File) {\r\n                return URL.createObjectURL(file)\r\n            }\r\n            return file.url\r\n        },\r\n        []\r\n    )\r\n\r\n    const generateUniqueId = useCallback((file: File | FileMetadata): string => {\r\n        if (file instanceof File) {\r\n            return `${file.name}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`\r\n        }\r\n        return file.id\r\n    }, [])\r\n\r\n    const clearFiles = useCallback(() => {\r\n        setState((prev) => {\r\n            // Clean up object URLs\r\n            prev.files.forEach((file) => {\r\n                if (\r\n                    file.preview &&\r\n                    file.file instanceof File &&\r\n                    file.file.type.startsWith(\"image/\")\r\n                ) {\r\n                    URL.revokeObjectURL(file.preview)\r\n                }\r\n            })\r\n\r\n            if (inputRef.current) {\r\n                inputRef.current.value = \"\"\r\n            }\r\n\r\n            const newState = {\r\n                ...prev,\r\n                files: [],\r\n                errors: [],\r\n            }\r\n\r\n            onFilesChange?.(newState.files)\r\n            return newState\r\n        })\r\n    }, [onFilesChange])\r\n\r\n    const addFiles = useCallback(\r\n        (newFiles: FileList | File[]) => {\r\n            if (!newFiles || newFiles.length === 0) return\r\n\r\n            const newFilesArray = Array.from(newFiles)\r\n            const errors: string[] = []\r\n\r\n            // Clear existing errors when new files are uploaded\r\n            setState((prev) => ({ ...prev, errors: [] }))\r\n\r\n            // In single file mode, clear existing files first\r\n            if (!multiple) {\r\n                clearFiles()\r\n            }\r\n\r\n            // Check if adding these files would exceed maxFiles (only in multiple mode)\r\n            if (\r\n                multiple &&\r\n                maxFiles !== Infinity &&\r\n                state.files.length + newFilesArray.length > maxFiles\r\n            ) {\r\n                errors.push(`You can only upload a maximum of ${maxFiles} files.`)\r\n                setState((prev) => ({ ...prev, errors }))\r\n                return\r\n            }\r\n\r\n            const validFiles: FileWithPreview[] = []\r\n\r\n            newFilesArray.forEach((file) => {\r\n                // Only check for duplicates if multiple files are allowed\r\n                if (multiple) {\r\n                    const isDuplicate = state.files.some(\r\n                        (existingFile) =>\r\n                            existingFile.file.name === file.name &&\r\n                            existingFile.file.size === file.size\r\n                    )\r\n\r\n                    // Skip duplicate files silently\r\n                    if (isDuplicate) {\r\n                        return\r\n                    }\r\n                }\r\n\r\n                // Check file size\r\n                if (file.size > maxSize) {\r\n                    errors.push(\r\n                        multiple\r\n                            ? `Some files exceed the maximum size of ${formatBytes(maxSize)}.`\r\n                            : `File exceeds the maximum size of ${formatBytes(maxSize)}.`\r\n                    )\r\n                    return\r\n                }\r\n\r\n                const error = validateFile(file)\r\n                if (error) {\r\n                    errors.push(error)\r\n                } else {\r\n                    validFiles.push({\r\n                        file,\r\n                        id: generateUniqueId(file),\r\n                        preview: createPreview(file),\r\n                    })\r\n                }\r\n            })\r\n\r\n            // Only update state if we have valid files to add\r\n            if (validFiles.length > 0) {\r\n                // Call the onFilesAdded callback with the newly added valid files\r\n                onFilesAdded?.(validFiles)\r\n\r\n                setState((prev) => {\r\n                    const newFiles = !multiple\r\n                        ? validFiles\r\n                        : [...prev.files, ...validFiles]\r\n                    onFilesChange?.(newFiles)\r\n                    return {\r\n                        ...prev,\r\n                        files: newFiles,\r\n                        errors,\r\n                    }\r\n                })\r\n            } else if (errors.length > 0) {\r\n                setState((prev) => ({\r\n                    ...prev,\r\n                    errors,\r\n                }))\r\n            }\r\n\r\n            // Reset input value after handling files\r\n            if (inputRef.current) {\r\n                inputRef.current.value = \"\"\r\n            }\r\n        },\r\n        [\r\n            state.files,\r\n            maxFiles,\r\n            multiple,\r\n            maxSize,\r\n            validateFile,\r\n            createPreview,\r\n            generateUniqueId,\r\n            clearFiles,\r\n            onFilesChange,\r\n            onFilesAdded,\r\n        ]\r\n    )\r\n\r\n    const removeFile = useCallback(\r\n        (id: string) => {\r\n            setState((prev) => {\r\n                const fileToRemove = prev.files.find((file) => file.id === id)\r\n                if (\r\n                    fileToRemove &&\r\n                    fileToRemove.preview &&\r\n                    fileToRemove.file instanceof File &&\r\n                    fileToRemove.file.type.startsWith(\"image/\")\r\n                ) {\r\n                    URL.revokeObjectURL(fileToRemove.preview)\r\n                }\r\n\r\n                const newFiles = prev.files.filter((file) => file.id !== id)\r\n                onFilesChange?.(newFiles)\r\n\r\n                return {\r\n                    ...prev,\r\n                    files: newFiles,\r\n                    errors: [],\r\n                }\r\n            })\r\n        },\r\n        [onFilesChange]\r\n    )\r\n\r\n    const clearErrors = useCallback(() => {\r\n        setState((prev) => ({\r\n            ...prev,\r\n            errors: [],\r\n        }))\r\n    }, [])\r\n\r\n    const handleDragEnter = useCallback((e: DragEvent<HTMLElement>) => {\r\n        e.preventDefault()\r\n        e.stopPropagation()\r\n        setState((prev) => ({ ...prev, isDragging: true }))\r\n    }, [])\r\n\r\n    const handleDragLeave = useCallback((e: DragEvent<HTMLElement>) => {\r\n        e.preventDefault()\r\n        e.stopPropagation()\r\n\r\n        if (e.currentTarget.contains(e.relatedTarget as Node)) {\r\n            return\r\n        }\r\n\r\n        setState((prev) => ({ ...prev, isDragging: false }))\r\n    }, [])\r\n\r\n    const handleDragOver = useCallback((e: DragEvent<HTMLElement>) => {\r\n        e.preventDefault()\r\n        e.stopPropagation()\r\n    }, [])\r\n\r\n    const handleDrop = useCallback(\r\n        (e: DragEvent<HTMLElement>) => {\r\n            e.preventDefault()\r\n            e.stopPropagation()\r\n            setState((prev) => ({ ...prev, isDragging: false }))\r\n\r\n            // Don't process files if the input is disabled\r\n            if (inputRef.current?.disabled) {\r\n                return\r\n            }\r\n\r\n            if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {\r\n                // In single file mode, only use the first file\r\n                if (!multiple) {\r\n                    const file = e.dataTransfer.files[0]\r\n                    addFiles([file])\r\n                } else {\r\n                    addFiles(e.dataTransfer.files)\r\n                }\r\n            }\r\n        },\r\n        [addFiles, multiple]\r\n    )\r\n\r\n    const handleFileChange = useCallback(\r\n        (e: ChangeEvent<HTMLInputElement>) => {\r\n            if (e.target.files && e.target.files.length > 0) {\r\n                addFiles(e.target.files)\r\n            }\r\n        },\r\n        [addFiles]\r\n    )\r\n\r\n    const openFileDialog = useCallback(() => {\r\n        if (inputRef.current) {\r\n            inputRef.current.click()\r\n        }\r\n    }, [])\r\n\r\n    const getInputProps = useCallback(\r\n        (props: InputHTMLAttributes<HTMLInputElement> = {}) => {\r\n            return {\r\n                ...props,\r\n                type: \"file\" as const,\r\n                onChange: handleFileChange,\r\n                accept: props.accept || accept,\r\n                multiple: props.multiple !== undefined ? props.multiple : multiple,\r\n                ref: inputRef,\r\n            }\r\n        },\r\n        [accept, multiple, handleFileChange]\r\n    )\r\n\r\n    return [\r\n        state,\r\n        {\r\n            addFiles,\r\n            removeFile,\r\n            clearFiles,\r\n            clearErrors,\r\n            handleDragEnter,\r\n            handleDragLeave,\r\n            handleDragOver,\r\n            handleDrop,\r\n            handleFileChange,\r\n            openFileDialog,\r\n            getInputProps,\r\n        },\r\n    ]\r\n}\r\n\r\n// Helper function to format bytes to human-readable format\r\nexport const formatBytes = (bytes: number, decimals = 2): string => {\r\n    if (bytes === 0) return \"0 Bytes\"\r\n\r\n    const k = 1024\r\n    const dm = decimals < 0 ? 0 : decimals\r\n    const sizes = [\"Bytes\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"]\r\n\r\n    const i = Math.floor(Math.log(bytes) / Math.log(k))\r\n\r\n    return Number.parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + sizes[i]\r\n}",
      "type": "registry:ui"
    }
  ]
}