import { defineComponent as S, ref as V, resolveComponent as s, openBlock as D, createBlock as I, withCtx as n, createElementVNode as U, createVNode as a, createTextVNode as y, toDisplayString as g, inject as h, unref as N, createCommentVNode as x, isRef as j, computed as F, createElementBlock as M, Fragment as O } from "vue";
import { E as R, d as T, k as A, n as w, o as z } from "./index-e250a75e.mjs";
const J = { class: "dialog-footer" }, q = /* @__PURE__ */ S({
  __name: "DataEditorDialog",
  setup(B, { expose: k }) {
    function b(d, o) {
      u.value = d, c = o, i.value = !0;
    }
    const i = V(!1), u = V({});
    let c;
    const r = V(), v = async (d) => {
      d && await d.validate((o) => {
        o && (i.value = !1, c && c(u.value));
      });
    };
    return k({ show: b }), (d, o) => {
      const C = s("el-input"), _ = s("el-form-item"), e = s("el-option"), t = s("el-select"), l = s("el-form"), m = s("el-button"), E = s("el-dialog");
      return D(), I(E, {
        modelValue: i.value,
        "onUpdate:modelValue": o[5] || (o[5] = (p) => i.value = p),
        title: d.$t("_.builtIn.plugin.dataEditor.dialogTitle"),
        width: "30%",
        "close-on-click-modal": !1,
        "close-on-press-escape": !1
      }, {
        footer: n(() => [
          U("span", J, [
            a(m, {
              onClick: o[3] || (o[3] = (p) => i.value = !1)
            }, {
              default: n(() => [
                y(g(d.$t("_._.cancel")), 1)
              ]),
              _: 1
            }),
            a(m, {
              type: "primary",
              onClick: o[4] || (o[4] = (p) => v(r.value))
            }, {
              default: n(() => [
                y(g(d.$t("_._.save")), 1)
              ]),
              _: 1
            })
          ])
        ]),
        default: n(() => [
          a(l, {
            ref_key: "dataEditorFormRef",
            ref: r,
            model: u.value,
            "label-width": "120px"
          }, {
            default: n(() => [
              a(_, {
                label: d.$t("_._.key"),
                prop: "key",
                required: ""
              }, {
                default: n(() => [
                  a(C, {
                    modelValue: u.value.key,
                    "onUpdate:modelValue": o[0] || (o[0] = (p) => u.value.key = p)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              a(_, {
                label: d.$t("_._.description"),
                prop: "description"
              }, {
                default: n(() => [
                  a(C, {
                    modelValue: u.value.description,
                    "onUpdate:modelValue": o[1] || (o[1] = (p) => u.value.description = p)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              a(_, {
                label: d.$t("_.builtIn.plugin.dataEditor.type"),
                prop: "type",
                required: ""
              }, {
                default: n(() => [
                  a(t, {
                    modelValue: u.value.type,
                    "onUpdate:modelValue": o[2] || (o[2] = (p) => u.value.type = p)
                  }, {
                    default: n(() => [
                      a(e, {
                        label: "String",
                        value: "String"
                      }),
                      a(e, {
                        label: "Number",
                        value: "Number"
                      }),
                      a(e, {
                        label: "Boolean",
                        value: "Boolean"
                      }),
                      a(e, {
                        label: "Object",
                        value: "Object"
                      }),
                      a(e, {
                        label: "Array",
                        value: "Array"
                      })
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"])
            ]),
            _: 1
          }, 8, ["model"])
        ]),
        _: 1
      }, 8, ["modelValue", "title"]);
    };
  }
}), P = { class: "dialog-footer" }, G = /* @__PURE__ */ S({
  __name: "DataValueDialog",
  setup(B, { expose: k }) {
    const b = h("context"), i = V(), u = V(!0), c = V(!1);
    let r, v = 0;
    function d(t, l) {
      r = t, v = l, i.value = C(t), o.value = !0;
    }
    const o = V(!1);
    function C(t) {
      let l;
      return v == 0 ? l = t.initValue : (l = b.dataManager.get(r.key), l = j(l) ? l.value : l), l != null ? t.type == "String" ? l : JSON.stringify(l, null, 2) : t.type == "Object" ? "{}" : t.type == "Array" ? "[]" : t.type == "String" ? "" : t.type == "Number" ? "0" : t.type == "Boolean" ? "true" : "";
    }
    function _() {
      return r.type == "Object" || r.type == "Array" ? JSON.parse(i.value) : r.type == "String" ? i.value : r.type == "Number" ? parseFloat(i.value) : r.type == "Boolean" ? i.value == "true" : "";
    }
    function e() {
      let t;
      try {
        t = _();
      } catch (l) {
        R({
          title: "Error",
          message: l.message,
          type: "error"
        });
        return;
      }
      v == 0 ? (r.initValue = t, u.value && b.dataManager.set(r.key, t)) : (b.dataManager.set(r.key, t), c.value && (r.initValue = t)), o.value = !1;
    }
    return k({ show: d }), (t, l) => {
      const m = s("b-ace-editor"), E = s("el-switch"), p = s("el-button"), $ = s("el-dialog");
      return D(), I($, {
        modelValue: o.value,
        "onUpdate:modelValue": l[4] || (l[4] = (f) => o.value = f),
        title: t.$t("_.builtIn.plugin.dataEditor.dataValueTitle")
      }, {
        footer: n(() => [
          U("span", P, [
            N(v) == 0 ? (D(), I(E, {
              key: 0,
              style: { "margin-right": "20px" },
              modelValue: u.value,
              "onUpdate:modelValue": l[1] || (l[1] = (f) => u.value = f),
              size: "large",
              "inactive-text": t.$t("_.builtIn.plugin.dataEditor.resetCurrent")
            }, null, 8, ["modelValue", "inactive-text"])) : x("", !0),
            N(v) == 1 ? (D(), I(E, {
              key: 1,
              style: { "margin-right": "20px" },
              modelValue: c.value,
              "onUpdate:modelValue": l[2] || (l[2] = (f) => c.value = f),
              size: "large",
              "inactive-text": t.$t("_.builtIn.plugin.dataEditor.resetInit")
            }, null, 8, ["modelValue", "inactive-text"])) : x("", !0),
            a(p, {
              onClick: l[3] || (l[3] = (f) => o.value = !1)
            }, {
              default: n(() => [
                y(g(t.$t("_._.cancel")), 1)
              ]),
              _: 1
            }),
            a(p, {
              type: "primary",
              onClick: e
            }, {
              default: n(() => [
                y(g(t.$t("_._.save")), 1)
              ]),
              _: 1
            })
          ])
        ]),
        default: n(() => [
          a(m, {
            modelValue: i.value,
            "onUpdate:modelValue": l[0] || (l[0] = (f) => i.value = f),
            lang: "json",
            width: "100%",
            height: "50vh",
            readonly: !1,
            "font-size": 14
          }, null, 8, ["modelValue"])
        ]),
        _: 1
      }, 8, ["modelValue", "title"]);
    };
  }
}), L = /* @__PURE__ */ S({
  __name: "index",
  setup(B) {
    const k = V(), b = V();
    let i = -1;
    const u = h("context");
    function c() {
      i = -1, k.value.show({}, v);
    }
    function r(e) {
      i = e.$index;
      const t = T(e.row);
      k.value.show(t, v);
    }
    const v = (e) => {
      if (i < 0) {
        for (const t of _.value)
          if (t.key == e.key) {
            A.error(w("_.builtIn.plugin.dataEditor.errorExist", [e.key]));
            return;
          }
        _.value.push(e);
      } else
        _.value[i] = e;
    }, d = (e) => {
      z.confirm(
        w("_.builtIn.plugin.dataEditor.deletePrompt"),
        w("_._.warning"),
        {
          confirmButtonText: w("_._.yes"),
          cancelButtonText: w("_._.no"),
          type: "warning"
        }
      ).then(() => {
        _.value.splice(e.$index, 1), u.dataManager.clear(e.row.key);
      });
    }, o = (e) => {
      b.value.show(e.row, 0);
    }, C = (e) => {
      b.value.show(e.row, 1);
    }, _ = F(() => u.codeManager.getCode().data);
    return (e, t) => {
      const l = s("el-table-column"), m = s("el-button"), E = s("el-button-group"), p = s("el-table");
      return D(), M(O, null, [
        a(p, {
          data: _.value,
          border: ""
        }, {
          empty: n(() => [
            a(m, {
              type: "primary",
              onClick: t[1] || (t[1] = ($) => c())
            }, {
              default: n(() => [
                y(g(e.$t("_._.add")), 1)
              ]),
              _: 1
            })
          ]),
          default: n(() => [
            a(l, {
              prop: "key",
              label: e.$t("_._.key")
            }, null, 8, ["label"]),
            a(l, {
              prop: "description",
              label: e.$t("_._.description")
            }, null, 8, ["label"]),
            a(l, {
              prop: "type",
              label: e.$t("_.builtIn.plugin.dataEditor.type")
            }, null, 8, ["label"]),
            a(l, {
              fixed: "right",
              label: e.$t("_._.operation"),
              width: "420px"
            }, {
              default: n(($) => [
                a(E, null, {
                  default: n(() => [
                    a(m, {
                      type: "primary",
                      onClick: t[0] || (t[0] = (f) => c())
                    }, {
                      default: n(() => [
                        y(g(e.$t("_._.add")), 1)
                      ]),
                      _: 1
                    }),
                    a(m, {
                      type: "success",
                      onClick: (f) => r($)
                    }, {
                      default: n(() => [
                        y(g(e.$t("_._.edit")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    a(m, {
                      type: "danger",
                      onClick: (f) => d($)
                    }, {
                      default: n(() => [
                        y(g(e.$t("_._.del")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    a(m, {
                      type: "primary",
                      onClick: (f) => o($)
                    }, {
                      default: n(() => [
                        y(g(e.$t("_.builtIn.plugin.dataEditor.initValue")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    a(m, {
                      type: "success",
                      onClick: (f) => C($)
                    }, {
                      default: n(() => [
                        y(g(e.$t("_.builtIn.plugin.dataEditor.currentValue")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"])
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 1
            }, 8, ["label"])
          ]),
          _: 1
        }, 8, ["data"]),
        a(q, {
          ref_key: "dataEditorDialogRef",
          ref: k
        }, null, 512),
        a(G, {
          ref_key: "dataValueDialogRef",
          ref: b
        }, null, 512)
      ], 64);
    };
  }
});
export {
  L as default
};
