"use client" import { useState, useCallback } from "react" import { cn } from "@lib/utils" import { dmSansClassName } from "@/lib/fonts" import { ChevronLeft, ChevronRight, Info, Loader2, MessageSquare, Link2, } from "lucide-react" import { Logo } from "@ui/assets/Logo" import { analytics } from "@/lib/analytics" export type HighlightFormat = "paragraph" | "bullets" | "quote" | "one_liner" export interface HighlightItem { id: string title: string content: string format: HighlightFormat query: string sourceDocumentIds: string[] } interface HighlightsCardProps { items: HighlightItem[] onChat: (seed: string) => void onShowRelated: (query: string) => void isLoading?: boolean width?: number } function renderContent(content: string, format: HighlightFormat) { switch (format) { case "bullets": { const lines = content .split("\n") .map((line) => line.replace(/^[-•*]\s*/, "").trim()) .filter(Boolean) return ( ) } case "quote": return (

"{content}"

) case "one_liner": return

{content}

default: return

{content}

} } export function HighlightsCard({ items, onChat, onShowRelated, isLoading = false, width = 216, }: HighlightsCardProps) { const [activeIndex, setActiveIndex] = useState(0) const currentItem = items[activeIndex] const handlePrev = useCallback(() => { setActiveIndex((prev) => (prev > 0 ? prev - 1 : items.length - 1)) }, [items.length]) const handleNext = useCallback(() => { setActiveIndex((prev) => (prev < items.length - 1 ? prev + 1 : 0)) }, [items.length]) const handleChat = useCallback(() => { if (!currentItem) return analytics.highlightClicked({ highlight_id: currentItem.id, action: "chat", }) const seed = `Tell me more about "${currentItem.title}"` onChat(seed) }, [currentItem, onChat]) const handleShowRelated = useCallback(() => { if (!currentItem) return analytics.highlightClicked({ highlight_id: currentItem.id, action: "related", }) onShowRelated(currentItem.query || currentItem.title) }, [currentItem, onShowRelated]) if (isLoading) { return (
Loading highlights...
) } if (!currentItem || items.length === 0) { return (
powered by supermemory

Add some documents to see highlights here

) } return (
powered by supermemory

{currentItem.title}

{renderContent(currentItem.content, currentItem.format)}
{items.length > 1 && (
{items.map((_, idx) => (
)}
) }