import type { AssistantBlock } from "../../types/message";
import { renderMarkdown } from "../../utils/markdown";
import styles from "./AssistantTurnBody.module.css";

interface AssistantTurnBodyProps {
	blocks: AssistantBlock[];
	streaming?: boolean;
	showThinking?: boolean;
}

export function AssistantTurnBody({
	blocks,
	streaming = false,
	showThinking = true,
}: AssistantTurnBodyProps) {
	if (blocks.length === 0) return null;

	return (
		<div className={styles.turn}>
			{blocks.map((block, index) => {
				if (block.type === "thinking") {
					if (!showThinking) {
						return (
							<p key={`thinking-${index}`} className={styles.thinkingHidden}>
								Thinking…
							</p>
						);
					}
					return (
						<div
							key={`thinking-${index}`}
							className={`${styles.thinking} ${streaming ? styles.streaming : ""}`}
							dangerouslySetInnerHTML={{ __html: renderMarkdown(block.content) }}
						/>
					);
				}

				return (
					<div
						key={`text-${index}`}
						className={`${styles.text} ${streaming ? styles.streaming : ""}`}
						dangerouslySetInnerHTML={{ __html: renderMarkdown(block.content) }}
					/>
				);
			})}
		</div>
	);
}
