import { isSeq as p, isPair as f, isMap as u } from "./accelbyte-widgets711.mjs";
import { createPair as y, Pair as l } from "./accelbyte-widgets715.mjs";
import { Scalar as g } from "./accelbyte-widgets651.mjs";
import { YAMLSeq as h } from "./accelbyte-widgets731.mjs";
function k(r, i) {
  if (p(r))
    for (let n = 0; n < r.items.length; ++n) {
      let e = r.items[n];
      if (!f(e)) {
        if (u(e)) {
          e.items.length > 1 && i("Each pair must have its own sequence indicator");
          const o = e.items[0] || new l(new g(null));
          if (e.commentBefore && (o.key.commentBefore = o.key.commentBefore ? `${e.commentBefore}
${o.key.commentBefore}` : e.commentBefore), e.comment) {
            const m = o.value ?? o.key;
            m.comment = m.comment ? `${e.comment}
${m.comment}` : e.comment;
          }
          e = o;
        }
        r.items[n] = f(e) ? e : new l(e);
      }
    }
  else
    i("Expected a sequence for this tag");
  return r;
}
function w(r, i, n) {
  const { replacer: e } = n, o = new h(r);
  o.tag = "tag:yaml.org,2002:pairs";
  let m = 0;
  if (i && Symbol.iterator in Object(i))
    for (let t of i) {
      typeof e == "function" && (t = e.call(i, String(m++), t));
      let c, a;
      if (Array.isArray(t))
        if (t.length === 2)
          c = t[0], a = t[1];
        else
          throw new TypeError(`Expected [key, value] tuple: ${t}`);
      else if (t && t instanceof Object) {
        const s = Object.keys(t);
        if (s.length === 1)
          c = s[0], a = t[c];
        else
          throw new TypeError(`Expected { key: value } tuple: ${t}`);
      } else
        c = t;
      o.items.push(y(c, a, n));
    }
  return o;
}
const E = {
  collection: "seq",
  default: !1,
  tag: "tag:yaml.org,2002:pairs",
  resolve: k,
  createNode: w
};
export {
  w as createPairs,
  E as pairs,
  k as resolvePairs
};
