{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "comp-126",
  "type": "registry:component",
  "title": "Comp 126",
  "description": "Comp 126",
  "files": [
    {
      "path": "registry/ui-basic/comp-126.tsx",
      "content": "\"use client\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { CircleUserRoundIcon, XIcon } from \"lucide-react\";\n\nimport { useFileUpload } from \"../utilities/usefileUpload\";\n\nexport default function Component() {\n\tconst [{ files }, { removeFile, openFileDialog, getInputProps }] =\n\t\tuseFileUpload({\n\t\t\taccept: \"image/*\",\n\t\t});\n\n\tconst previewUrl = files[0]?.preview || null;\n\tconst fileName = files[0]?.file.name || null;\n\n\treturn (\n\t\t<div className=\"flex flex-col items-center gap-2\">\n\t\t\t<div className=\"relative inline-flex\">\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"outline\"\n\t\t\t\t\tclassName=\"relative size-16 overflow-hidden p-0 shadow-none\"\n\t\t\t\t\tonClick={openFileDialog}\n\t\t\t\t\taria-label={previewUrl ? \"Change image\" : \"Upload image\"}\n\t\t\t\t>\n\t\t\t\t\t{previewUrl ? (\n\t\t\t\t\t\t<img\n\t\t\t\t\t\t\tclassName=\"size-full object-cover\"\n\t\t\t\t\t\t\tsrc={previewUrl}\n\t\t\t\t\t\t\talt=\"Preview of uploaded image\"\n\t\t\t\t\t\t\twidth={64}\n\t\t\t\t\t\t\theight={64}\n\t\t\t\t\t\t\tstyle={{ objectFit: \"cover\" }}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<div aria-hidden=\"true\">\n\t\t\t\t\t\t\t<CircleUserRoundIcon className=\"size-4 opacity-60\" />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t</Button>\n\t\t\t\t{previewUrl && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tonClick={() => removeFile(files[0]?.id)}\n\t\t\t\t\t\tsize=\"icon\"\n\t\t\t\t\t\tclassName=\"border-background focus-visible:border-background absolute -top-2 -right-2 size-6 rounded-full border-2 shadow-none\"\n\t\t\t\t\t\taria-label=\"Remove image\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<XIcon className=\"size-3.5\" />\n\t\t\t\t\t</Button>\n\t\t\t\t)}\n\t\t\t\t<input\n\t\t\t\t\t{...getInputProps()}\n\t\t\t\t\tclassName=\"sr-only\"\n\t\t\t\t\taria-label=\"Upload image file\"\n\t\t\t\t\ttabIndex={-1}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t{fileName && (\n\t\t\t\t<p className=\"text-muted-foreground text-xs\">{fileName}</p>\n\t\t\t)}\n\t\t\t<p\n\t\t\t\taria-live=\"polite\"\n\t\t\t\trole=\"region\"\n\t\t\t\tclassName=\"text-muted-foreground mt-2 text-xs\"\n\t\t\t>\n\t\t\t\tAvatar upload button\n\t\t\t</p>\n\t\t</div>\n\t);\n}\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"
    }
  ]
}