{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-copy-block",
  "title": "CopyBlock",
  "description": "Exibe um trecho de texto ou código com um botão acoplado para cópia rápida.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/button",
    "@lema-ds/tooltip",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider",
    "@lema-ds/tokens"
  ],
  "files": [
    {
      "path": "components/ds/ds-copy-block.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { CheckIcon, CopyIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { Button } from \"@/components/ui/button\"\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\"\n\n// ── Types ──\n\nexport type CopyBlockSize = \"sm\" | \"md\" | \"lg\"\n\nexport interface CopyBlockProps\n  extends\n    Omit<React.HTMLAttributes<HTMLDivElement>, \"children\">,\n    VariantProps<typeof copyBlockVariants> {\n  /**\n   * The text to display and copy.\n   */\n  value: string\n  /**\n   * Defines the size of the block.\n   */\n  size?: CopyBlockSize\n  /**\n   * Whether the text should truncate if it exceeds the container width.\n   * If false, it will wrap to the next line.\n   */\n  truncate?: boolean\n  /**\n   * Localization for the tooltip texts.\n   */\n  locale?: UILocale\n}\n\n// ── Variants ──\n\nexport const copyBlockVariants = cva(\n  \"flex w-full items-center justify-between gap-3 overflow-hidden rounded-md border border-border bg-muted\",\n  {\n    variants: {\n      size: {\n        sm: \"min-h-8 py-1 pr-1 pl-3\",\n        md: \"min-h-10 py-1.5 pr-1.5 pl-4\",\n        lg: \"min-h-12 py-2 pr-2 pl-5\",\n      },\n    },\n    defaultVariants: {\n      size: \"md\",\n    },\n  }\n)\n\nexport const copyBlockTextVariants = cva(\"text-foreground\", {\n  variants: {\n    size: {\n      sm: \"text-xs\",\n      md: \"text-sm\",\n      lg: \"text-base\",\n    },\n    truncate: {\n      true: \"truncate\",\n      false: \"break-all\",\n    },\n  },\n  defaultVariants: {\n    size: \"md\",\n    truncate: false,\n  },\n})\n\n// ── Component ──\n\nexport const CopyBlock = React.forwardRef<HTMLDivElement, CopyBlockProps>(\n  (\n    {\n      value,\n      size = \"md\",\n      truncate = false,\n      locale: localeProp,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const [hasCopied, setHasCopied] = React.useState(false)\n\n    const { copy: copyLabel, copied: copiedLabel } = UI_I18N[locale].copyBlock\n\n    const onCopy = React.useCallback(() => {\n      if (!value) return\n      navigator.clipboard.writeText(value).then(() => {\n        setHasCopied(true)\n        setTimeout(() => {\n          setHasCopied(false)\n        }, 2000)\n      })\n    }, [value])\n\n    const iconSize =\n      size === \"sm\" ? \"size-3.5\" : size === \"lg\" ? \"size-5\" : \"size-4\"\n    const buttonSize =\n      size === \"sm\" ? \"icon-xs\" : size === \"lg\" ? \"icon\" : \"icon-sm\"\n\n    return (\n      <div\n        ref={ref}\n        className={cn(copyBlockVariants({ size }), className)}\n        {...props}\n      >\n        <span className={cn(copyBlockTextVariants({ size, truncate }))}>\n          {value}\n        </span>\n\n        <TooltipProvider delayDuration={100}>\n          <Tooltip>\n            <TooltipTrigger asChild>\n              <Button\n                variant=\"ghost\"\n                size={buttonSize}\n                className=\"shrink-0\"\n                onClick={onCopy}\n                aria-label={hasCopied ? copiedLabel : copyLabel}\n              >\n                {hasCopied ? (\n                  <CheckIcon\n                    className={cn(iconSize, \"text-success\")}\n                    aria-hidden=\"true\"\n                  />\n                ) : (\n                  <CopyIcon\n                    className={cn(iconSize, \"text-muted-foreground\")}\n                    aria-hidden=\"true\"\n                  />\n                )}\n              </Button>\n            </TooltipTrigger>\n            <TooltipContent>\n              {hasCopied ? copiedLabel : copyLabel}\n            </TooltipContent>\n          </Tooltip>\n        </TooltipProvider>\n      </div>\n    )\n  }\n)\nCopyBlock.displayName = \"CopyBlock\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
