import styles from "./BashOutputBlock.module.css";

interface BashOutputBlockProps {
	command?: string;
	content: string;
	exitCode?: number;
	streaming?: boolean;
	excludeFromContext?: boolean;
}

export function BashOutputBlock({
	command,
	content,
	exitCode,
	streaming,
	excludeFromContext,
}: BashOutputBlockProps) {
	const hasOutput = Boolean(content.trim());
	const showExit = exitCode !== undefined && exitCode !== 0 && !streaming;

	return (
		<div className={`${styles.block} ${excludeFromContext ? styles.blockDim : ""}`}>
			<div className={styles.header}>
				<span className={styles.icon} aria-hidden="true">
					<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
						<polyline points="4 17 10 11 4 5" />
						<line x1="12" y1="19" x2="20" y2="19" />
					</svg>
				</span>
				<span className={styles.prompt}>$</span>
				<span className={styles.command}>{command || "shell"}</span>
			</div>
			<pre
				className={`${styles.output} ${!hasOutput ? styles.outputEmpty : ""} ${streaming ? styles.outputStreaming : ""}`}
			>
				{hasOutput ? content : streaming ? "执行中..." : "(无输出)"}
			</pre>
			{showExit ? <div className={styles.exit}>退出码 {exitCode}</div> : null}
		</div>
	);
}
