import { Ref } from 'react';

/**
 * Converts a Markdown string to plain text by stripping all formatting syntax.
 *
 * Handles headings, bold/italic/strikethrough, links, images, blockquotes, code blocks,
 * inline code, tables, and horizontal rules. Inline code content is preserved literally
 * (formatting inside backticks is not stripped).
 *
 * @param markdown - The Markdown source string.
 * @returns A plain-text string with all Markdown syntax removed.
 */
declare function markdownToPlainText(markdown: string): string;

/**
 * Combines multiple React refs into a single callback ref.
 * Useful when a component needs to forward its ref while also keeping a local ref.
 *
 * @param refs - Any number of React refs (callback refs, RefObjects, or `undefined`).
 * @returns A callback ref that updates all provided refs when the DOM node changes.
 */
declare function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): (node: T | null) => void;

/** Structured representation of a parsed markdown table. */
interface MarkdownTable {
    /** Column header labels. */
    columns: string[];
    /** Data rows, each an array of cell values matching the column order. */
    rows: string[][];
    /** Optional title extracted from a `<!-- table-title: ... -->` comment above the table. */
    title?: string;
}
/**
 * Extracts the Nth GFM markdown table from a string.
 * @param markdown - The markdown content to parse.
 * @param tableIndex - Zero-based index of the table to extract.
 * @returns The parsed table, or `null` if no table exists at the given index.
 */
declare function parseMarkdownTable(markdown: string, tableIndex?: number): MarkdownTable | null;

/**
 * Converts a parsed markdown table to a CSV string (RFC 4180).
 * Fields containing commas, double quotes, or newlines are quoted.
 * @param table - The structured table data to convert.
 * @returns A CSV-formatted string with CRLF line endings.
 */
declare function convertTableToCSV(table: MarkdownTable): string;

/**
 * Escapes and optionally quotes a CSV field per RFC 4180, with OWASP-recommended formula-injection
 * neutralisation for fields beginning with a trigger character.
 *
 * - Fields starting with `=`, `+`, `@`, `\t`, or `\r` are prefixed with a tab so the spreadsheet
 *   renders them as literal text instead of evaluating them as a formula. The tab itself disappears
 *   in the rendered cell.
 * - Fields containing commas, double quotes, newlines, or a leading tab (from formula neutralisation)
 *   are wrapped in double quotes per RFC 4180. The double-quote wrapping ensures the tab prefix is
 *   preserved in parsers that would otherwise strip leading whitespace.
 * - Existing double quotes are escaped by doubling them.
 *
 * @param field - The raw field value.
 * @returns The escaped/quoted field string.
 */
declare function escapeCsvField(field: string): string;

export { type MarkdownTable, convertTableToCSV, escapeCsvField, markdownToPlainText, mergeRefs, parseMarkdownTable };
