{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "source",
  "type": "registry:component",
  "title": "Source",
  "description": "Source viewer component",
  "registryDependencies": [
    "tooltip"
  ],
  "files": [
    {
      "path": "components/chatcn/ai/source.tsx",
      "content": "\"use client\";\nimport React, { createContext, useContext } from \"react\";\nimport {\n  HoverCard,\n  HoverCardContent,\n  HoverCardTrigger,\n} from \"@/components/ui/hover-card\";\nimport { cn } from \"@/lib/utils\";\n\ntype SourceContextType = {\n  href: string;\n  label?: string | number;\n};\n\nconst SourceContext = createContext<SourceContextType | null>(null);\n\nfunction useSourceContext() {\n  const context = useContext(SourceContext);\n  if (!context) {\n    throw new Error(\"useSourceContext must be used within a Source component\");\n  }\n  return context;\n}\n\nexport type SourceProps = {\n  href: string;\n  label?: string | number;\n  children: React.ReactNode;\n};\n\nfunction getDomainFromUrl(url: string): string {\n  try {\n    const urlObj = new URL(url);\n    return urlObj.hostname;\n  } catch {\n    return url;\n  }\n}\n\nexport function Source({ href, label, children }: SourceProps) {\n  return (\n    <SourceContext.Provider value={{ href, label }}>\n      <HoverCard openDelay={150} closeDelay={0}>\n        {children}\n      </HoverCard>\n    </SourceContext.Provider>\n  );\n}\n\nexport type SourceTriggerProps = {\n  showFavicon?: boolean;\n  className?: string;\n  label?: string | number;\n};\n\nexport function SourceTrigger({\n  showFavicon = true,\n  className,\n  label: propLabel,\n}: SourceTriggerProps) {\n  const { href, label: contextLabel } = useSourceContext();\n  const displayLabel = propLabel ?? contextLabel;\n\n  return (\n    <HoverCardTrigger asChild>\n      <a\n        href={href}\n        target=\"_blank\"\n        rel=\"noopener noreferrer\"\n        className={cn(\n          \"bg-muted text-muted-foreground hover:bg-muted-foreground/30 hover:text-primary inline-flex h-5 max-w-32 items-center gap-1 overflow-hidden rounded-full py-1 text-xs leading-none no-underline transition-colors duration-150\",\n          showFavicon ? \"pr-2 pl-1\" : \"px-1\",\n          className\n        )}\n      >\n        {showFavicon && (\n          // eslint-disable-next-line @next/next/no-img-element\n          <img\n            src={`https://www.google.com/s2/favicons?sz=64&domain_url=${encodeURIComponent(\n              href\n            )}`}\n            alt=\"favicon\"\n            width={14}\n            height={14}\n            className=\"size-3.5 rounded-full\"\n          />\n        )}\n        <span className=\"truncate text-center font-normal\">\n          {displayLabel ?? getDomainFromUrl(href)}\n        </span>\n      </a>\n    </HoverCardTrigger>\n  );\n}\n\nexport type SourceContentProps = {\n  title: string;\n  description: string;\n  className?: string;\n  children?: React.ReactNode;\n};\n\nexport function SourceContent({\n  title,\n  description,\n  className,\n  children,\n}: SourceContentProps) {\n  const { href } = useSourceContext();\n  if (children)\n    return <HoverCardContent className=\"w-80 p-4\">{children}</HoverCardContent>;\n\n  if (!title && !description) return null;\n\n  return (\n    <HoverCardContent className={cn(className, \"shadow-xs\")}>\n      <a href={href} className=\"space-y-4\" target=\"_blank\">\n        <div className=\"flex items-center gap-2\">\n          {/* eslint-disable-next-line @next/next/no-img-element */}\n          <img\n            src={`https://www.google.com/s2/favicons?sz=64&domain_url=${encodeURIComponent(\n              href\n            )}`}\n            alt=\"favicon\"\n            width={16}\n            height={16}\n            className=\"w-4 h-4 rounded-sm flex-shrink-0\"\n          />\n          <p className=\"text-xs text-muted-foreground font-medium truncate\">\n            {getDomainFromUrl(href)}\n          </p>\n        </div>\n\n        <div className=\"space-y-2\">\n          <h3 className=\"text-sm font-semibold text-foreground/80 leading-tight line-clamp-2\">\n            {title}\n          </h3>\n          <p className=\"text-xs text-muted-foreground leading-relaxed line-clamp-3\">\n            {description}\n          </p>\n        </div>\n      </a>\n    </HoverCardContent>\n  );\n}\n",
      "type": "registry:component"
    }
  ]
}