"use client" import { useMemo } from "react" import type { DocumentsWithMemoriesResponseSchema } from "@repo/validation/api" import type { z } from "zod" import { dmSansClassName } from "@/lib/fonts" import { cn } from "@lib/utils" import { NotionDoc, SyncLogoIcon } from "@ui/assets/icons" type DocumentsResponse = z.infer type DocumentWithMemories = DocumentsResponse["documents"][0] // Extract structured blocks from markdown content for a visual preview function parseContentBlocks(content: string) { const lines = content.split("\n").filter((l) => l.trim()) const blocks: { type: "heading" | "text" | "bullet" | "todo" | "divider" text: string checked?: boolean }[] = [] for (const line of lines) { if (blocks.length >= 6) break const trimmed = line.trim() if (trimmed.startsWith("# ")) { blocks.push({ type: "heading", text: trimmed.replace(/^#+\s*/, "") }) } else if (trimmed.startsWith("- [x]") || trimmed.startsWith("- [ ]")) { blocks.push({ type: "todo", text: trimmed.replace(/^- \[.\]\s*/, ""), checked: trimmed.includes("[x]"), }) } else if (trimmed.startsWith("- ") || trimmed.startsWith("* ")) { blocks.push({ type: "bullet", text: trimmed.replace(/^[-*]\s*/, "") }) } else if (trimmed === "---") { blocks.push({ type: "divider", text: "" }) } else if (trimmed.length > 0) { blocks.push({ type: "text", text: trimmed.replace(/\*\*/g, "").replace(/\*/g, "").replace(/`/g, ""), }) } } return blocks } export function NotionPreview({ document, }: { document: DocumentWithMemories }) { const blocks = useMemo( () => parseContentBlocks(document.content || document.summary || ""), [document.content, document.summary], ) return (
{/* Header with Notion branding */}
Notion
{/* Decorative dots mimicking Notion's block handles */}
{/* Content area — structured block preview */}
{document.title && (

{document.title}

)} {blocks.length > 0 ? (
{blocks.map((block, i) => { if (block.type === "divider") { return
} if (block.type === "heading") { return (

{block.text}

) } if (block.type === "todo") { return (
{block.checked && ( )}

{block.text}

) } if (block.type === "bullet") { return (

{block.text}

) } return (

{block.text}

) })}
) : document.summary ? (

{document.summary}

) : null}
{/* Footer */} {(document.memoryEntries.length > 0 || document.createdAt) && (
{document.memoryEntries.length > 0 && (

{document.memoryEntries.length}

)}

{new Date(document.createdAt).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", })}

)}
) }