{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-file-upload",
  "title": "FileUpload",
  "description": "Área de upload de arquivos com suporte a arrastar e soltar e barra de progresso.",
  "dependencies": [
    "lucide-react",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@lema-ds/button",
    "@lema-ds/progress",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-file-upload.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { UploadCloudIcon, FileIcon, XIcon, Loader2Icon } from \"lucide-react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\nimport { Progress } from \"@/components/ui/progress\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\n\n// ── Types ──\n\nexport const fileUploadVariants = cva(\n  \"relative flex cursor-pointer flex-col items-center justify-center rounded-lg border-2 border-dashed transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring has-[:focus-visible]:ring-offset-2 has-[:focus-visible]:ring-offset-background\",\n  {\n    variants: {\n      isDragActive: {\n        true: \"border-primary bg-primary/5\",\n        false: \"border-border bg-background hover:bg-muted/50\",\n      },\n      disabled: {\n        true: \"cursor-not-allowed opacity-50\",\n        false: \"\",\n      },\n      size: {\n        sm: \"min-h-32 p-4\",\n        md: \"min-h-48 p-6\",\n      },\n    },\n    defaultVariants: {\n      isDragActive: false,\n      disabled: false,\n      size: \"md\",\n    },\n  }\n)\n\nexport interface FileUploadProps\n  extends\n    Omit<React.HTMLAttributes<HTMLDivElement>, \"onDrop\" | \"onChange\">,\n    VariantProps<typeof fileUploadVariants> {\n  onUpload: (file: File) => void\n  accept?: string\n  maxSizeMB?: number\n  progress?: number\n  disabled?: boolean\n  locale?: UILocale\n}\n\n// ── Component ──\n\nexport const FileUpload = React.forwardRef<HTMLDivElement, FileUploadProps>(\n  (\n    {\n      onUpload,\n      accept = \"*/*\",\n      maxSizeMB = 10,\n      progress,\n      disabled = false,\n      locale: localeProp,\n      size = \"md\",\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const inputRef = React.useRef<HTMLInputElement>(null)\n    const [isDragActive, setIsDragActive] = React.useState(false)\n    const [selectedFile, setSelectedFile] = React.useState<File | null>(null)\n    const [error, setError] = React.useState<string | null>(null)\n\n    const i18n = UI_I18N[locale].fileUpload\n    const t = {\n      dragDrop: i18n.dragDrop,\n      clickToBrowse: i18n.clickToBrowse,\n      maxSize: `${i18n.maxSizeLabel}: ${maxSizeMB}MB`,\n      uploading: i18n.uploading,\n      fileTooLarge: `${i18n.fileTooLargeLabel} ${maxSizeMB}MB.`,\n      remove: i18n.remove,\n    }\n\n    const handleFile = (file: File) => {\n      setError(null)\n      if (file.size > maxSizeMB * 1024 * 1024) {\n        setError(t.fileTooLarge)\n        return\n      }\n      setSelectedFile(file)\n      onUpload(file)\n    }\n\n    const onDragOver = (e: React.DragEvent) => {\n      e.preventDefault()\n      if (disabled) return\n      setIsDragActive(true)\n    }\n\n    const onDragLeave = () => {\n      if (disabled) return\n      setIsDragActive(false)\n    }\n\n    const onDrop = (e: React.DragEvent) => {\n      e.preventDefault()\n      if (disabled) return\n      setIsDragActive(false)\n      if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {\n        handleFile(e.dataTransfer.files[0])\n      }\n    }\n\n    const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n      if (e.target.files && e.target.files.length > 0) {\n        handleFile(e.target.files[0])\n      }\n    }\n\n    const handleRemove = (e: React.MouseEvent) => {\n      e.stopPropagation()\n      setSelectedFile(null)\n      setError(null)\n      if (inputRef.current) {\n        inputRef.current.value = \"\"\n      }\n    }\n\n    const formatBytes = (bytes: number) => {\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\n    const isUploading =\n      progress !== undefined && progress >= 0 && progress < 100\n\n    return (\n      <div className=\"w-full\">\n        {!selectedFile ? (\n          <div\n            ref={ref}\n            aria-label={t.dragDrop}\n            aria-describedby=\"file-upload-hint\"\n            className={cn(\n              fileUploadVariants({ isDragActive, disabled, size }),\n              !disabled &&\n                \"focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2\",\n              className\n            )}\n            onDragOver={onDragOver}\n            onDragLeave={onDragLeave}\n            onDrop={onDrop}\n            {...props}\n          >\n            <label className=\"flex w-full flex-col items-center justify-center\">\n              <input\n                ref={inputRef}\n                type=\"file\"\n                className=\"sr-only\"\n                accept={accept}\n                onChange={onChange}\n                disabled={disabled}\n              />\n              <UploadCloudIcon className=\"mb-4 size-10 text-muted-foreground\" />\n              <p className=\"text-center text-sm font-medium text-foreground\">\n                {t.dragDrop}\n              </p>\n              <p className=\"mt-1 text-center text-sm text-muted-foreground\">\n                {t.clickToBrowse}\n              </p>\n              <p\n                id=\"file-upload-hint\"\n                className=\"mt-4 text-center text-xs text-muted-foreground\"\n              >\n                {t.maxSize} · {accept}\n              </p>\n            </label>\n          </div>\n        ) : (\n          <div\n            ref={ref}\n            className={cn(\n              \"flex flex-col gap-4 rounded-lg border border-border bg-background p-4\",\n              className\n            )}\n            {...props}\n          >\n            <div className=\"flex items-center gap-4\">\n              <div className=\"flex size-10 shrink-0 items-center justify-center rounded-md bg-muted\">\n                <FileIcon className=\"size-5 text-muted-foreground\" />\n              </div>\n              <div className=\"flex min-w-0 flex-1 flex-col\">\n                <span className=\"truncate text-sm font-medium text-foreground\">\n                  {selectedFile.name}\n                </span>\n                <span className=\"text-xs text-muted-foreground\">\n                  {formatBytes(selectedFile.size)}\n                </span>\n              </div>\n              {!isUploading && (\n                <Button\n                  variant=\"ghost\"\n                  size=\"icon\"\n                  className=\"shrink-0 text-muted-foreground hover:text-destructive\"\n                  onClick={handleRemove}\n                  aria-label={t.remove}\n                >\n                  <XIcon />\n                </Button>\n              )}\n            </div>\n            {isUploading && (\n              <div className=\"flex flex-col gap-1.5\">\n                <div className=\"flex items-center justify-between text-xs text-muted-foreground\">\n                  <span className=\"flex items-center gap-1\">\n                    <Loader2Icon className=\"size-3 animate-spin\" />{\" \"}\n                    {t.uploading}\n                  </span>\n                  <span>{progress}%</span>\n                </div>\n                <Progress value={progress} className=\"h-2\" />\n              </div>\n            )}\n          </div>\n        )}\n        {error && <p className=\"mt-2 text-sm text-destructive\">{error}</p>}\n      </div>\n    )\n  }\n)\nFileUpload.displayName = \"FileUpload\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
