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