import { Alias as A } from "./accelbyte-widgets714.mjs";
import { composeCollection as d } from "./accelbyte-widgets752.mjs";
import { composeScalar as p } from "./accelbyte-widgets753.mjs";
import { resolveEnd as g } from "./accelbyte-widgets713.mjs";
import { emptyScalarPosition as b } from "./accelbyte-widgets754.mjs";
const y = { composeNode: h, composeEmptyNode: u };
function h(n, e, i, t) {
  const { spaceBefore: r, comment: a, anchor: s, tag: o } = i;
  let c, l = !0;
  switch (e.type) {
    case "alias":
      c = S(n, e, t), (s || o) && t(e, "ALIAS_PROPS", "An alias node must not specify any properties");
      break;
    case "scalar":
    case "single-quoted-scalar":
    case "double-quoted-scalar":
    case "block-scalar":
      c = p(n, e, o, t), s && (c.anchor = s.source.substring(1));
      break;
    case "block-map":
    case "block-seq":
    case "flow-collection":
      c = d(y, n, e, o, t), s && (c.anchor = s.source.substring(1));
      break;
    default: {
      const f = e.type === "error" ? e.message : `Unsupported token (type: ${e.type})`;
      t(e, "UNEXPECTED_TOKEN", f), c = u(n, e.offset, void 0, null, i, t), l = !1;
    }
  }
  return s && c.anchor === "" && t(s, "BAD_ALIAS", "Anchor cannot be an empty string"), r && (c.spaceBefore = !0), a && (e.type === "scalar" && e.source === "" ? c.comment = a : c.commentBefore = a), n.options.keepSourceTokens && l && (c.srcToken = e), c;
}
function u(n, e, i, t, { spaceBefore: r, comment: a, anchor: s, tag: o, end: c }, l) {
  const f = {
    type: "scalar",
    offset: b(e, i, t),
    indent: -1,
    source: ""
  }, m = p(n, f, o, l);
  return s && (m.anchor = s.source.substring(1), m.anchor === "" && l(s, "BAD_ALIAS", "Anchor cannot be an empty string")), r && (m.spaceBefore = !0), a && (m.comment = a, m.range[2] = c), m;
}
function S({ options: n }, { offset: e, source: i, end: t }, r) {
  const a = new A(i.substring(1));
  a.source === "" && r(e, "BAD_ALIAS", "Alias cannot be an empty string"), a.source.endsWith(":") && r(e + i.length - 1, "BAD_ALIAS", "Alias ending in : is ambiguous", !0);
  const s = e + i.length, o = g(t, s, n.strict, r);
  return a.range = [e, s, o.offset], o.comment && (a.comment = o.comment), a;
}
export {
  u as composeEmptyNode,
  h as composeNode
};
