import { Text, View } from '@react-pdf/renderer' import type { ReactElement } from 'react' import type { Snapshot } from 'valtio' import { type QueryResult } from '../types' import { NotebookPdfChart } from './NotebookPdfChart' import { NotebookPdfTable } from './NotebookPdfTable' import { pdfStyles } from './theme' import { formatTimeRange } from '@/components/ui/AIAssistantPanel/AssistantNotebookPreview.utils' import { type QueryCell } from '@/data/content/notebooks/notebook-schema' import { pluralize } from '@/lib/helpers' function SqlBlock({ sql }: { sql: string }) { return ( {sql} ) } function ResultsTable({ rows }: { rows: readonly Record[] }) { return ( ) } function QueryResultsSection({ result, view, chart, }: { result: QueryResult | undefined view: 'table' | 'chart' chart: Snapshot['chart'] }): ReactElement { if (!result) { return ( Query has not been run. ) } if (result.error) { return ( Error: {result.error.message} ) } const rows = result.rows ?? [] if (rows.length === 0) { return ( Success. No rows returned ) } if (view === 'chart') { return ( ) } return } interface NotebookPdfQueryCellProps { cell: Snapshot result: QueryResult | undefined } export function NotebookPdfQueryCell({ cell, result }: NotebookPdfQueryCellProps) { const view = cell.view ?? 'table' const rowCount = result?.rows?.length ?? 0 const rowLimit = cell._tag === 'database_cell' ? cell.row_limit : undefined return ( {cell.title ?? 'Untitled query'} {cell._tag === 'log_cell' && ( // react-pdf's default font (Helvetica) can't render the '→' from formatTimeRange {formatTimeRange(cell.time_range).replace('→', '-')} )} {rowCount.toLocaleString()} {pluralize(rowCount, 'row')} {rowLimit !== undefined && ( <> · {rowLimit < 0 ? 'No row limit' : `Limit ${rowLimit} rows`} )} ) }