import { jsx as _jsx } from "react/jsx-runtime";
import { marked } from 'marked';
import { useMemo } from 'react';
import style from './waiting-message.module.scss';
export const WaitingMessage = (props)=>{
    const { item } = props;
    const { html, hasBlockElements } = useMemo(()=>{
        const text = item.items.map((x)=>x.text).join('');
        marked.use({
            renderer: {
                link (href, title, text) {
                    return `<a class="llm__text-link" href="${href}" target="_blank" rel="noreferrer"
          ${title ? `title="${title}"` : ''}
          onclick="javascript:event.preventDefault(),window.open(event.currentTarget.href);">
            ${text}
          </a>`;
                },
                image (href, title, text) {
                    return `<a class="llm__text-img" href="${href}" target="_blank" rel="noreferrer"
          onclick="javascript:event.preventDefault(),window.open(event.currentTarget.href);">
            <img src="${href}"${title ? ` title="${title}"` : ''} alt="" />
          </a>`;
                }
            }
        });
        let hasBlockElements = false;
        const html = marked.parse(text, {
            walkTokens: (token)=>{
                // console.log('walkTokens', token);
                if (![
                    'text',
                    'strong',
                    'em',
                    'paragraph',
                    'span',
                    'space'
                ].includes(token.type)) {
                    hasBlockElements = true;
                }
            }
        });
        return {
            html,
            hasBlockElements
        };
    }, [
        item.items
    ]);
    return /*#__PURE__*/ _jsx("div", {
        className: style.waitingMessage,
        children: /*#__PURE__*/ _jsx("div", {
            className: style.html,
            "data-text": true,
            dangerouslySetInnerHTML: {
                __html: html
            }
        })
    });
};

//# sourceMappingURL=waiting-message.js.map