{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-dialog",
  "title": "Share Dialog",
  "description": "Modal dialog for sharing a page across social platforms with a copy-link action and overridable labels.",
  "dependencies": [
    "@vllnt/ui@^0.2.1"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/default/share-dialog/share-dialog.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@vllnt/ui\";\nimport {\n  Dialog,\n  DialogContent,\n  DialogDescription,\n  DialogHeader,\n  DialogTitle,\n} from \"@vllnt/ui\";\n\nexport type SharePlatform = {\n  buildUrl: (pageUrl: string, pageTitle: string) => string;\n  key: string;\n  label: string;\n};\n\nexport type ShareDialogLabels = {\n  copied: string;\n  copyLink: string;\n};\n\nexport type ShareDialogProps = {\n  /** Function to build the URL for copying (should add UTM params) */\n  buildCopyUrl?: (url: string) => string;\n  description?: string;\n  labels?: ShareDialogLabels;\n  onCopy?: () => void;\n  onOpenChange?: (open: boolean) => void;\n  onShare?: (platformKey: string) => void;\n  open?: boolean;\n  platforms: SharePlatform[];\n  title?: string;\n};\n\nfunction PlatformButton({\n  onClick,\n  platform,\n}: {\n  onClick: (key: string) => void;\n  platform: SharePlatform;\n}) {\n  const handleSelectPlatform = () => {\n    onClick(platform.key);\n  };\n\n  return (\n    <button\n      className={cn(\n        \"w-full rounded-md border border-border bg-background px-4 py-3\",\n        \"text-sm font-medium text-foreground\",\n        \"transition-colors duration-150\",\n        \"hover:bg-accent hover:text-accent-foreground\",\n        \"focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2\",\n      )}\n      onClick={handleSelectPlatform}\n      type=\"button\"\n    >\n      {platform.label}\n    </button>\n  );\n}\n\nfunction CopyButton({\n  buildCopyUrl,\n  labels,\n  onCopy,\n}: {\n  buildCopyUrl?: (url: string) => string;\n  labels: ShareDialogLabels;\n  onCopy?: () => void;\n}) {\n  const [copied, setCopied] = React.useState(false);\n\n  const handleCopy = React.useCallback(async () => {\n    const url = buildCopyUrl\n      ? buildCopyUrl(window.location.href)\n      : window.location.href;\n    const text = `${document.title} - ${url}`;\n\n    await navigator.clipboard.writeText(text);\n    setCopied(true);\n    onCopy?.();\n\n    setTimeout(() => {\n      setCopied(false);\n    }, 2000);\n  }, [buildCopyUrl, onCopy]);\n\n  return (\n    <button\n      className={cn(\n        \"col-span-2 w-full rounded-md border px-4 py-3\",\n        \"text-sm font-medium\",\n        \"transition-colors duration-150\",\n        \"focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2\",\n        copied\n          ? \"border-green-500 bg-green-500/10 text-green-600 dark:text-green-400\"\n          : \"border-border bg-background text-foreground hover:bg-accent hover:text-accent-foreground\",\n      )}\n      onClick={handleCopy}\n      type=\"button\"\n    >\n      {copied ? labels.copied : labels.copyLink}\n    </button>\n  );\n}\n\nconst defaultLabels: ShareDialogLabels = {\n  copied: \"Copied!\",\n  copyLink: \"Copy link\",\n};\n\nexport function ShareDialog({\n  buildCopyUrl,\n  description,\n  labels = defaultLabels,\n  onCopy,\n  onOpenChange,\n  onShare,\n  open,\n  platforms,\n  title = \"Share\",\n}: ShareDialogProps) {\n  const handlePlatformClick = React.useCallback(\n    (key: string) => {\n      const platform = platforms.find((p) => p.key === key);\n      if (platform) {\n        const url = platform.buildUrl(window.location.href, document.title);\n        window.open(url, \"_blank\", \"noopener,noreferrer\");\n        onShare?.(key);\n        onOpenChange?.(false);\n      }\n    },\n    [platforms, onShare, onOpenChange],\n  );\n\n  return (\n    <Dialog onOpenChange={onOpenChange} open={open}>\n      <DialogContent className=\"sm:max-w-sm\">\n        <DialogHeader>\n          <DialogTitle>{title}</DialogTitle>\n          {description ? (\n            <DialogDescription>{description}</DialogDescription>\n          ) : null}\n        </DialogHeader>\n        <div className=\"grid grid-cols-2 gap-2\">\n          {platforms.map((platform) => (\n            <PlatformButton\n              key={platform.key}\n              onClick={handlePlatformClick}\n              platform={platform}\n            />\n          ))}\n          <CopyButton\n            buildCopyUrl={buildCopyUrl}\n            labels={labels}\n            onCopy={onCopy}\n          />\n        </div>\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component",
  "version": "0.2.1",
  "stability": "stable"
}
