'use client'; import { buttonVariants } from 'fumadocs-ui/components/ui/button'; import { Popover, PopoverContent, PopoverTrigger } from 'fumadocs-ui/components/ui/popover'; import { ChevronDown, ExternalLink, Text } from 'lucide-react'; import { useMemo, type ComponentProps, type ReactNode } from 'react'; import { cn } from '@/lib/cn'; import { GitHubIcon } from './icons'; type ViewOptionsPopoverProps = ComponentProps & { markdownUrl?: string; githubUrl?: string; /** Canonical page URL the AI prompts ask to read. */ pageUrl: string; }; type Option = { title: string; href: string; icon: ReactNode; }; export function ViewOptionsPopover({ markdownUrl, githubUrl, pageUrl, children, className, ...props }: ViewOptionsPopoverProps) { const items = useMemo(() => { const prompt = `Read ${pageUrl}, I want to ask questions about it.`; const options: Option[] = []; if (githubUrl) { options.push({ title: 'Open in GitHub', href: githubUrl, icon: , }); } if (markdownUrl) { options.push({ title: 'View as Markdown', href: markdownUrl, icon: , }); } options.push( { title: 'Open in ChatGPT', href: `https://chatgpt.com/?${new URLSearchParams({ prompt, hints: 'search' })}`, icon: , }, { title: 'Open in Claude', href: `https://claude.ai/new?${new URLSearchParams({ q: prompt })}`, icon: , }, { title: 'Open in Gemini', // gemini.google.com ignores prompt query params; AI Mode is Gemini and reads `q` href: `https://www.google.com/search?${new URLSearchParams({ udm: '50', q: prompt })}`, icon: , }, ); return options; }, [githubUrl, markdownUrl, pageUrl]); return ( cn( buttonVariants({ variant: 'secondary', size: 'sm' }), 'gap-2 data-[popup-open]:bg-fd-accent data-[popup-open]:text-fd-accent-foreground', typeof className === 'function' ? className(state) : className, ) } > {children ?? 'Open'} {items.map((item) => ( {item.icon} {item.title} ))} ); } function OpenAIIcon() { return ( ); } function ClaudeIcon() { return ( ); } function GeminiIcon() { return ( ); }