import { isNode as g } from "./accelbyte-widgets711.mjs";
import { createStringifyContext as a, stringify as h } from "./accelbyte-widgets740.mjs";
import { indentComment as r, lineComment as v } from "./accelbyte-widgets741.mjs";
function S(t, c) {
  var u;
  const e = [];
  let m = c.directives === !0;
  if (c.directives !== !1 && t.directives) {
    const n = t.directives.toString(t);
    n ? (e.push(n), m = !0) : t.directives.docStart && (m = !0);
  }
  m && e.push("---");
  const o = a(t, c), { commentString: f } = o.options;
  if (t.commentBefore) {
    e.length !== 1 && e.unshift("");
    const n = f(t.commentBefore);
    e.unshift(r(n, ""));
  }
  let l = !1, s = null;
  if (t.contents) {
    if (g(t.contents)) {
      if (t.contents.spaceBefore && m && e.push(""), t.contents.commentBefore) {
        const p = f(t.contents.commentBefore);
        e.push(r(p, ""));
      }
      o.forceBlockIndent = !!t.comment, s = t.contents.comment;
    }
    const n = s ? void 0 : () => l = !0;
    let i = h(t.contents, o, () => s = null, n);
    s && (i += v(i, "", f(s))), (i[0] === "|" || i[0] === ">") && e[e.length - 1] === "---" ? e[e.length - 1] = `--- ${i}` : e.push(i);
  } else
    e.push(h(t.contents, o));
  if ((u = t.directives) != null && u.docEnd)
    if (t.comment) {
      const n = f(t.comment);
      n.includes(`
`) ? (e.push("..."), e.push(r(n, ""))) : e.push(`... ${n}`);
    } else
      e.push("...");
  else {
    let n = t.comment;
    n && l && (n = n.replace(/^\n+/, "")), n && ((!l || s) && e[e.length - 1] !== "" && e.push(""), e.push(r(f(n), "")));
  }
  return e.join(`
`) + `
`;
}
export {
  S as stringifyDocument
};
