import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { getClassNames } from '@websolutespa/bom-core';
import { useLabel } from '@websolutespa/bom-mixer-hooks';
import { ChunkWrapper, Disclaimer, Feedback, Stream, useLlm } from '@websolutespa/bom-mixer-llm';
import React from 'react';
import style from './thread.module.scss';
export const Thread = ()=>{
    const label = useLabel();
    const enableFeedback = useLlm((state)=>state.app?.contents.enableFeedback);
    const messages = useLlm((state)=>state.messages);
    const hasChunks = useLlm((state)=>state.chunks !== undefined);
    return /*#__PURE__*/ _jsxs("section", {
        className: getClassNames(style.thread, 'llm__container'),
        children: [
            messages.map((message, m)=>/*#__PURE__*/ _jsxs("div", {
                    className: getClassNames(style.threadMessage, message.role === 'user' ? style.threadMessageUser : style.threadMessageAssistant),
                    role: "region",
                    "aria-label": message.role === 'user' ? label('llm.question') : label('llm.answer'),
                    children: [
                        message.chunks.map((chunk, c)=>/*#__PURE__*/ _jsx(ChunkWrapper, {
                                className: getClassNames(style.threadInner, style[chunk.type]),
                                item: chunk,
                                chunkIndex: c,
                                index: m,
                                total: messages.length,
                                role: message.role
                            }, `llm-message-${m}-chunk-${c}`)),
                        message.role === 'user' ? m === 0 && /*#__PURE__*/ _jsx(Disclaimer, {}) : m === messages.length - 1 && enableFeedback && /*#__PURE__*/ _jsx(Feedback, {
                            message: message
                        })
                    ]
                }, `llm-message-${m}`)),
            hasChunks && /*#__PURE__*/ _jsx(Stream, {
                index: messages.length
            })
        ]
    });
};

//# sourceMappingURL=thread.js.map