import { isPair as f, isScalar as p, isMap as c } from "./accelbyte-widgets711.mjs";
import { Pair as n, createPair as m } from "./accelbyte-widgets715.mjs";
import { YAMLMap as h, findPair as a } from "./accelbyte-widgets729.mjs";
class l extends h {
  constructor(e) {
    super(e), this.tag = l.tag;
  }
  add(e) {
    let t;
    f(e) ? t = e : e && typeof e == "object" && "key" in e && "value" in e && e.value === null ? t = new n(e.key, null) : t = new n(e, null), a(this.items, t.key) || this.items.push(t);
  }
  get(e, t) {
    const s = a(this.items, e);
    return !t && f(s) ? p(s.key) ? s.key.value : s.key : s;
  }
  set(e, t) {
    if (typeof t != "boolean")
      throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);
    const s = a(this.items, e);
    s && !t ? this.items.splice(this.items.indexOf(s), 1) : !s && t && this.items.push(new n(e));
  }
  toJSON(e, t) {
    return super.toJSON(e, t, Set);
  }
  toString(e, t, s) {
    if (!e)
      return JSON.stringify(this);
    if (this.hasAllNullValues(!0))
      return super.toString(Object.assign({}, e, { allNullValues: !0 }), t, s);
    throw new Error("Set items must all have null values");
  }
  static from(e, t, s) {
    const { replacer: o } = s, u = new this(e);
    if (t && Symbol.iterator in Object(t))
      for (let r of t)
        typeof o == "function" && (r = o.call(t, r, r)), u.items.push(m(r, null, s));
    return u;
  }
}
l.tag = "tag:yaml.org,2002:set";
const S = {
  collection: "map",
  identify: (i) => i instanceof Set,
  nodeClass: l,
  default: !1,
  tag: "tag:yaml.org,2002:set",
  createNode: (i, e, t) => l.from(i, e, t),
  resolve(i, e) {
    if (c(i)) {
      if (i.hasAllNullValues(!0))
        return Object.assign(new l(), i);
      e("Set items must all have null values");
    } else
      e("Expected a mapping for this tag");
    return i;
  }
};
export {
  l as YAMLSet,
  S as set
};
