import { createNode as a } from "./accelbyte-widgets721.mjs";
import { stringifyCollection as d } from "./accelbyte-widgets730.mjs";
import { Collection as c } from "./accelbyte-widgets650.mjs";
import { SEQ as p, isScalar as m } from "./accelbyte-widgets711.mjs";
import { isScalarValue as h } from "./accelbyte-widgets651.mjs";
import { toJS as g } from "./accelbyte-widgets716.mjs";
class q extends c {
  static get tagName() {
    return "tag:yaml.org,2002:seq";
  }
  constructor(t) {
    super(p, t), this.items = [];
  }
  add(t) {
    this.items.push(t);
  }
  delete(t) {
    const e = f(t);
    return typeof e != "number" ? !1 : this.items.splice(e, 1).length > 0;
  }
  get(t, e) {
    const i = f(t);
    if (typeof i != "number")
      return;
    const r = this.items[i];
    return !e && m(r) ? r.value : r;
  }
  has(t) {
    const e = f(t);
    return typeof e == "number" && e < this.items.length;
  }
  set(t, e) {
    const i = f(t);
    if (typeof i != "number")
      throw new Error(`Expected a valid index, not ${t}.`);
    const r = this.items[i];
    m(r) && h(e) ? r.value = e : this.items[i] = e;
  }
  toJSON(t, e) {
    const i = [];
    e != null && e.onCreate && e.onCreate(i);
    let r = 0;
    for (const s of this.items)
      i.push(g(s, String(r++), e));
    return i;
  }
  toString(t, e, i) {
    return t ? d(this, t, {
      blockItemPrefix: "- ",
      flowChars: { start: "[", end: "]" },
      itemIndent: (t.indent || "") + "  ",
      onChompKeep: i,
      onComment: e
    }) : JSON.stringify(this);
  }
  static from(t, e, i) {
    const { replacer: r } = i, s = new this(t);
    if (e && Symbol.iterator in Object(e)) {
      let l = 0;
      for (let o of e) {
        if (typeof r == "function") {
          const u = e instanceof Set ? o : String(l++);
          o = r.call(e, u, o);
        }
        s.items.push(a(o, void 0, i));
      }
    }
    return s;
  }
}
function f(n) {
  let t = m(n) ? n.value : n;
  return t && typeof t == "string" && (t = Number(t)), typeof t == "number" && Number.isInteger(t) && t >= 0 ? t : null;
}
export {
  q as YAMLSeq
};
