import parse from "html-react-parser";
import { deserialize } from "../utils/richTextUtilities";
/**
 * Converts an HTML string to RichTextValue format.
 * Parses the HTML content and transforms it into an array of Descendant objects
 * that can be used by the rich text editor.
 *
 * @param {string} html - HTML string to be converted to rich text format
 * @returns {RichTextValue} Array of Descendant objects representing the parsed content
 *
 * @example
 * ```typescript
 * const richTextService = new RichTextService();
 * const html = "<p><strong>Hello world</strong></p>";
 * const richText = richTextService.toRichTextValue(html);
 * // Returns: [{ type: 'paragraph', children: [{ text: 'Hello world', bold: true }] }]
 * ```
 *
 * @example
 * ```typescript
 * // Handling plain text
 * const plainText = "Simple text";
 * const richText = richTextService.toRichTextValue(plainText);
 * // Returns: [{ text: 'Simple text' }]
 * ```
 */
function toRichTextValue(html) {
    const parsed = parse(html);
    if (Array.isArray(parsed)) {
        return parsed.map((node) => {
            if (typeof node === "string")
                return { text: node };
            return deserialize(node);
        });
    }
    if (typeof parsed === "string")
        return [{ text: parsed }];
    return [deserialize(parsed)];
}
export { toRichTextValue };
