import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useLabel } from '@websolutespa/bom-mixer-hooks';
import { useLlm } from '@websolutespa/bom-mixer-llm';
import { AnimatePresence } from 'framer-motion';
import React, { useMemo } from 'react';
import { chunksToUIChunks } from '../../../utils';
export const PageStream = ({ index, className })=>{
    const label = useLabel();
    const { PageLoading, ChunkWrapper } = useLlm((state)=>state.components);
    const chunks = useLlm((state)=>state.chunks);
    const parsedChunks = useMemo(()=>{
        if (chunks) {
            return chunksToUIChunks(chunks);
        }
        return undefined;
    }, [
        chunks
    ]);
    return /*#__PURE__*/ _jsx(_Fragment, {
        children: parsedChunks && /*#__PURE__*/ _jsx(_Fragment, {
            children: /*#__PURE__*/ _jsx("div", {
                className: className || 'llm__message llm__message--assistant',
                role: "region",
                "aria-label": label('llm.answer'),
                children: /*#__PURE__*/ _jsxs(AnimatePresence, {
                    children: [
                        parsedChunks.map((chunk, c)=>/*#__PURE__*/ _jsx(ChunkWrapper, {
                                className: `llm__inner llm__inner--${chunk.type}`,
                                item: chunk,
                                chunkIndex: c,
                                index: index,
                                total: index + 1,
                                role: "assistant",
                                stream: true
                            }, `llm-message-${index}-chunk-${c}--${chunk.type}`)),
                        /*#__PURE__*/ _jsx(PageLoading, {})
                    ]
                })
            })
        })
    });
};

//# sourceMappingURL=page-stream.js.map