import { LogViewer as e } from "../editors/log-viewer.js";
import { t } from "../utils-B7XIe3qq.js";
import * as n from "react";
import { jsx as r } from "react/jsx-runtime";
//#region src/primitives/live-log-tail.tsx
var i = n.forwardRef(function({ lines: i, maxLines: a, follow: o = !0, lineParser: s, onScrollAway: c, className: l, ...u }, d) {
	let f = n.useRef(null), p = n.useRef(null), m = n.useRef(s), h = n.useRef(c);
	return n.useEffect(() => {
		m.current = s;
	}, [s]), n.useEffect(() => {
		h.current = c;
	}, [c]), n.useEffect(() => {
		let t = f.current;
		if (!t) return;
		let n = new e({
			container: t,
			maxLines: a ?? 1e4,
			followMode: o,
			severityColors: !0,
			value: i && i.length > 0 ? i.join("\n") : ""
		});
		p.current = n;
		let r = n.getView().scrollDOM, s = !1, c = () => {
			let e = r.scrollHeight - (r.scrollTop + r.clientHeight) > 16;
			e && !s ? (s = !0, h.current?.()) : !e && s && (s = !1);
		};
		return r.addEventListener("scroll", c, { passive: !0 }), () => {
			r.removeEventListener("scroll", c), n.destroy(), p.current = null;
		};
	}, []), n.useEffect(() => {
		p.current?.setFollowMode(o);
	}, [o]), n.useEffect(() => {
		typeof a == "number" && p.current?.setMaxLines(a);
	}, [a]), n.useImperativeHandle(d, () => ({
		append(e) {
			let t = p.current;
			if (!t) return;
			let n = m.current;
			if (n) {
				let r = n(e);
				t.appendLine(r.text, r.severity);
			} else t.appendLine(e);
		},
		clear() {
			p.current?.clear();
		}
	}), []), /* @__PURE__ */ r("div", {
		ref: f,
		"data-slot": "live-log-tail",
		className: t("cmm-live-log-tail relative h-full min-h-[200px] w-full overflow-hidden rounded-md border border-border bg-muted/40 font-mono text-xs", l),
		...u
	});
});
//#endregion
export { i as LiveLogTail };

//# sourceMappingURL=live-log-tail.js.map