import type { ReactNode } from 'react' import { cn } from '@/lib/utils' import { Button } from '../basic/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '../basic/dropdown-menu' import { CloseLine, ArrowDownSLine, WarningLine, SparklingLine } from '../basic/icons-inline' import { Scrollbar } from '../basic/scrollbar' export interface HintBannerProps { type?: 'wiki' | 'credits' title?: string description?: string highlightText?: string language?: string rechargeText?: string onClose?: () => void onGenerate?: () => void onRecharge?: () => void onLanguageChange?: (language: string) => void closeIcon?: ReactNode arrowDownSIcon?: ReactNode suggestionIcon?: ReactNode /** 供 Portal 浮层继承(与 ChatInput FolderButton 一致),不传则由 dropdown-menu 使用 getThemeFromDocument() 兜底 */ dataStyle?: string dataTheme?: string } const DEFAULT_HIGHLIGHT = 'Repo Wiki' const LANGUAGES = ['English', '中文', '日本語', '한국어'] const closeClass = 'h-3.5 w-3.5' const arrowClass = 'h-3 w-3' const suggestionClass = 'h-4 w-4' export function HintBanner({ type = 'wiki', title, description, highlightText = DEFAULT_HIGHLIGHT, language = 'English', rechargeText, onClose, onGenerate, onRecharge, onLanguageChange, closeIcon, arrowDownSIcon, suggestionIcon, dataStyle, dataTheme, }: HintBannerProps) { const isCreditsType = type === 'credits' const defaultClose = closeIcon ?? const defaultArrow = arrowDownSIcon ?? const defaultSuggestion = suggestionIcon ?? (isCreditsType ? : ) const displayTitle = title ?? (isCreditsType ? 'Credits Exhausted' : 'Free Wiki Generation Available') const descriptionTemplate = isCreditsType ? 'Your credits have been exhausted. Please recharge to continue using.' : `Generate ${highlightText} for this repository to boost AI agent with structured context.` const displayDescription = description ?? descriptionTemplate const renderDescription = (): ReactNode => { if (!displayDescription.includes(highlightText)) { return {displayDescription} } const parts = displayDescription.split(highlightText) const result: ReactNode[] = [] for (let i = 0; i < parts.length; i++) { if (parts[i]) { result.push({parts[i]}) } if (i < parts.length - 1) { result.push( {highlightText} ) } } return <>{result} } return (
{onClose && ( )}
{defaultSuggestion}

{displayTitle}

<> {renderDescription()}
{isCreditsType ? ( rechargeText && ( ) ) : ( <> {LANGUAGES.map((lang) => ( onLanguageChange?.(lang)} > {lang} ))} )}
) } HintBanner.displayName = 'HintBanner'