class O {
  constructor(t, e) {
    this.formBuilder = t, this.conditionFactory = e, this.registeredConstructors = {};
  }
  createComponent(t, e = null) {
    if (typeof t.type != "string") throw new Error("Type is not a string");
    if (typeof this.registeredConstructors[t.type] != "function")
      return console.warn(`Component ${t.type} is not registered`), null;
    const s = {};
    s.parent = e, s.formBuilder = this.formBuilder;
    const i = t.idPrefix ?? e?.idPrefix ?? "";
    s.idPrefix = i, s.id = t.id;
    const a = this.registeredConstructors[t.type](t, s);
    return a == null ? (console.warn(`Component ${t.type} could not be created`), null) : (this.formBuilder.registry[i + t.id] = a, this.formBuilder.onClean.add(() => a.cleanHtml()), this.formBuilder.onComponentsCreated.add(() => a.checkVisibility()), t.conditions.forEach((r) => {
      let o = this.conditionFactory.createCondition(r);
      o !== null && (o.idPrefix = i, a.addConditions(o));
    }), a);
  }
  registerConstructor(t, e) {
    return this.registeredConstructors[t] = e, this;
  }
}
function I(n, t = !0) {
  const e = n.getAttribute("data-pad-visibility-change-id");
  e && clearTimeout(parseInt(e)), n.classList.remove("pad-hidden"), n.classList.remove("pad-hiding"), n.style.opacity = "0", n.style.transition = "opacity 0.5s, max-height 0.5s", t && (n.style.maxHeight = "0", n.style.overflow = "hidden"), setTimeout(() => {
    n.style.opacity = "", t && (n.style.maxHeight = n.scrollHeight + "px");
  });
  const s = setTimeout(() => {
    n.style.transition = "", t && (n.style.maxHeight = "", n.style.overflow = "");
  }, 510);
  n.setAttribute("data-pad-visibility-change-id", s.toString());
}
function S(n, t = !0) {
  const e = n.getAttribute("data-pad-visibility-change-id");
  e && clearTimeout(parseInt(e)), n.style.transition = "opacity 0.5s, max-height 0.5s", n.classList.add("pad-hiding"), t && (n.style.maxHeight = n.scrollHeight + "px", n.style.overflow = "hidden"), setTimeout(() => {
    n.style.opacity = "0", t && (n.style.maxHeight = "0");
  });
  const s = setTimeout(() => {
    n.style.transition = "", n.style.opacity = "", t && (n.style.maxHeight = "", n.style.overflow = ""), n.classList.add("pad-hidden"), n.classList.remove("pad-hiding");
  }, 510);
  n.setAttribute("data-pad-visibility-change-id", s.toString());
}
function u(n, t, e = !0) {
  k(n) !== t && (t ? I(n, e) : S(n, e));
}
function k(n) {
  return !(n.classList.contains("pad-hidden") || n.classList.contains("pad-hiding"));
}
class C {
  constructor(t = {}) {
    this.placedHtml = [], this.conditions = [], this._visible = !1, this.parent = null, Object.assign(this, t);
  }
  cleanHtml() {
    this.placedHtml.forEach((t) => t.remove());
  }
  addConditions(...t) {
    return t.forEach((e) => {
      this.conditions.push(e), e.onChange.add(() => this.checkVisibility());
    }), this;
  }
  checkVisibility(t = null) {
    t !== this._visible && (t === !1 && (this._visible = !1), (t === !0 || t === null) && (this._visible = this.conditions.every((e) => e.check())), this.updateVisibility());
  }
  updateVisibility() {
    this.placedHtml.forEach((t) => u(t, this.visible));
  }
  get visible() {
    return this._visible;
  }
  getOwnerForm() {
    let t = this.parent;
    for (; t !== null && !(t instanceof y); )
      t = t.parent;
    return t === null ? this.formBuilder.form : t;
  }
}
class c extends C {
  constructor(t = {}) {
    super(t), this.contents = [], this.classes = [], this.index = null, this.displayDefaultNotice = null, Object.assign(this, t);
  }
  cleanHtml() {
    this.contents.forEach((t) => t.cleanHtml()), super.cleanHtml();
  }
  updateVisibility() {
    super.updateVisibility(), this.dataNode.isVisible = this.visible;
  }
  addStandardContainerProperties(t) {
    this.index != null && t.classList.add("pad-" + this.index), t.classList.add("pad-form-group", ...this.classes), t.classList.toggle("pad-invalid", !this.dataNode.isValid), t.classList.toggle("pad-hidden", !this.visible), this.dataNode.onValidChange.add((e) => {
      t.classList.toggle("pad-invalid", !e.isValid);
    }), this.dataNode.onServerSideErrorsChange.add((e) => {
      t.classList.toggle("pad-server-side-errors", e.errors.length !== 0);
    });
  }
  addChildren(...t) {
    return t.forEach((e) => {
      this.contents.push(e);
    }), this;
  }
  setDataNode(t) {
    return this.dataNode = t, this;
  }
  getDataNode() {
    return this.dataNode;
  }
  get isDisplayDefaultNotice() {
    return this.displayDefaultNotice ?? this.parent?.isDisplayDefaultNotice ?? !1;
  }
}
class l {
  constructor() {
    this.eventRegistry = [];
  }
  add(t) {
    this.eventRegistry.push(t);
  }
  remove(t) {
    this.eventRegistry = this.eventRegistry.filter((e) => e !== t);
  }
  emit(t) {
    for (let e = 0; e < this.eventRegistry.length; e++)
      this.eventRegistry[e](t);
  }
  clear() {
    this.eventRegistry = [];
  }
}
class y extends c {
  constructor(t = {}) {
    super(t), this.onSubmittingChange = new l(), this.onMessageChange = new l(), this.onFormChange = new l(), this.forceDivElement = !1, this.name = "", this.displayDefaultNotice = !1, this.isDefaultText = "", this.isChangedText = "", this.resetButtonText = "", this.writeDefaultData = !1, this.useHiddenFieldForJson = !1, Object.assign(this, t);
  }
  placeHtml(t) {
    let e = "form";
    if (this.forceDivElement)
      e = "div";
    else {
      let i = t;
      for (; i; ) {
        if (i.tagName === "FORM") {
          e = "div";
          break;
        }
        i = i.parentElement;
      }
    }
    const s = document.createElement(e);
    if (s.classList.add(...this.classes, "pad-form-" + this.name, "pad-form", "pad-form-group"), t.append(s), this.placedHtml.push(s), this.useHiddenFieldForJson) {
      const i = document.createElement("input");
      i.style.display = "none", i.type = "hidden", i.name = (this.index ?? this.name) + "[dataJson]", i.value = JSON.stringify(this.getDataNode().value), this.dataNode.onChange.add(() => {
        i.value = JSON.stringify(this.getDataNode().value), i.dispatchEvent(new Event("change", { bubbles: !0, cancelable: !1 }));
      }), s.append(i);
    }
    this.contents.forEach((i) => i.placeHtml(s)), this.dataNode.onChange.add(() => {
      this.onFormChange.emit(null);
    }), this.dataNode.onValidChange.add((i) => {
      s.classList.toggle("pad-invalid", !i.isValid);
    }), s.addEventListener("submit", (i) => {
      i.preventDefault();
    });
  }
  submit() {
    if (this.dataNode.validate(!0), !this.dataNode.isValid) {
      console.warn("Form is not valid so cannot be submitted"), this.onMessageChange.emit(new x("Niet alle velden zijn geldig, check de bovenstaande velden en probeer het opnieuw."));
      return;
    }
    this.submitStrategy.submit(this.writeDefaultData ? this.getDataNode().valueOrDefault : this.getDataNode().value);
  }
  getFormBuilder() {
    return this.formBuilder;
  }
  getPlacedHtml() {
    return this.placedHtml;
  }
  set submitting(t) {
    this.onSubmittingChange.emit(new H(t));
  }
  set message(t) {
    this.onMessageChange.emit(new x(t));
  }
  set serverSideErrors(t) {
    this.dataNode.serverSideErrors = t;
  }
}
let x = class {
  constructor(t = null) {
    this.message = t;
  }
};
class H {
  constructor(t = !1) {
    this.submitting = t;
  }
}
class m {
  constructor() {
    this.validators = [], this.onChange = new l();
  }
  addValidator(...t) {
    this.validators.push(...t), t.forEach(
      (e) => e.onChange.add(() => this.onChange.emit(null))
    );
  }
  validate(t) {
    let e = !0, s = [];
    return this.validators.forEach(
      (i) => {
        let a = i.validate(t);
        a !== !0 && (e = !1, s.push(a));
      }
    ), e ? !0 : s;
  }
}
class w extends m {
  sanitize(t) {
    if (t == null) return t;
    if (typeof t == "number") return t !== 0;
    if (typeof t == "boolean") return t;
    if (typeof t == "string") return this.getFromString(t);
    throw console.warn("Value is not a boolean"), console.warn(t), new Error("Value is not a boolean");
  }
  getFromString(t) {
    return t = t.toLowerCase(), t === "true" || t === "1" || t === "on" || t === "yes" || t === "y" || t === "ja";
  }
}
class D extends m {
  sanitize(t) {
    if (t === "") return null;
    if (t == null || typeof t == "number") return t;
    if (typeof t == "boolean") return t ? 1 : 0;
    if (typeof t == "string" && !isNaN(parseFloat(t))) return parseFloat(t);
    throw console.warn("Value is not a number"), console.warn(t), new Error("Value is not a number");
  }
}
class B extends m {
  sanitize(t) {
    if (t == null || typeof t == "object") return t;
    throw console.warn("Value is not an object"), console.warn(t), new Error("Value is not an object");
  }
}
class _ extends m {
  sanitize(t) {
    if (t === "") return null;
    if (t == null) return t;
    if (typeof t == "number") return "" + t;
    if (typeof t == "boolean") return t ? "1" : "0";
    if (typeof t == "string") return t;
    throw console.warn("Value is not a string"), console.warn(t), new Error("Value is not a string");
  }
}
class P extends m {
  constructor(t) {
    super(), this.subDataType = t, this.subDataType.onChange.add(() => this.onChange.emit(null));
  }
  sanitize(t) {
    if (t == null) return t;
    if (!Array.isArray(t))
      throw console.warn("Value is not an array"), console.warn(t), new Error("Value is not an array");
    return t = t.map((e) => this.subDataType.sanitize(e)), t;
  }
  validate(t) {
    let e = !0, s = [];
    return t && t.forEach((i) => {
      let a = this.subDataType.validate(i);
      a !== !0 && (e = !1, s.push(...a));
    }), this.validators.forEach(
      (i) => {
        let a = i.validate(t);
        a !== !0 && (e = !1, s.push(a));
      }
    ), e ? !0 : s;
  }
}
class R {
  constructor(t) {
    this.validatorFactory = t, this.registeredConstructors = {};
  }
  createDataNode(t, e) {
    if (typeof t.type != "string") throw new Error("Type is not a string");
    if (typeof this.registeredConstructors[t.type] == "function") {
      let s = this.registeredConstructors[t.type](t, e);
      for (let i of t.validators) {
        i.idPrefix = e.idPrefix ?? "";
        const a = this.validatorFactory.createValidator(i);
        a !== null && s.addValidator(a);
      }
      return s;
    }
    return null;
  }
  registerConstructor(t, e) {
    return this.registeredConstructors[t] = e, this;
  }
  setDefaults() {
    return this.registerConstructor("bool", () => new w()), this.registerConstructor("int", () => new D()), this.registerConstructor("float", () => new D()), this.registerConstructor("object", () => new B()), this.registerConstructor("string", () => new _()), this.registerConstructor("array", (t, e) => new P(
      this.createDataNode(
        t.subType ?? { type: "bool", validators: [] },
        e
      ) ?? new w()
    )), this;
  }
}
class T {
  constructor(t = {}) {
    this.errorMessage = "", this.checkName = "", this.conditions = [], this._isValid = !0, this.onChange = new l(), Object.assign(this, t);
  }
  addConditions(...t) {
    this.conditions.push(...t), t.forEach(
      (e) => e.onChange.add((s) => this.checkConditions(s))
    );
  }
  checkConditions(t = null) {
    if (this._isValid !== t) {
      if (t === !1) {
        this.isValid = !1;
        return;
      }
      this.isValid = this.conditions.every((e) => e.check());
    }
  }
  set isValid(t) {
    this._isValid !== t && (this._isValid = t, this.onChange.emit(null));
  }
}
class j extends T {
  constructor(t = {}) {
    super(t), this.zeroIsInvalid = !1, Object.assign(this, t);
  }
  validate(t) {
    return this._isValid ? t == null ? this.errorMessage : typeof t == "string" && t.trim() === "" ? this.errorMessage : typeof t == "number" && (isNaN(t) || this.zeroIsInvalid && t === 0) ? this.errorMessage : typeof t == "boolean" && !t ? this.errorMessage : typeof t == "object" && Object.keys(t).length === 0 ? this.errorMessage : Array.isArray(t) && t.length === 0 ? this.errorMessage : !0 : !0;
  }
}
function M(n) {
  return n.type === "required";
}
function A(n) {
  n.registerConstructor("required", (t, e) => {
    if (!M(t)) return null;
    const s = e;
    return s.zeroIsInvalid = t.zeroIsInvalid, new j(s);
  });
}
class q extends T {
  constructor(t = {}) {
    super(t), this.regex = "", Object.assign(this, t);
  }
  validate(t) {
    return !this._isValid || typeof t == "string" && t.trim() === "" ? !0 : typeof t == "string" && !new RegExp(this.regex).test(t.trim()) ? this.errorMessage : !0;
  }
}
function z(n) {
  return n.type === "regex";
}
function $(n) {
  n.registerConstructor("regex", (t, e) => {
    if (!z(t)) return null;
    const s = e;
    return s.regex = t.regex, new q(s);
  });
}
class Q {
  constructor(t) {
    this.conditionFactory = t, this.registeredConstructors = {};
  }
  createValidator(t) {
    if (typeof t.type != "string") throw new Error("Type is not a string");
    if (typeof this.registeredConstructors[t.type] != "function") return null;
    const e = {};
    e.errorMessage = t.errorMessage, e.checkName = t.checkName;
    const s = this.registeredConstructors[t.type](t, e);
    return s == null ? (console.warn(`Validator ${t.type} could not be created`), null) : (t.conditions.forEach((i) => {
      let a = this.conditionFactory.createCondition(i);
      a !== null && (a.idPrefix = t.idPrefix ?? "", s.addConditions(a));
    }), s.checkConditions(), s);
  }
  registerConstructor(t, e) {
    return this.registeredConstructors[t] = e, this;
  }
  setDefaults() {
    return A(this), $(this), this;
  }
}
class K {
  constructor(t = {}) {
    this.idPrefix = "", this.onChange = new l(), Object.assign(this, t);
  }
}
class h extends C {
  constructor(t) {
    super(t), this.name = "", this.autocomplete = "", this.description = "", this.index = "", this.questionId = "", this._value = void 0, this.onChange = new l(), this.onReset = new l(), Object.assign(this, t), this.questionId = `pad-${Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)}`;
  }
  getFullPathName() {
    let t = this.index, e = "", s = this.parent;
    for (; s != null; )
      s.index != null && (e = `[${t}]${e}`, t = s.index), s = s.parent;
    return t + e;
  }
  getQuestionContainer() {
    const t = document.createElement("label");
    t.classList.add(
      "pad-input",
      "pad-form-index-" + this.index
    ), this.dataNode.onValidChange.add((s) => {
      t.classList.toggle("pad-invalid", !s.isValid);
    }), this.dataNode.onServerSideErrorsChange.add((s) => {
      t.classList.toggle("pad-server-side-errors", s.errors.length !== 0);
    }), t.append(
      this.getWarningsAreaElement()
    ), (this.parent?.isDisplayDefaultNotice ?? !1) && t.append(this.getNoticesElement());
    const e = this.getInputElement();
    return e.classList.add("pad-input-field"), e.id = this.questionId, t.append(
      this.getLabelElement(),
      e,
      this.getDescriptionElement()
    ), t;
  }
  getLabelElement() {
    const t = document.createElement("label");
    return t.innerText = this.name, t.htmlFor = this.questionId, t.classList.add("pad-label"), t;
  }
  getDescriptionElement() {
    const t = document.createElement("p");
    return t.innerText = this.description, t.classList.add("pad-description"), t;
  }
  getNoticesElement() {
    const t = document.createElement("p");
    t.classList.add("pad-notice-area");
    const e = document.createElement("span");
    e.classList.add("pad-notice");
    const s = document.createElement("a");
    return s.innerText = this.getOwnerForm().resetButtonText, s.href = "#", s.classList.add("pad-reset-text"), s.addEventListener("click", () => {
      this.dataNode.resetValue();
    }), t.append(e), t.append(s), this.dataNode.onChange.add(() => {
      this.dataNode.isChanged ? (e.innerText = this.getOwnerForm().isChangedText, s.classList.remove("pad-hidden")) : (e.innerText = this.getOwnerForm().isDefaultText, s.classList.add("pad-hidden"));
    }), this.dataNode.isChanged ? (e.innerText = this.getOwnerForm().isChangedText, s.classList.remove("pad-hidden")) : (e.innerText = this.getOwnerForm().isDefaultText, s.classList.add("pad-hidden")), t;
  }
  getWarningsAreaElement() {
    const t = document.createElement("ul");
    t.classList.add(
      "pad-warning",
      "pad-hidden"
    );
    let e = [], s = [];
    const i = () => {
      t.innerHTML = "", e.forEach((a) => {
        const r = document.createElement("li");
        r.classList.add("pad-data-error"), r.innerText = a, t.append(r);
      }), s.forEach((a) => {
        const r = document.createElement("li");
        r.classList.add("pad-server-side-error"), r.innerText = a, t.append(r);
      }), t.classList.toggle("pad-hidden", e.length + s.length === 0);
    };
    return this.dataNode.onMessagesChange.add((a) => {
      e = [], a.messages.forEach((r) => {
        e.push(r);
      }), i();
    }), this.dataNode.onServerSideErrorsChange.add((a) => {
      s = [], a.errors.forEach((r) => {
        s.push(r);
      }), i();
    }), t;
  }
  setDataNode(t) {
    return this.dataNode = t, this;
  }
  getDataNode() {
    return this.dataNode;
  }
  saveValue() {
    this.dataNode.value = this._value;
  }
  set value(t) {
    this._value !== t && (this._value = t, this.onChange.emit(new J(t)));
  }
  updateVisibility() {
    super.updateVisibility(), this.dataNode.isVisible = this.visible;
  }
}
let J = class {
  constructor(t) {
    this.value = t;
  }
};
class W extends K {
  constructor(t) {
    super(t), this.targetValue = null, this.equals = !1, this.greaterThan = !1, this.smallerThan = !1, this.not = !1, this.field = "", this._isValid = !1, Object.assign(this, t), this.formBuilder.onComponentsCreated.add(() => {
      const e = this.formBuilder.registry[this.field] ?? this.formBuilder.registry[this.idPrefix + this.field];
      if (!(e instanceof c || e instanceof h)) {
        this.check(), console.warn("Field " + this.field + " is not an input or structure");
        return;
      }
      e.getDataNode().onChange.add(() => {
        this.check();
      }), this.check();
    });
  }
  set isValid(t) {
    t !== this._isValid && (this._isValid = t, this.onChange.emit(this._isValid));
  }
  get isValid() {
    return this._isValid;
  }
  check() {
    const t = this.formBuilder.registry[this.field];
    if (!(t instanceof c || t instanceof h))
      return this.isValid = !0, !0;
    const e = t.getDataNode().valueOrDefault;
    let s = !0;
    return this.targetValue === null || this.targetValue === void 0 ? !0 : (this.equals && (s = typeof e == "object" ? Object.is(e, this.targetValue) : e == this.targetValue), this.greaterThan && (s = s && e > this.targetValue), this.smallerThan && (s = s && e < this.targetValue), this.not && (s = !s), this.isValid = s, s);
  }
}
function G(n) {
  n.registerConstructor("inputValueCondition", (t, e) => {
    if (!U(t)) return null;
    const s = e;
    return s.targetValue = t.targetValue, s.equals = t.equals, s.greaterThan = t.greaterThan, s.smallerThan = t.smallerThan, s.not = t.not, s.field = t.field, new W(s);
  });
}
function U(n) {
  return n.type === "inputValueCondition";
}
class X {
  constructor(t) {
    this.formBuilder = t, this.registeredConstructors = {};
  }
  createCondition(t) {
    if (typeof t.type != "string") throw new Error("Type is not a string");
    if (typeof this.registeredConstructors[t.type] != "function") return null;
    const e = {};
    return e.formBuilder = this.formBuilder, this.registeredConstructors[t.type](t, e);
  }
  registerConstructor(t, e) {
    return this.registeredConstructors[t] = e, this;
  }
  setDefaults() {
    return G(this), this;
  }
}
class V {
  constructor(t, e = void 0) {
    this.dataNode = t, this.value = e;
  }
}
class f {
  constructor(t, e) {
    this.isValueValid = t, this.isVisible = e;
  }
  get isValid() {
    return !this.isVisible || this.isValueValid;
  }
}
class v {
  constructor(t) {
    this.errors = t;
  }
}
class Y {
  constructor() {
    this.onChange = new l(), this.onValidChange = new l(), this.onServerSideErrorsChange = new l(), this.parent = null, this.children = [], this.index = null, this.containsExtraData = !1, this.dataStorage = {}, this._serverSideErrors = [], this._isValid = !0, this._isVisible = !0;
  }
  validate(t = !1) {
    let e = !0;
    for (const s in this.children)
      t && this.children[s].validate(!0), e = e && this.children[s].isValid;
    this.isValid = e;
  }
  addChildren(...t) {
    t.forEach((e) => {
      this.children.includes(e) || (this.children.push(e), e.parent = this, e.onChange.add((s) => this.runChange(s)), e.onValidChange.add(() => this.validate()));
    });
  }
  runChange(t = null) {
    this.validate(), this.onChange.emit(t ?? new V(this));
  }
  removeChild(t) {
    for (const e in this.children)
      this.children[e] === t && (delete this.children[e], t.parent = null, t.onChange.remove(() => this.runChange()), t.onValidChange.remove(() => this.validate()));
  }
  set isValid(t) {
    this._isValid !== t && (this._isValid = t, this.onValidChange.emit(new f(this._isValid, this._isVisible)));
  }
  set isVisible(t) {
    this._isVisible !== t && (this._isVisible = t, this.onValidChange.emit(new f(this._isValid, this._isVisible)));
  }
  get isValid() {
    return !this._isVisible || this._isValid;
  }
  get isChanged() {
    if (this.containsExtraData) return !0;
    for (const t in this.children)
      if (this.children[t].isChanged) return !0;
    return !1;
  }
  set value(t) {
    if (typeof t != "object" || t == null) return;
    let e = {};
    for (const s in this.children) {
      if (this.children[s].index === null) {
        this.children[s].value = t;
        continue;
      }
      t[this.children[s].index] !== void 0 && (this.children[s].value = t[this.children[s].index]);
    }
    for (const s in this.children)
      this.children[s].index === null ? Object.assign(e, this.children[s].valueOrDefault) : e[this.children[s].index] = this.children[s].valueOrDefault;
    if (this.index != null || this.parent == null) {
      this.dataStorage = {}, this.containsExtraData = !1;
      for (const s in t)
        e[s] === void 0 && (this.containsExtraData = !0, this.dataStorage[s] = t[s], this.dataStorage[s] = t[s]);
    }
    this.runChange();
  }
  set serverSideErrors(t) {
    if (typeof t != "object" || t == null) {
      this._serverSideErrors = [], this.onServerSideErrorsChange.emit(new v([]));
      for (const s in this.children)
        this.children[s].serverSideErrors = null;
      return;
    }
    const e = [];
    for (const s in this.children) {
      if (this.children[s].index === null) {
        this.children[s].serverSideErrors = t, this.children[s].serverSideErrors.forEach((i) => e.push(i));
        continue;
      }
      this.children[s].serverSideErrors = t[this.children[s].index], this.children[s].serverSideErrors.length !== 0 && e.push(t[this.children[s].index]);
    }
    this._serverSideErrors = e, this.onServerSideErrorsChange.emit(new v(e));
  }
  get value() {
    if (!this.isChanged)
      return;
    let t = {};
    for (const e in this.children)
      this.children[e].value !== void 0 && (this.children[e].index === null ? Object.assign(t, this.children[e].value) : t[this.children[e].index] = this.children[e].value);
    for (const e in this.dataStorage)
      t[e] === void 0 && this.dataStorage[e] !== void 0 && (t[e] = this.dataStorage[e]);
    return t;
  }
  get valueOrDefault() {
    let t = {};
    for (const e in this.children)
      this.children[e].index === null ? Object.assign(t, this.children[e].valueOrDefault) : t[this.children[e].index] = this.children[e].valueOrDefault;
    for (const e in this.dataStorage)
      t[e] === void 0 && this.dataStorage[e] !== void 0 && (t[e] = this.dataStorage[e]);
    return t;
  }
  get serverSideErrors() {
    return this._serverSideErrors;
  }
}
class N {
  submit(t) {
    console.warn("This form has no submit action, data:"), console.log(t);
  }
}
class Z {
  constructor(t) {
    this.form = t, this.url = "", t.getFormBuilder().onComponentsCreated.add(() => this.loadSavedData()), t.onFormChange.add(() => window.addEventListener("beforeunload", this.leaveCheck));
  }
  loadSavedData() {
    const t = sessionStorage.getItem("planaday-form-" + this.form.name);
    t && (this.form.getDataNode().value = JSON.parse(t));
  }
  saveData() {
    sessionStorage.setItem("planaday-form-" + this.form.name, JSON.stringify(this.form.getDataNode().value));
  }
  submit(t) {
    this.saveData(), this.form.getDataNode().value = t;
    let e = this.form.getPlacedHtml()[0] ?? null;
    if (!(e instanceof HTMLElement)) {
      console.error("Form has not been placed yet, cannot submit with post");
      return;
    }
    for (; e && e.tagName !== "FORM"; )
      e = e.parentElement;
    if (!(e instanceof HTMLFormElement)) {
      console.error("Form to submit could not be found");
      return;
    }
    e.setAttribute("method", "post"), e.setAttribute("action", this.url), window.removeEventListener("beforeunload", this.leaveCheck), e.submit();
  }
  leaveCheck(t) {
    t.preventDefault(), t.returnValue = !0;
  }
}
function tt(n) {
  n.registerConstructor("post", (t, e) => {
    if (!et(t)) return null;
    const s = new Z(e);
    return s.url = t.url, s;
  });
}
function et(n) {
  return n.type === "post";
}
class st {
  constructor(t, e = !1) {
    this.form = t, this.saveDataOnSuccess = e, this.url = "", this.headers = {}, this.parentData = null, this.childData = null, t.onFormChange.add(() => {
      window.addEventListener("beforeunload", this.leaveCheck);
    }), this.saveDataOnSuccess && this.form.getFormBuilder().onComponentsCreated.add(() => {
      let s = this.form.parent?.getDataNode();
      if (!s) return;
      const i = this.form.getDataNode();
      for (this.childData = i, s.removeChild(i); s.index == null && s.parent != null; )
        s = s.parent;
      this.parentData = s;
    });
  }
  async submit(t) {
    this.form.message = null, this.form.submitting = !0, await fetch(this.url, {
      method: "POST",
      headers: {
        ...this.headers,
        "Content-Type": "application/json"
      },
      body: JSON.stringify(t)
    }).then(
      (e) => e.json()
    ).then(
      (e) => this.handleResponse(e)
    ).catch(
      (e) => {
        console.error(e), this.form.message = "Er is iets misgegaan, probeer het later opnieuw.", this.form.submitting = !1, this.form.getPlacedHtml().every((s) => s.classList.add("pad-error"));
      }
    );
  }
  leaveCheck(t) {
    t.preventDefault(), t.returnValue = !0;
  }
  handleRedirect(t) {
    window.removeEventListener("beforeunload", this.leaveCheck), window.location.href = t.url;
  }
  handleMessage(t) {
    if (t.message == null && (t.message = (() => {
      switch (t.status) {
        case "success":
          return "Succesvol verzonden.";
        case "failed":
          return "Iets is mis gegaan, probeer het later opnieuw.";
        case "server-error":
          return "Er is iets misgegaan op de server. Probeer het later opnieuw.";
        case "config-error":
          return "Er is iets misgegaan met de configuratie. Laat de ons dit graag weten.";
        default:
          return "Er is iets misgegaan. Probeer het later opnieuw.";
      }
    })()), this.form.message = t.message, this.form.submitting = !1, t.status !== "success") {
      console.warn("Error while submitting form, status: " + t.status), console.warn(t), this.form.getPlacedHtml().every((e) => e.classList.add("pad-error")), t.errors != null && (this.form.serverSideErrors = t.errors);
      return;
    }
    if (this.form.serverSideErrors = {}, this.saveDataOnSuccess && this.parentData && this.childData) {
      let e = this.parentData.value ?? {}, s = this.childData.value ?? {};
      this.parentData.value = { ...e, ...s };
    }
    this.form.getPlacedHtml().every((e) => e.classList.remove("pad-error")), window.removeEventListener("beforeunload", this.leaveCheck);
  }
  handleResponse(t) {
    if (this.responseIsRedirect(t)) {
      this.handleRedirect(t);
      return;
    }
    if (this.responseIsMessage(t)) {
      this.handleMessage(t);
      return;
    }
    console.error("Unknown response from rest submit"), console.error(t), this.form.submitting = !1;
  }
  responseIsRedirect(t) {
    return t.status === "redirect";
  }
  responseIsMessage(t) {
    return t.status === "success" || t.status === "server-error" || t.status === "config-error" || t.status === "failed";
  }
}
function it(n) {
  n.registerConstructor("rest", (t, e) => {
    if (!nt(t)) return null;
    const s = new st(e, t.saveDataOnSuccess);
    return s.url = t.url, s.headers = t.headers, s;
  });
}
function nt(n) {
  return n.type === "rest";
}
class at {
  constructor() {
    this.registeredConstructors = {};
  }
  createSubmitStrategy(t, e) {
    if (typeof t.type != "string") throw new Error("Type is not a string");
    return typeof this.registeredConstructors[t.type] != "function" ? new N() : this.registeredConstructors[t.type](t, e) ?? new N();
  }
  registerConstructor(t, e) {
    return this.registeredConstructors[t] = e, this;
  }
  setDefaults() {
    return tt(this), it(this), this;
  }
}
class rt {
  constructor() {
    this.submitStrategyFactory = new at().setDefaults();
  }
  createForm(t, e) {
    const s = t.impl;
    if (!L(s)) throw new Error("Invalid config");
    const i = e;
    i.name = s.name, i.writeDefaultData = s.writeDefaultData, i.displayDefaultNotice = s.displayDefaultNotice, i.isDefaultText = s.isDefaultText, i.isChangedText = s.isChangedText, i.resetButtonText = s.resetButtonText, i.forceDivElement = s.forceDivElement, i.useHiddenFieldForJson = s.useHiddenFieldForJson;
    const a = new y(i);
    return a.submitStrategy = this.submitStrategyFactory.createSubmitStrategy(s.submitBehaviour, a), a;
  }
  addToStructureFactory(t) {
    t.registerConstructor("form", (e, s) => L(e.impl) ? this.createForm(e, s) : null);
  }
}
function L(n) {
  return n.type === "form";
}
class ot extends c {
  constructor(t = {}) {
    super(t), Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    this.addStandardContainerProperties(e), t.append(e), this.placedHtml.push(e), this.contents.forEach((s) => s.placeHtml(e));
  }
}
function lt(n) {
  n.registerConstructor("basic", (t, e) => {
    const s = t.impl;
    if (!dt(s)) return null;
    const i = e;
    return new ot(i);
  });
}
function dt(n) {
  return n.type === "basic";
}
class ut extends c {
  constructor(t = {}) {
    super(t), this.tabs = [], Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    this.addStandardContainerProperties(e), e.classList.add("pad-tabbed-group");
    const s = document.createElement("ul");
    e.append(s), this.tabs.forEach((i, a) => {
      const r = document.createElement("li"), o = document.createElement("div"), d = document.createElement("a"), E = "pad-" + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
      r.classList.add("pad-tab-label"), r.append(d), d.href = "#" + E, d.innerText = i.label, o.id = E, o.classList.add("pad-tab-content"), s.appendChild(r), e.appendChild(o), i.contents.forEach((F) => {
        const p = this.formBuilder.registry[F];
        p && (p.placeHtml(o), (p instanceof c || p instanceof h) && p.getDataNode().onValidChange.add(() => {
          r.classList.toggle("pad-invalid", !this.checkTabValid(a));
        }), (p instanceof c || p instanceof h) && p.getDataNode().onServerSideErrorsChange.add(() => {
          r.classList.toggle("pad-server-side-errors", !this.checkTabServerSide(a));
        }));
      }), r.classList.toggle("pad-invalid", !this.checkTabValid(a));
    }), ct(window) && window.jQuery(e).tabs(), t.append(e), this.placedHtml.push(e);
  }
  checkTabValid(t) {
    return this.tabs[t].contents.every((e) => {
      const s = this.formBuilder.registry[e];
      return s instanceof c || s instanceof h ? s.getDataNode().isValid : !0;
    });
  }
  checkTabServerSide(t) {
    return this.tabs[t].contents.every((e) => {
      const s = this.formBuilder.registry[e];
      return s instanceof c || s instanceof h ? s.getDataNode().serverSideErrors.length === 0 : !0;
    });
  }
}
function ct(n) {
  return typeof n.jQuery == "function";
}
function ht(n) {
  n.registerConstructor("tabbedGroups", (t, e) => {
    const s = t.impl;
    if (!pt(s)) return null;
    const i = e;
    return i.tabs = s.tabs, new ut(i);
  });
}
function pt(n) {
  return n.type === "tabbedGroups";
}
class mt extends c {
  constructor(t = {}) {
    super(t), this.name = "", this.description = "", Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    this.addStandardContainerProperties(e), e.classList.add("pad-question-cluster");
    const s = document.createElement("span"), i = document.createElement("p"), a = document.createElement("div");
    s.classList.add("pad-name"), s.innerText = this.name, i.classList.add("pad-description"), i.innerText = this.description, a.classList.add("pad-questions"), e.append(s), e.append(i), e.append(a), t.append(e), this.placedHtml.push(e), this.contents.forEach((r) => r.placeHtml(a));
  }
}
function gt(n) {
  n.registerConstructor("questionCluster", (t, e) => {
    const s = t.impl;
    if (!ft(s)) return null;
    const i = e;
    return i.name = s.name, i.description = s.description, new mt(i);
  });
}
function ft(n) {
  return n.type === "questionCluster";
}
class vt extends c {
  constructor(t = {}) {
    super(t), this.startCollapsed = !1, this.header = null, this.description = null, Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    this.addStandardContainerProperties(e), e.classList.add("pad-collapsible-group");
    const s = document.createElement("div"), i = document.createElement("span");
    if (i.classList.add("pad-expand-arrow"), s.append(i), this.header) {
      const o = document.createElement("span");
      o.classList.add("pad-header"), o.innerText = this.header, s.append(o);
    }
    if (this.description) {
      const o = document.createElement("p");
      o.classList.add("pad-description"), o.innerText = this.description, s.append(o);
    }
    const a = document.createElement("div");
    let r = this.startCollapsed;
    s.addEventListener("click", () => {
      r = !r, u(a, !r), r ? s.classList.add("pad-collapsed") : s.classList.remove("pad-collapsed");
    }), e.append(s), e.append(a), a.classList.add("pad-form-group"), s.classList.add("pad-header-box"), s.classList.toggle("pad-collapsed", r), u(a, !r), t.append(e), this.placedHtml.push(e), this.contents.forEach((o) => o.placeHtml(a));
  }
}
function Ct(n) {
  n.registerConstructor("collapsible", (t, e) => {
    const s = t.impl;
    if (!yt(s)) return null;
    const i = e;
    return i.startCollapsed = s.startCollapsed, i.header = s.header, i.description = s.description, new vt(i);
  });
}
function yt(n) {
  return n.type === "collapsible";
}
class bt extends c {
  constructor(t = {}) {
    super(t), this.externalElements = [], this.buttonTitle = "", this.closeButtonText = "", Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    this.addStandardContainerProperties(e), e.classList.add("pad-popup-group");
    const s = document.createElement("div"), i = document.createElement("div"), a = document.createElement("button"), r = document.createElement("form");
    r.classList.add("pad-form", "pad-full-screen-item-container", "planaday"), i.classList.add("pad-popup-background", "pad-hidden"), i.append(s), s.classList.add("pad-popup", "pad-hidden", "pad-form-group");
    let o = document.createElement("button");
    o.classList.add("pad-close-button", "button-primary"), o.innerText = this.closeButtonText ?? "Close", o.type = "button", o.addEventListener("click", () => {
      u(i, !1, !1), u(s, !1);
    }), s.append(o), a.classList.add("pad-popup-open-button", "button-primary"), a.innerText = this.buttonTitle, a.type = "button", a.addEventListener("click", () => {
      u(i, !0, !1), u(s, !0);
    }), i.addEventListener("click", () => {
      u(i, !1, !1), u(s, !1);
    }), u(s, !1, !1), u(i, !1), e.appendChild(a), r.appendChild(i), r.appendChild(s), t.append(e), document.body.appendChild(r), this.placedHtml.push(e), this.externalElements.push(r), this.contents.forEach((d) => d.placeHtml(s));
  }
  cleanHtml() {
    super.cleanHtml(), this.externalElements.forEach((t) => t.remove()), this.externalElements = [];
  }
}
function Et(n) {
  n.registerConstructor("fullScreenPopup", (t, e) => {
    const s = t.impl;
    if (!xt(s)) return null;
    const i = e;
    return i.buttonTitle = s.buttonTitle, i.closeButtonText = s.closeButtonText, new bt(i);
  });
}
function xt(n) {
  return n.type === "fullScreenPopup";
}
class wt extends c {
  constructor(t = {}) {
    super(t), this.repeatingConditions = [], this.withRemoveButton = !1, this.removeButtonText = "Remove", this.addButtonText = "Add", this._isRepeating = !0, this.nextRepeatIndex = 0, this.createdInstances = [], this.addButtons = [], this.placedContainers = [], Object.assign(this, t), this.formBuilder.onComponentsCreated.add(() => this.checkRepeatingConditions());
  }
  placeButtons() {
    this.placedHtml.forEach((t) => {
      const e = document.createElement("button");
      e.type = "button", e.innerText = this.addButtonText, e.classList.add("pad-add-repeating-button", "button-primary"), e.addEventListener("click", () => {
        this.addRepeatingContent();
      }), e.disabled = this.createdInstances.length + (this.atLeastOne ? 1 : 0) >= this.maxCount, t.append(e), this.addButtons.push(e);
    });
  }
  placeHtml(t) {
    if (this.atLeastOne && this.nextRepeatIndex === 0) {
      this.repeatingContents.idPrefix = this.idPrefix + this.id + "-" + this.nextRepeatIndex + "-", this.repeatingContents.index = String(this.nextRepeatIndex), this.nextRepeatIndex++;
      const s = this.formBuilder.componentFactory.createComponent(this.repeatingContents, this);
      if (!s) throw new Error("Failed to create repeating instance");
      this.contents.push(s), this.dataNode.addChildren(s.getDataNode()), this.formBuilder.manualComponentsCreatedEvent();
    }
    const e = document.createElement("div");
    e.classList.add("pad-repeating-group"), this.addStandardContainerProperties(e), t.append(e), this.placedHtml.push(e), this.contents.forEach((s) => s.placeHtml(e)), this.createdInstances.forEach((s) => this.placeRepeatingContent(s, e)), this.setRepeatingVisibility(this._isRepeating);
  }
  setRepeatingVisibility(t) {
    t ? (this.placedContainers.forEach((e) => u(e, !0)), this.createdInstances.forEach((e) => this.dataNode.addChildren(e.getDataNode())), this.addButtons.forEach((e) => e.remove()), this.addButtons = [], this.placeButtons()) : (this.addButtons.forEach((e) => e.remove()), this.addButtons = [], this.placedContainers.forEach((e) => u(e, !1)), this.createdInstances.forEach((e) => this.dataNode.removeChild(e.getDataNode())));
  }
  addRepeatingCondition(t) {
    t.onChange.add((e) => this.checkRepeatingConditions(e)), this.repeatingConditions.push(t);
  }
  checkRepeatingConditions(t = null) {
    if (t !== this._isRepeating) {
      if (t === !1) {
        this.isRepeating = !1;
        return;
      }
      this.isRepeating = this.repeatingConditions.every((e) => e.check());
    }
  }
  set isRepeating(t) {
    t !== this._isRepeating && (this._isRepeating = t, this.setRepeatingVisibility(t));
  }
  placeRepeatingContent(t, e) {
    const s = document.createElement("div");
    s.classList.add("pad-repeating-item", "pad-form-group", "pad-hidden");
    const i = document.createElement("button");
    i.type = "button", i.innerText = this.removeButtonText, i.classList.add("pad-remove-repeating-button", "button-primary"), i.addEventListener("click", () => {
      this.dataNode.removeChild(t.getDataNode()), this.createdInstances.splice(this.createdInstances.indexOf(t), 1), u(s, !1), setTimeout(() => {
        s.remove(), t.cleanHtml();
      }, 1e3), this.addButtons.forEach((a) => a.remove()), this.addButtons = [], this.placeButtons();
    }), s.append(i), t.placeHtml(s), e.append(s), this.placedContainers.push(s), setTimeout(() => u(s, !0));
  }
  addRepeatingContent() {
    if (this.createdInstances.length + (this.atLeastOne ? 1 : 0) >= this.maxCount) return;
    this.addButtons.forEach((e) => e.remove()), this.addButtons = [], this.repeatingContents.idPrefix = this.idPrefix + this.id + "-" + this.nextRepeatIndex + "-", this.repeatingContents.index = String(this.nextRepeatIndex), this.nextRepeatIndex++;
    const t = this.formBuilder.componentFactory.createComponent({ ...this.repeatingContents }, this);
    if (!t) throw new Error("Failed to create repeating instance");
    this.createdInstances.push(t), this.dataNode.addChildren(t.getDataNode()), this.formBuilder.manualComponentsCreatedEvent(), this.placedHtml.forEach((e) => this.placeRepeatingContent(t, e)), this.placeButtons();
  }
}
function Dt(n) {
  n.registerConstructor("repeating", (t, e) => {
    const s = t.impl;
    if (!Nt(s)) return null;
    const i = e;
    i.maxCount = s.maxCount, i.atLeastOne = s.atLeastOne, i.repeatingContents = s.repeatingContents, i.addButtonText = s.addButtonText, i.removeButtonText = s.removeButtonText, i.withRemoveButton = s.withRemoveButton;
    const a = new wt(i);
    return s.repeatingConditions.forEach((r) => {
      const o = i.formBuilder?.conditionFactory.createCondition(r);
      o && a.addRepeatingCondition(o);
    }), a;
  });
}
function Nt(n) {
  return n.type === "repeating";
}
class Lt extends c {
  constructor(t = {}) {
    super(t), this.url = "", this.headers = {}, this.dependencies = [], this.isLoading = !0, this.currentRequest = null, this.currentMessage = null, this.currentForm = null, Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    this.addStandardContainerProperties(e), e.classList.add("pad-remotely-loaded-form"), t.append(e), this.placedHtml.push(e), this.isLoading && (e.innerHTML = '<div class="pad-spinner"></div>'), this.currentMessage && (e.innerHTML = `<div class="pad-error">${this.currentMessage}</div>`), this.currentForm && (e.innerHTML = "", this.currentForm.placeHtml(e));
  }
  addDependency(t) {
    t.onChange.add(() => this.updateForm()), this.dependencies.push(t);
  }
  updateForm() {
    this.isLoading || this.placeSpinner(), this.isLoading = !0;
    let t = {};
    this.dependencies.forEach((s) => {
      const i = s.index;
      if (i == null) {
        Object.assign(t, s.value);
        return;
      }
      t[i] = s.value;
    });
    const e = this.currentRequest = fetch(this.url, {
      method: "POST",
      headers: {
        ...this.headers,
        "Content-Type": "application/json"
      },
      body: JSON.stringify(t)
    });
    e.then(
      (s) => {
        this.currentRequest === e && (this.currentRequest = null, s.json().then(
          (i) => {
            this.placeForm(i.options);
          }
        ).catch((i) => {
          console.error(i), this.placeMessage("Er is iets misgegaan, probeer het later opnieuw.");
        }));
      }
    ).catch(
      (s) => {
        this.currentRequest = null, this.placeMessage(s.message), console.error(s);
      }
    );
  }
  placeForm(t) {
    const e = this.formBuilder.getData(!1) ?? {}, s = new we(t);
    s.form.parent = this, this.currentForm && (this.currentForm.clean(), this.dataNode.removeChild(this.currentForm.form.getDataNode())), this.dataNode.addChildren(s.form.getDataNode()), this.formBuilder.loadData(e), this.currentForm = s, this.currentMessage = null, this.isLoading = !1, this.placedHtml.forEach((i) => {
      i.innerHTML = "", s.placeHtml(i);
    });
  }
  placeMessage(t) {
    this.placedHtml.forEach((e) => e.innerHTML = `<div class="pad-error">${t}</div>`);
  }
  placeSpinner() {
    this.placedHtml.forEach((t) => {
      const e = document.createElement("div");
      e.classList.add("pad-spinner"), t.prepend(e);
    });
  }
}
function St(n) {
  n.registerConstructor("remotelyLoadedForm", (t, e) => {
    const s = t.impl;
    if (!Tt(s)) return null;
    const i = e;
    i.url = s.url, i.headers = s.headers;
    const a = new Lt(i);
    return i.formBuilder?.onComponentsCreated.add(() => {
      s.dependencies.forEach((r) => {
        let o = i.formBuilder?.registry[r];
        (o instanceof h || o instanceof c) && a.addDependency(o.getDataNode());
      }), a.updateForm();
    }), a;
  });
}
function Tt(n) {
  return n.type === "remotelyLoadedForm";
}
class Vt {
  constructor(t) {
    this.componentFactory = t, this.registeredConstructors = {};
  }
  createStructure(t, e) {
    if (typeof t.impl.type != "string") throw new Error("Type is not a string");
    if (typeof this.registeredConstructors[t.impl.type] != "function")
      return console.warn(`Structure ${t.impl.type} is not registered`), null;
    const s = e;
    s.index = t.index, s.classes = t.classes, s.displayDefaultNotice = t.displayDefaultNotice;
    const i = this.registeredConstructors[t.impl.type](t, s);
    if (i == null)
      return console.warn(`Structure ${t.impl.type} could not be created`), null;
    const a = new Y();
    a.index = t.index, i.setDataNode(a);
    const r = [];
    return t.contents.forEach((o) => {
      const d = this.componentFactory.createComponent(o, i);
      d !== null && (i.addChildren(d), d instanceof h && r.push(d.getDataNode()), d instanceof c && r.push(d.getDataNode()));
    }), a.addChildren(...r), i;
  }
  registerConstructor(t, e) {
    return this.registeredConstructors[t] = e, this;
  }
  setDefaults() {
    return new rt().addToStructureFactory(this), lt(this), ht(this), gt(this), Ct(this), Et(this), Dt(this), St(this), this;
  }
  registerOnComponentFactory(t) {
    t.registerConstructor("structure", (e, s) => {
      if (Ft(e))
        return this.createStructure(e, s);
    });
  }
}
function Ft(n) {
  return n.type === "structure";
}
class g extends C {
  constructor(t) {
    super(t), Object.assign(this, t);
  }
}
class Ot extends g {
  constructor(t = {}) {
    super(t), this.text = "", this.level = 3, Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("h" + this.level);
    e.classList.toggle("pad-hidden", !this.visible), e.classList.add("pad-header"), e.innerText = this.text, t.appendChild(e), this.placedHtml.push(e);
  }
}
function It(n) {
  n.registerConstructor("header", (t, e) => {
    const s = t.impl;
    if (!kt(s)) return null;
    const i = e;
    return i.text = s.text, i.level = s.level, new Ot(i);
  });
}
function kt(n) {
  return n.type === "header";
}
class Ht extends g {
  constructor(t) {
    super(t), this.outputElements = [], this.classes = [], this.message = null, Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    e.title = "Click to close", e.classList.add("pad-message", "pad-hidden", ...this.classes);
    const s = document.createElement("p");
    e.append(s);
    const i = document.createElement("div");
    i.classList.add("pad-close-button"), i.innerText = "X", e.addEventListener("click", () => {
      S(e);
    }), e.append(i), t.append(e), this.placedHtml.push(e), this.outputElements.push(s);
  }
  updateMessage(t) {
    this.message = t, this.outputElements.forEach((e) => {
      e.innerHTML = t ?? "", u(e, (t ?? "") !== "");
    }), this.placedHtml.forEach((e) => {
      u(e, (t ?? "") !== "");
    });
  }
}
function Bt(n) {
  n.registerConstructor("messageDisplay", (t, e) => {
    const s = t.impl;
    if (!_t(s)) return null;
    const i = e;
    i.classes = s.classes;
    const a = new Ht(i);
    return a.getOwnerForm().onMessageChange.add((r) => {
      a.updateMessage(r.message);
    }), a;
  });
}
function _t(n) {
  return n.type === "messageDisplay";
}
class Pt extends g {
  constructor(t = {}) {
    super(t), this.html = "", Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    e.classList.toggle("pad-hidden", !this.visible), e.innerHTML = this.html, e.classList.add("pad-html"), t.append(e), this.placedHtml.push(e);
  }
}
function Rt(n) {
  n.registerConstructor("html", (t, e) => {
    const s = t.impl;
    if (!jt(s)) return null;
    const i = e;
    return i.html = s.html, new Pt(i);
  });
}
function jt(n) {
  return n.type === "html";
}
class Mt extends g {
  constructor(t = {}) {
    super(t), this.text = "", Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("button");
    e.classList.toggle("pad-hidden", !this.visible), e.innerText = this.text, e.type = "button", e.addEventListener("click", () => {
      this.getOwnerForm().submit();
    }), e.classList.add("pad-submit-button", "button-primary"), e.disabled = !this.getOwnerForm().getDataNode().isValid, this.getOwnerForm().onSubmittingChange.add((s) => {
      e.classList.toggle("pad-submitting", s.submitting), e.disabled = s.submitting || e.classList.contains("pad-invalid");
    }), this.getOwnerForm().getDataNode().onValidChange.add((s) => {
      e.classList.toggle("pad-invalid", !s.isValid), e.disabled = !s.isValid || e.classList.contains("pad-submitting");
    }), t.appendChild(e), this.placedHtml.push(e);
  }
}
function At(n) {
  n.registerConstructor("submitButton", (t, e) => {
    const s = t.impl;
    if (!qt(s)) return null;
    const i = e;
    return i.text = s.text, new Mt(i);
  });
}
function qt(n) {
  return n.type === "submitButton";
}
class zt extends g {
  constructor(t = {}) {
    super(t), this.text = "", this.classes = [], Object.assign(this, t);
  }
  placeHtml(t) {
    const e = document.createElement("div");
    e.classList.toggle("pad-hidden", !this.visible), e.innerText = this.text, e.classList.add("pad-text", ...this.classes), t.append(e), this.placedHtml.push(t);
  }
}
function $t(n) {
  n.registerConstructor("text", (t, e) => {
    const s = t.impl;
    if (!Qt(s)) return null;
    const i = e;
    return i.text = s.text, i.classes = s.classes, new zt(i);
  });
}
function Qt(n) {
  return n.type === "text";
}
class Kt {
  constructor() {
    this.registeredConstructors = {};
  }
  createLayoutItem(t, e) {
    if (typeof t.impl.type != "string") throw new Error("Type is not a string");
    if (typeof this.registeredConstructors[t.impl.type] != "function")
      return console.warn(`LayoutItem ${t.impl.type} is not registered`), null;
    const s = e, i = this.registeredConstructors[t.impl.type](t, s);
    return i ?? (console.warn(`LayoutItem ${t.impl.type} could not be created`), null);
  }
  registerConstructor(t, e) {
    return this.registeredConstructors[t] = e, this;
  }
  setDefaults() {
    return It(this), Bt(this), Rt(this), At(this), $t(this), this;
  }
  registerOnComponentFactory(t) {
    t.registerConstructor("LayoutItem", (e, s) => {
      if (Jt(e))
        return this.createLayoutItem(e, s);
    });
  }
}
function Jt(n) {
  return n.type === "LayoutItem";
}
class Wt {
  constructor(t) {
    this.type = t, this.onChange = new l(), this.onReset = new l(), this.onValidChange = new l(), this.onServerSideErrorsChange = new l(), this.onMessagesChange = new l(), this.parent = null, this._serverSideErrors = [], this._messages = [], this._isValid = !0, this._value = void 0, this._defaultValue = null, this._isVisible = !0, this.type.onChange.add(() => this.validate());
  }
  validate() {
    let t = this.type.validate(this.isChanged ? this.value ?? null : this.valueOrDefault);
    t !== !0 ? (this.isValid = !1, this.messages = t) : (this.messages = [], this.isValid = !0);
  }
  resetValue() {
    this.value = void 0, this.onReset.emit(null);
  }
  set isVisible(t) {
    this._isVisible !== t && (this._isVisible = t, this.onValidChange.emit(new f(this._isValid, this._isVisible)));
  }
  set isValid(t) {
    this._isValid !== t && (this._isValid = t, this.onValidChange.emit(new f(this._isValid, this._isVisible)));
  }
  set value(t) {
    try {
      let e = this.type.sanitize(t);
      e !== this._value && (this._value = e, this.validate(), this.onChange.emit(new V(this, this._value)));
    } catch (e) {
      this.messages = [e.message], this.isValid = !1;
    }
  }
  set serverSideErrors(t) {
    if (typeof t != "object" || t == null) {
      this._serverSideErrors = [], this.onServerSideErrorsChange.emit(new v([]));
      return;
    }
    this._serverSideErrors = [];
    for (const e in t)
      this._serverSideErrors.push(t[e]);
    this.onServerSideErrorsChange.emit(new v(this._serverSideErrors));
  }
  get serverSideErrors() {
    return this._serverSideErrors;
  }
  set defaultValue(t) {
    let e = this.type.sanitize(t);
    e === void 0 && (e = null), this._defaultValue = e;
  }
  set messages(t) {
    this._messages = t, this.onMessagesChange.emit(new Gt(t));
  }
  get isChanged() {
    return this._value !== void 0;
  }
  get isValid() {
    return !this._isVisible || this._isValid;
  }
  get value() {
    return this._value;
  }
  get valueOrDefault() {
    return this._value ?? this._defaultValue;
  }
  get messages() {
    return this._messages;
  }
}
class Gt {
  constructor(t) {
    this.messages = t;
  }
}
class Ut extends h {
  constructor(t) {
    super(t), Object.assign(this, t);
  }
  placeHtml(t) {
    const e = this.getQuestionContainer();
    e.classList.add("pad-bool-input"), t.append(e), this.placedHtml.push(e);
  }
  getInputElement() {
    const t = document.createElement("input");
    return t.type = "checkbox", t.name = this.getFullPathName(), t.addEventListener("change", () => {
      this.value = t.checked, this.getDataNode().value = t.checked;
    }), this.onChange.add((e) => {
      t.checked = e.value ?? !1;
    }), this.getDataNode().onChange.add((e) => {
      t.checked = e.value ?? !1;
    }), this.getDataNode().onReset.add(() => {
      this.value = void 0, t.checked = this.getDataNode().valueOrDefault ?? !1;
    }), t.checked = this.getDataNode().valueOrDefault ?? !1, t;
  }
}
function Xt(n) {
  n.registerConstructor("bool", (t, e) => {
    const s = t.impl;
    if (!Yt(s)) return null;
    const i = e;
    return new Ut(i);
  });
}
function Yt(n) {
  return n.type === "bool";
}
class Zt extends h {
  constructor(t) {
    super(t), this.placeholder = null, Object.assign(this, t);
  }
  placeHtml(t) {
    const e = this.getQuestionContainer();
    e.classList.add("pad-text-input"), t.append(e), this.placedHtml.push(e);
  }
  getInputElement() {
    const t = document.createElement("input");
    return t.type = "text", t.name = this.getFullPathName(), t.setAttribute("autocomplete", this.autocomplete), this.placeholder && (t.placeholder = this.placeholder), t.addEventListener("input", () => {
      let e = t.value;
      e === "" && (e = null), this.value = e;
    }), t.addEventListener("change", () => {
      this.saveValue();
    }), this.onChange.add((e) => {
      t.value = e.value ?? "";
    }), this.getDataNode().onChange.add((e) => {
      t.value = e.value ?? "";
    }), this.getDataNode().onReset.add(() => {
      this.value = void 0, t.value = this.getDataNode().valueOrDefault ?? "";
    }), t.value = this._value ?? this.getDataNode().valueOrDefault ?? "", t;
  }
}
function te(n) {
  n.registerConstructor("string", (t, e) => {
    const s = t.impl;
    if (!ee(s)) return null;
    const i = e;
    return i.placeholder = s.placeholder, new Zt(i);
  });
}
function ee(n) {
  return n.type === "string";
}
class se extends h {
  constructor(t) {
    super(t), this.placeholder = null, this.min = null, this.max = null, this.step = null, Object.assign(this, t);
  }
  placeHtml(t) {
    const e = this.getQuestionContainer();
    e.classList.add("pad-number-input"), t.append(e), this.placedHtml.push(e);
  }
  getInputElement() {
    const t = document.createElement("input");
    return t.name = this.getFullPathName(), t.setAttribute("autocomplete", this.autocomplete), t.type = "number", t.step = String(this.step ?? 1), this.min !== null && (t.min = String(this.min)), this.max !== null && (t.max = String(this.max)), this.placeholder && (t.placeholder = this.placeholder), t.addEventListener("input", () => {
      let e = t.valueAsNumber;
      isNaN(e) && (e = null), this.value = e;
    }), t.addEventListener("change", () => {
      this.saveValue();
    }), this.onChange.add((e) => {
      t.value = "" + (e.value ?? "");
    }), this.getDataNode().onChange.add((e) => {
      t.value = "" + (e.value ?? "");
    }), this.getDataNode().onReset.add(() => {
      this.value = void 0, t.value = String(this.getDataNode().valueOrDefault ?? 0);
    }), t.value = String(this._value ?? this.getDataNode().valueOrDefault ?? 0), t;
  }
  saveValue() {
    if (this._value == null) {
      this.getDataNode().value = this._value;
      return;
    }
    if (isNaN(this._value)) {
      this.getDataNode().value = null;
      return;
    }
    if (this.min !== null && this._value < this.min) {
      this.getDataNode().value = this.min;
      return;
    }
    if (this.max !== null && this._value > this.max) {
      this.getDataNode().value = this.max;
      return;
    }
    this.getDataNode().value = this._value;
  }
}
function ie(n) {
  n.registerConstructor("number", (t, e) => {
    const s = t.impl;
    if (!ne(s)) return null;
    const i = e;
    return i.placeholder = s.placeholder, i.min = s.min, i.max = s.max, i.step = s.step, new se(i);
  });
}
function ne(n) {
  return n.type === "number";
}
class ae extends h {
  constructor(t) {
    super(t), this.options = [], this.optionsObjects = [], Object.assign(this, t);
  }
  setDataNode(t) {
    return super.setDataNode(t), this.options.forEach(
      (e) => this.optionsObjects.push(
        this.getCheckBoxOption(e)
      )
    ), this;
  }
  getCheckBoxOption(t) {
    const e = new le(), s = this.getDataNode();
    return e.label = t.label, Array.isArray(t.value) ? (t.value.forEach((i) => e.addChildren(this.getCheckBoxOption(i))), e.checkChildren()) : (s.onChange.add((i) => {
      e.checked = i.value?.includes(t.value) ?? !1;
    }), s.onReset.add(() => {
      this.value = void 0, e.checked = s.valueOrDefault?.includes(t.value) ?? !1;
    }), e.onChange.add((i) => {
      let a = (s.valueOrDefault ?? []).concat();
      i ? (a.push(t.value), s.value = a) : s.value = a.filter((r) => r !== t.value), this.value = s.value;
    }), e.checked = s.valueOrDefault?.includes(t.value) ?? !1, e.value = t.value), e;
  }
  placeHtml(t) {
    const e = this.getQuestionContainer();
    e.classList.add("pad-layered-checkbox-input"), t.append(e), this.placedHtml.push(e);
  }
  getInputElement() {
    const t = document.createElement("div");
    return t.classList.add("pad-layered-checkbox-options"), this.optionsObjects.forEach((e) => {
      t.append(this.getChildBox(e));
    }), t;
  }
  getChildBox(t) {
    const e = document.createElement("div");
    e.classList.add("pad-layered-checkbox-container");
    const s = document.createElement("input");
    s.type = "checkbox", s.name = this.getFullPathName() + "[]";
    const i = document.createElement("label");
    if (i.innerText = t.label, i.classList.add("pad-layered-checkbox-label"), i.prepend(s), e.append(i), t.onChange.add(() => {
      s.checked = t.checked, s.indeterminate = t.indeterminate;
    }), s.addEventListener("change", () => {
      t.checked = s.checked;
    }), t.getChildren().length > 0) {
      const a = document.createElement("div");
      a.classList.add("pad-layered-checkbox-children"), e.append(a), t.getChildren().forEach((r) => {
        a.append(this.getChildBox(r));
      });
    } else
      s.value = String(t.value);
    return e;
  }
}
function re(n) {
  n.registerConstructor("layeredCheckboxes", (t, e) => {
    const s = t.impl;
    if (!oe(s)) return null;
    const i = e;
    return i.options = s.options, new ae(i);
  });
}
function oe(n) {
  return n.type === "layeredCheckboxes";
}
class le {
  constructor() {
    this.value = void 0, this._checked = !1, this._indeterminate = !1, this.children = [], this.onChange = new l();
  }
  addChildren(...t) {
    t.forEach((e) => {
      this.children.push(e), e.onChange.add(() => this.checkChildren());
    });
  }
  checkChildren() {
    this.checked = this.children.every((t) => t.checked), this.indeterminate = this.children.some((t) => t.checked || t.indeterminate) && !this.checked;
  }
  getChildren() {
    return this.children;
  }
  set indeterminate(t) {
    this._indeterminate !== t && (this._indeterminate = t, this.onChange.emit(this._checked));
  }
  get indeterminate() {
    return this._indeterminate;
  }
  get checked() {
    return this._checked;
  }
  set checked(t) {
    this._checked !== t && (this._checked = t, this.children.forEach((e) => e.checked = t), this.onChange.emit(this._checked));
  }
}
class de extends h {
  constructor(t) {
    super(t), this.options = [], this.customInput = null, this.onAddCustomOption = new l(), Object.assign(this, t);
  }
  getOptionElement(t) {
    const e = this.getDataNode(), s = document.createElement("label"), i = document.createElement("span");
    if (i.classList.add("pad-multi-select-option-name"), s.append(i), t.description) {
      const r = document.createElement("p");
      r.classList.add("pad-multi-select-option-description"), r.innerText = t.description, s.append(r);
    }
    i.innerText = t.label, s.classList.add("pad-multi-select-option");
    const a = document.createElement("input");
    return a.value = String(t.value), a.checked = e.valueOrDefault?.includes(t.value) ?? !1, a.type = "checkbox", a.name = this.getFullPathName() + "[]", s.prepend(a), e.onChange.add((r) => {
      a.checked = r.value?.includes(t.value) ?? !1;
    }), e.onReset.add(() => {
      this.value = void 0, a.checked = e.valueOrDefault?.includes(t.value) ?? !1;
    }), a.addEventListener("change", () => {
      let r = (e.valueOrDefault ?? []).concat();
      a.checked ? (r.push(t.value), e.value = r) : e.value = r.filter((o) => o !== t.value), this.value = e.value;
    }), s;
  }
  placeHtml(t) {
    const e = this.getQuestionContainer();
    if (e.classList.add("pad-multi-select-input"), this.customInput) {
      const s = document.createElement("button");
      s.innerText = "+", s.type = "button", s.classList.add("pad-add-custom-option"), s.addEventListener("click", () => {
        const a = this.customInput?.getDataNode();
        if (!a || a.value == null || a.value === "" || !a.isValid) return;
        if (this.options.some((d) => d.value === a.value)) {
          let d = (this.getDataNode().valueOrDefault ?? []).concat();
          d.push(a.value), this.getDataNode().value = d, this.value = d;
          return;
        }
        const r = {
          label: String(a.value),
          value: a.value
        };
        this.options.push(r), a.value = void 0, this.onAddCustomOption.emit(new b(r));
        let o = (this.getDataNode().valueOrDefault ?? []).concat();
        o.push(r.value), this.getDataNode().value = o, this.value = o;
      });
      const i = document.createElement("div");
      i.classList.add("pad-custom-input-container"), i.append(s), this.customInput.placeHtml(i), e.append(i);
    }
    t.append(e), this.placedHtml.push(e);
  }
  getInputElement() {
    const t = document.createElement("div");
    return t.classList.add("pad-multi-select-options"), this.onAddCustomOption.add((e) => {
      t.append(this.getOptionElement(e.newOption));
    }), this.options.forEach((e) => {
      t.append(this.getOptionElement(e));
    }), this.dataNode.value?.forEach(
      (e) => {
        let s = !1;
        for (let i of this.options)
          if (i.value === e) {
            s = !0;
            break;
          }
        s || t.append(this.getOptionElement({ value: e, label: e }));
      }
    ), t;
  }
}
function ue(n) {
  n.registerConstructor("multiSelect", (t, e) => {
    const s = t.impl;
    if (!ce(s)) return null;
    const i = e;
    i.options = s.options;
    const a = new de(i);
    if (!s.allowCustom) return a;
    const r = {};
    r.formBuilder = a.formBuilder;
    const o = n.createInput(s.customInput, r);
    return o && (a.customInput = o), a;
  });
}
function ce(n) {
  return n.type === "multiSelect";
}
class b {
  constructor(t) {
    this.newOption = t;
  }
}
class he extends h {
  constructor(t) {
    super(t), this.options = [], this.customInput = null, this.onAddCustomOption = new l(), Object.assign(this, t);
  }
  getOptionElement(t) {
    const e = this.getDataNode(), s = document.createElement("label"), i = document.createElement("span");
    if (i.classList.add("pad-radio-option-name"), s.append(i), t.description) {
      const r = document.createElement("p");
      r.classList.add("pad-radio-option-description"), r.innerText = t.description, s.append(r);
    }
    i.innerText = t.label, s.classList.add("pad-radio-option");
    const a = document.createElement("input");
    return a.value = String(t.value), a.checked = e.valueOrDefault === t.value, a.type = "radio", a.name = this.getFullPathName(), s.prepend(a), e.onChange.add((r) => {
      a.checked = r.value === t.value;
    }), e.onReset.add(() => {
      this.value = void 0, a.checked = e.valueOrDefault === t.value;
    }), a.addEventListener("change", () => {
      a.checked && (e.value = t.value);
    }), s;
  }
  placeHtml(t) {
    const e = this.getQuestionContainer();
    if (e.classList.add("pad-radio-input"), this.customInput) {
      const s = document.createElement("button");
      s.innerText = "+", s.type = "button", s.classList.add("pad-add-custom-option"), s.addEventListener("click", () => {
        const a = this.customInput?.getDataNode();
        if (!a || a.value == null || a.value === "" || !a.isValid) return;
        if (this.options.some((o) => o.value === a.value)) {
          this.getDataNode().value = a.value, this.value = a.value;
          return;
        }
        const r = {
          label: String(a.value),
          value: a.value
        };
        this.options.push(r), a.value = void 0, this.onAddCustomOption.emit(new b(r)), this.getDataNode().value = r.value, this.value = r.value;
      });
      const i = document.createElement("div");
      i.classList.add("pad-custom-input-container"), i.append(s), this.customInput.placeHtml(i), e.append(i);
    }
    t.append(e), this.placedHtml.push(e);
  }
  getInputElement() {
    const t = document.createElement("div");
    return t.classList.add("pad-radio-options"), this.onAddCustomOption.add((e) => {
      t.append(this.getOptionElement(e.newOption));
    }), this.options.forEach((e) => {
      t.append(this.getOptionElement(e));
    }), t;
  }
}
function pe(n) {
  n.registerConstructor("radio", (t, e) => {
    const s = t.impl;
    if (!me(s)) return null;
    const i = e;
    i.options = s.options;
    const a = new he(i);
    if (!s.allowCustom) return a;
    const r = {};
    r.formBuilder = a.formBuilder;
    const o = n.createInput(s.customInput, r);
    return o && (a.customInput = o), a;
  });
}
function me(n) {
  return n.type === "radio";
}
class ge extends h {
  constructor(t) {
    super(t), this.options = [], this.customInput = null, this.onAddCustomOption = new l(), Object.assign(this, t);
  }
  getOptionElement(t) {
    const e = this.getDataNode(), s = document.createElement("option");
    return s.value = String(t.value), s.selected = e.valueOrDefault === t.value, s.innerText = t.label, e.onChange.add((i) => {
      s.selected = i.value === t.value;
    }), e.onReset.add(() => {
      this.value = void 0, s.selected = e.valueOrDefault === t.value;
    }), s;
  }
  placeHtml(t) {
    const e = this.getQuestionContainer();
    if (e.classList.add("pad-select-input"), this.customInput) {
      const s = document.createElement("button");
      s.innerText = "+", s.type = "button", s.classList.add("pad-add-custom-option"), s.addEventListener("click", () => {
        const a = this.customInput?.getDataNode();
        if (!a || a.value == null || a.value === "" || !a.isValid) return;
        if (this.options.some((o) => o.value === a.value)) {
          this.getDataNode().value = a.value, this.value = a.value;
          return;
        }
        const r = {
          label: String(a.value),
          value: a.value
        };
        this.options.push(r), a.value = void 0, this.onAddCustomOption.emit(new b(r)), this.getDataNode().value = r.value, this.value = r.value;
      });
      const i = document.createElement("div");
      i.classList.add("pad-custom-input-container"), i.append(s), this.customInput.placeHtml(i), e.append(i);
    }
    t.append(e), this.placedHtml.push(e);
  }
  getInputElement() {
    const t = document.createElement("select");
    return t.name = this.getFullPathName(), t.setAttribute("autocomplete", this.autocomplete), t.addEventListener("change", () => {
      const e = this.options.find(
        (s) => String(s.value) === t.value
      );
      if (!e) {
        this.value = null, this.getDataNode().value = null;
        return;
      }
      this.value = e.value, this.getDataNode().value = e.value;
    }), this.getDataNode().onChange.add((e) => {
      t.value = String(e.value);
    }), this.getDataNode().onReset.add(() => {
      this.value = void 0, t.value = String(this.getDataNode().valueOrDefault ?? "");
    }), t.value = String(this.getDataNode().valueOrDefault ?? ""), this.onAddCustomOption.add((e) => {
      t.append(this.getOptionElement(e.newOption));
    }), this.options.forEach((e) => {
      t.append(this.getOptionElement(e));
    }), t;
  }
}
function fe(n) {
  n.registerConstructor("selection", (t, e) => {
    const s = t.impl;
    if (!ve(s)) return null;
    const i = e;
    i.options = s.options;
    const a = new ge(i);
    if (!s.allowCustom) return a;
    const r = {};
    r.formBuilder = a.formBuilder;
    const o = n.createInput(s.customInput, r);
    return o && (a.customInput = o), a;
  });
}
function ve(n) {
  return n.type === "selection";
}
class Ce extends h {
  constructor(t) {
    super(t), this.buttons = {}, Object.assign(this, t);
  }
  placeHtml(t) {
    const e = this.getQuestionContainer();
    e.classList.add("pad-text-editor-input"), t.append(e), this.placedHtml.push(e);
  }
  getInputElement() {
    const t = document.createElement("div");
    t.classList.add("pad-input-field");
    const e = document.createElement("textarea");
    e.id = this.questionId, e.name = this.getFullPathName(), t.append(e), e.innerHTML = this.getDataNode().valueOrDefault ?? "";
    const s = window;
    return typeof s.planadayTinymceV8 > "u" && import("../../../../../../assets/js/tinymce/v8/tinymce.js").then(() => {
      s.planadayTinymceV8 = s.tinymce;
    }), this.initializeTinymce(e), t;
  }
  getSubMenuItems(t, e) {
    const s = [];
    for (const i in e) {
      const a = e[i];
      typeof a == "string" ? s.push({
        type: "menuitem",
        text: i,
        onAction: () => {
          t.insertContent(a);
        }
      }) : s.push({
        type: "nestedmenuitem",
        text: i,
        getSubmenuItems: () => this.getSubMenuItems(t, a)
      });
    }
    return s;
  }
  initializeTinymce(t) {
    const e = window;
    setTimeout(() => {
      if (typeof e.planadayTinymceV8 > "u") {
        this.initializeTinymce(t);
        return;
      }
      e.planadayTinymceV8.init(
        {
          target: t,
          plugins: "link",
          menubar: "visualaid",
          toolbar: "blocks | fontsize forecolor | bold italic underline | align | link" + (Object.keys(this.buttons).length === 0 || Array.isArray(this.buttons) ? "" : " | planaday"),
          setup: (s) => {
            Object.keys(this.buttons).length === 0 || Array.isArray(this.buttons) || s.ui.registry.addMenuButton("planaday", {
              text: "Planaday",
              fetch: (i) => i(this.getSubMenuItems(s, this.buttons))
            }), s.on("input", () => {
              this.value = s.getContent();
            }), this.onChange.add((i) => {
              s.getContent() !== i.value && s.setContent(i.value ?? "");
            }), s.on("change", () => {
              this.saveValue();
            }), this.getDataNode().onChange.add((i) => {
              s.setContent(i.value ?? "");
            }), this.getDataNode().onReset.add(() => {
              this.value = void 0, s.setContent(this.getDataNode().valueOrDefault ?? "");
            });
          },
          license_key: "gpl",
          base_url: "/wp-content/plugins/planaday-connector/assets/js/tinymce/v8/",
          branding: !1,
          promotion: !1
        }
      );
    }, 10);
  }
}
function ye(n) {
  n.registerConstructor("textEditor", (t, e) => {
    const s = t.impl;
    if (!be(s)) return null;
    const i = e;
    return i.buttons = s.buttons, new Ce(i);
  });
}
function be(n) {
  return n.type === "textEditor";
}
class Ee {
  constructor(t, e) {
    this.dataFactory = t, this.FormBuilder = e, this.registeredConstructors = {};
  }
  createInput(t, e) {
    if (typeof t.impl.type != "string") throw new Error("Type is not a string");
    if (typeof this.registeredConstructors[t.impl.type] != "function")
      return console.warn(`Input ${t.impl.type} is not registered`), null;
    const s = e;
    s.index = t.index, s.name = t.name, s.description = t.description, s.autocomplete = t.autocomplete;
    const i = this.registeredConstructors[t.impl.type](t, s);
    if (i == null)
      return console.warn(`Input ${t.impl.type} could not be created`), null;
    const a = this.dataFactory.createDataNode(t.dataType, i);
    if (!a) throw new Error("Data type is not defined");
    const r = new Wt(a);
    return r.index = t.index, r.defaultValue = t.defaultValue, i.setDataNode(r), this.FormBuilder.onCommit.add(() => i.saveValue()), i;
  }
  registerConstructor(t, e) {
    return this.registeredConstructors[t] = e, this;
  }
  setDefaults() {
    return Xt(this), te(this), ie(this), re(this), ue(this), pe(this), fe(this), ye(this), this;
  }
  registerOnComponentFactory(t) {
    t.registerConstructor("input", (e, s) => {
      if (xe(e))
        return this.createInput(e, s);
    });
  }
}
function xe(n) {
  return n.type === "input";
}
class we {
  constructor(t) {
    this.registry = {}, this.onCommit = new l(), this.onClean = new l(), this.onChange = new l(), this.onValidChange = new l(), this.onComponentsCreated = new l(), this.conditionFactory = new X(this).setDefaults(), this.componentFactory = new O(this, this.conditionFactory), this.validatorFactory = new Q(this.conditionFactory).setDefaults(), this.dataFactory = new R(this.validatorFactory).setDefaults(), this.structureFactory = new Vt(this.componentFactory).setDefaults(), this.layoutItemFactory = new Kt().setDefaults(), this.inputFactory = new Ee(this.dataFactory, this).setDefaults(), this.structureFactory.registerOnComponentFactory(this.componentFactory), this.layoutItemFactory.registerOnComponentFactory(this.componentFactory), this.inputFactory.registerOnComponentFactory(this.componentFactory);
    const e = this.componentFactory.createComponent(t);
    if (!(e instanceof y)) throw new Error("invalid config of form");
    this.form = e, e.getDataNode().onChange.add(() => this.onChange.emit(null)), e.getDataNode().onValidChange.add((s) => this.onValidChange.emit(s)), this.onComponentsCreated.emit(null), this.onComponentsCreated.clear();
  }
  manualComponentsCreatedEvent() {
    return this.onComponentsCreated.emit(null), this.onComponentsCreated.clear(), this;
  }
  commit() {
    this.onCommit.emit(null);
  }
  clean() {
    this.onClean.emit(null);
  }
  runValidate() {
    return this.form.getDataNode().validate(!0), this;
  }
  get isValid() {
    return this.form.getDataNode().isValid;
  }
  placeHtml(t) {
    return this.form.placeHtml(t), this;
  }
  loadData(t) {
    return this.form.getDataNode().value = t, this;
  }
  getData(t = !1) {
    return t ? this.form.getDataNode().valueOrDefault : this.form.getDataNode().value;
  }
}
export {
  we as default
};
