import { defineComponent as C, ref as _, resolveComponent as d, openBlock as h, createBlock as $, withCtx as o, createElementVNode as S, createVNode as t, createTextVNode as m, inject as E, computed as B, createElementBlock as R, Fragment as j } from "vue";
import { d as M, i as F } from "./index-a857af7d.mjs";
const T = { class: "dialog-footer" }, z = /* @__PURE__ */ C({
  __name: "ComputedEditorDialog",
  setup(D, { expose: v }) {
    const b = _("code");
    function c(l, e) {
      n.value = l, p = e, s.value = !0;
    }
    const s = _(!1), n = _({});
    let p;
    const g = _(), V = async (l) => {
      l && await l.validate((e) => {
        e && (s.value = !1, p && p(n.value));
      });
    };
    return v({ show: c }), (l, e) => {
      const a = d("el-input"), u = d("el-form-item"), r = d("el-alert"), f = d("b-ace-editor"), w = d("el-tab-pane"), x = d("el-tabs"), y = d("el-form"), k = d("el-button"), U = d("el-dialog");
      return h(), $(U, {
        modelValue: s.value,
        "onUpdate:modelValue": e[7] || (e[7] = (i) => s.value = i),
        title: "Computed editor",
        "close-on-click-modal": !1,
        "close-on-press-escape": !1
      }, {
        footer: o(() => [
          S("span", T, [
            t(k, {
              onClick: e[5] || (e[5] = (i) => s.value = !1)
            }, {
              default: o(() => [
                m("Cancel")
              ]),
              _: 1
            }),
            t(k, {
              type: "primary",
              onClick: e[6] || (e[6] = (i) => V(g.value))
            }, {
              default: o(() => [
                m(" Save ")
              ]),
              _: 1
            })
          ])
        ]),
        default: o(() => [
          t(y, {
            ref_key: "dataEditorFormRef",
            ref: g,
            model: n.value,
            "label-width": "120px"
          }, {
            default: o(() => [
              t(u, {
                label: "Key",
                prop: "key",
                required: ""
              }, {
                default: o(() => [
                  t(a, {
                    modelValue: n.value.key,
                    "onUpdate:modelValue": e[0] || (e[0] = (i) => n.value.key = i)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              t(u, {
                label: "Description",
                prop: "description"
              }, {
                default: o(() => [
                  t(a, {
                    modelValue: n.value.description,
                    "onUpdate:modelValue": e[1] || (e[1] = (i) => n.value.description = i)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              t(x, {
                modelValue: b.value,
                "onUpdate:modelValue": e[4] || (e[4] = (i) => b.value = i),
                class: "demo-tabs"
              }, {
                default: o(() => [
                  t(w, {
                    label: "Get code",
                    name: "code"
                  }, {
                    default: o(() => [
                      t(u, {
                        label: "",
                        prop: "code",
                        required: "",
                        "label-width": 1
                      }, {
                        default: o(() => [
                          t(r, {
                            type: "info",
                            closable: !1,
                            title: "Get computed. It has one parameter named 'c' which is page context"
                          }),
                          t(f, {
                            modelValue: n.value.code,
                            "onUpdate:modelValue": e[2] || (e[2] = (i) => n.value.code = i),
                            lang: "javascript",
                            width: "100%",
                            height: "40vh",
                            readonly: !1,
                            "font-size": 14
                          }, null, 8, ["modelValue"])
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  }),
                  t(w, {
                    label: "Set code",
                    name: "codeSet"
                  }, {
                    default: o(() => [
                      t(u, {
                        label: "",
                        prop: "codeSet",
                        "label-width": 1
                      }, {
                        default: o(() => [
                          t(r, {
                            type: "info",
                            closable: !1,
                            title: "Set computed. It has tow parameter,one is named 'c' which is page context and the other is value which is the new value to set"
                          }),
                          t(f, {
                            modelValue: n.value.codeSet,
                            "onUpdate:modelValue": e[3] || (e[3] = (i) => n.value.codeSet = i),
                            lang: "javascript",
                            width: "100%",
                            height: "40vh",
                            readonly: !1,
                            "font-size": 14
                          }, null, 8, ["modelValue"])
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }, 8, ["modelValue"])
            ]),
            _: 1
          }, 8, ["model"])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), A = { class: "dialog-footer" }, I = /* @__PURE__ */ C({
  __name: "ComputedValueDialog",
  setup(D, { expose: v }) {
    const b = E("context"), c = _();
    let s;
    function n(V) {
      s = V, c.value = g(), p.value = !0;
    }
    const p = _(!1);
    function g(V) {
      var e;
      const l = (e = b.computedManager.get(s.key)) == null ? void 0 : e.value;
      return l != null ? typeof l == "string" ? l : JSON.stringify(l, null, 2) : "undefined";
    }
    return v({ show: n }), (V, l) => {
      const e = d("b-ace-editor"), a = d("el-button"), u = d("el-dialog");
      return h(), $(u, {
        modelValue: p.value,
        "onUpdate:modelValue": l[2] || (l[2] = (r) => p.value = r),
        title: "Computed value"
      }, {
        footer: o(() => [
          S("span", A, [
            t(a, {
              onClick: l[1] || (l[1] = (r) => p.value = !1)
            }, {
              default: o(() => [
                m("Close")
              ]),
              _: 1
            })
          ])
        ]),
        default: o(() => [
          t(e, {
            modelValue: c.value,
            "onUpdate:modelValue": l[0] || (l[0] = (r) => c.value = r),
            lang: "json",
            width: "100%",
            height: "50vh",
            readonly: !1,
            "font-size": 14
          }, null, 8, ["modelValue"])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), G = /* @__PURE__ */ C({
  __name: "index",
  setup(D) {
    const v = _(), b = _();
    let c = -1;
    const s = E("context");
    function n() {
      c = -1, v.value.show({ code: "", codeSet: "" }, g);
    }
    function p(a) {
      c = a.$index;
      const u = M(a.row);
      v.value.show(u, g);
    }
    const g = (a) => {
      c < 0 ? e.value.push(a) : (e.value[c] = a, s.computedManager.clear(a.key));
    }, V = (a) => {
      F.confirm(
        "Will you want to delte this computed",
        "Warning",
        {
          confirmButtonText: "Yes",
          cancelButtonText: "No",
          type: "warning"
        }
      ).then(() => {
        e.value.splice(a.$index, 1), s.computedManager.reset(a.row.key);
      });
    }, l = (a) => {
      b.value.show(a.row);
    }, e = B(() => s.codeManager.getCode().computed);
    return (a, u) => {
      const r = d("el-table-column"), f = d("el-button"), w = d("el-button-group"), x = d("el-table");
      return h(), R(j, null, [
        t(x, {
          data: e.value,
          border: ""
        }, {
          empty: o(() => [
            m(" Please "),
            t(f, {
              type: "primary",
              onClick: u[1] || (u[1] = (y) => n())
            }, {
              default: o(() => [
                m("Add")
              ]),
              _: 1
            }),
            m(" a new record ")
          ]),
          default: o(() => [
            t(r, {
              prop: "key",
              label: "Key"
            }),
            t(r, {
              prop: "description",
              label: "Description"
            }),
            t(r, {
              fixed: "right",
              label: "Operations",
              width: "280px"
            }, {
              default: o((y) => [
                t(w, null, {
                  default: o(() => [
                    t(f, {
                      type: "primary",
                      onClick: u[0] || (u[0] = (k) => n())
                    }, {
                      default: o(() => [
                        m("Add")
                      ]),
                      _: 1
                    }),
                    t(f, {
                      type: "success",
                      onClick: (k) => p(y)
                    }, {
                      default: o(() => [
                        m("Edit")
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    t(f, {
                      type: "danger",
                      onClick: (k) => V(y)
                    }, {
                      default: o(() => [
                        m("Delete")
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    t(f, {
                      type: "success",
                      onClick: (k) => l(y)
                    }, {
                      default: o(() => [
                        m("Value")
                      ]),
                      _: 2
                    }, 1032, ["onClick"])
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 1
            })
          ]),
          _: 1
        }, 8, ["data"]),
        t(z, {
          ref_key: "computedEditorDialogRef",
          ref: v
        }, null, 512),
        t(I, {
          ref_key: "computedValueDialogRef",
          ref: b
        }, null, 512)
      ], 64);
    };
  }
});
export {
  G as default
};
