import { longestStreak as e } from "../../../longest-streak/index.js";
import { formatCodeAsIndented as t } from "../util/format-code-as-indented.js";
import { checkFence as n } from "../util/check-fence.js";
//#region ../../node_modules/mdast-util-to-markdown/lib/handle/code.js
function r(r, a, o, s) {
	let c = n(o), l = r.value || "", u = c === "`" ? "GraveAccent" : "Tilde";
	if (t(r, o)) {
		let e = o.enter("codeIndented"), t = o.indentLines(l, i);
		return e(), t;
	}
	let d = o.createTracker(s), f = c.repeat(Math.max(e(l, c) + 1, 3)), p = o.enter("codeFenced"), m = d.move(f);
	if (r.lang) {
		let e = o.enter(`codeFencedLang${u}`);
		m += d.move(o.safe(r.lang, {
			before: m,
			after: " ",
			encode: ["`"],
			...d.current()
		})), e();
	}
	if (r.lang && r.meta) {
		let e = o.enter(`codeFencedMeta${u}`);
		m += d.move(" "), m += d.move(o.safe(r.meta, {
			before: m,
			after: "\n",
			encode: ["`"],
			...d.current()
		})), e();
	}
	return m += d.move("\n"), l && (m += d.move(l + "\n")), m += d.move(f), p(), m;
}
function i(e, t, n) {
	return (n ? "" : "    ") + e;
}
//#endregion
export { r as code };
