// Pulls the first line of readable text out of a Tiptap ProseMirror JSON
// document, for note card/list previews.
export function extractNotePreview(content: Record<string, unknown>): string {
  try {
    const doc = content as { content?: Array<{ content?: Array<{ text?: string }> }> };
    if (!doc.content) return "";
    const texts: string[] = [];
    for (const block of doc.content) {
      if (block.content) {
        for (const inline of block.content) {
          if (inline.text) texts.push(inline.text);
        }
      }
      if (texts.length > 0) break;
    }
    return texts.join("").slice(0, 120);
  } catch {
    return "";
  }
}
