import { defineComponent as V, ref as k, resolveComponent as a, openBlock as w, createBlock as x, withCtx as t, createElementVNode as D, createVNode as l, createTextVNode as _, toDisplayString as p, inject as U, computed as R, createElementBlock as h, Fragment as I } from "vue";
import { d as T, o as F, n as g } from "./index-e250a75e.mjs";
const M = { class: "dialog-footer" }, j = /* @__PURE__ */ V({
  __name: "LifecycleEditorDialog",
  setup(B, { expose: f }) {
    function c(n, e) {
      d.value = n, m = e, i.value = !0;
    }
    const i = k(!1), d = k({});
    let m;
    const v = k(), $ = async (n) => {
      n && await n.validate((e) => {
        e && (i.value = !1, m && m(d.value));
      });
    };
    return f({ show: c }), (n, e) => {
      const o = a("el-option"), y = a("el-select"), u = a("el-form-item"), C = a("b-ace-editor"), E = a("el-form"), s = a("el-button"), b = a("el-dialog");
      return w(), x(b, {
        modelValue: i.value,
        "onUpdate:modelValue": e[4] || (e[4] = (r) => i.value = r),
        title: "Lifecycle editor",
        "close-on-click-modal": !1,
        "close-on-press-escape": !1
      }, {
        footer: t(() => [
          D("span", M, [
            l(s, {
              onClick: e[2] || (e[2] = (r) => i.value = !1)
            }, {
              default: t(() => [
                _(p(n.$t("_._.cancel")), 1)
              ]),
              _: 1
            }),
            l(s, {
              type: "primary",
              onClick: e[3] || (e[3] = (r) => $(v.value))
            }, {
              default: t(() => [
                _(p(n.$t("_._.save")), 1)
              ]),
              _: 1
            })
          ])
        ]),
        default: t(() => [
          l(E, {
            ref_key: "dataEditorFormRef",
            ref: v,
            model: d.value,
            "label-width": "120px"
          }, {
            default: t(() => [
              l(u, {
                label: n.$t("_.builtIn.plugin.lifecycleEditor.key"),
                prop: "key",
                required: ""
              }, {
                default: t(() => [
                  l(y, {
                    modelValue: d.value.key,
                    "onUpdate:modelValue": e[0] || (e[0] = (r) => d.value.key = r)
                  }, {
                    default: t(() => [
                      l(o, { value: "onMounted" }),
                      l(o, { value: "onUpdated" }),
                      l(o, { value: "onUnmounted" }),
                      l(o, { value: "onBeforeMount" }),
                      l(o, { value: "onBeforeUpdate" }),
                      l(o, { value: "onBeforeUnmount" }),
                      l(o, { value: "onErrorCaptured" }),
                      l(o, { value: "onRenderTracked" }),
                      l(o, { value: "onRenderTracked" }),
                      l(o, { value: "onActivated" }),
                      l(o, { value: "onDeactivated" })
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              l(u, {
                label: n.$t("_.builtIn.plugin.lifecycleEditor.code"),
                prop: "code",
                required: ""
              }, {
                default: t(() => [
                  l(C, {
                    modelValue: d.value.code,
                    "onUpdate:modelValue": e[1] || (e[1] = (r) => d.value.code = r),
                    lang: "javascript",
                    width: "100%",
                    height: "30vh",
                    readonly: !1,
                    "font-size": 14
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"])
            ]),
            _: 1
          }, 8, ["model"])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), L = /* @__PURE__ */ V({
  __name: "index",
  setup(B) {
    const f = k();
    let c = -1;
    const i = U("context");
    function d() {
      c = -1, f.value.show({ mode: "script", code: "" }, v);
    }
    function m(e) {
      c = e.$index;
      const o = T(e.row);
      f.value.show(o, v);
    }
    const v = (e) => {
      c < 0 ? n.value.push(e) : n.value[c] = e;
    }, $ = (e) => {
      F.confirm(
        g("_.builtIn.plugin.lifecycleEditor.deletePrompt"),
        g("_._.warning"),
        {
          confirmButtonText: g("_._.yes"),
          cancelButtonText: g("_._.no"),
          type: "warning"
        }
      ).then(() => {
        n.value.splice(e.$index, 1);
      });
    }, n = R(() => i.codeManager.getCode().lifecycle);
    return (e, o) => {
      const y = a("el-table-column"), u = a("el-button"), C = a("el-button-group"), E = a("el-table");
      return w(), h(I, null, [
        l(E, {
          data: n.value,
          border: ""
        }, {
          empty: t(() => [
            l(u, {
              type: "primary",
              onClick: o[1] || (o[1] = (s) => d())
            }, {
              default: t(() => [
                _(p(e.$t("_._.add")), 1)
              ]),
              _: 1
            })
          ]),
          default: t(() => [
            l(y, {
              prop: "key",
              label: e.$t("_.builtIn.plugin.lifecycleEditor.key")
            }, null, 8, ["label"]),
            l(y, {
              fixed: "right",
              label: e.$t("_._.operation"),
              width: "280px"
            }, {
              default: t((s) => [
                l(C, null, {
                  default: t(() => [
                    l(u, {
                      type: "primary",
                      onClick: o[0] || (o[0] = (b) => d())
                    }, {
                      default: t(() => [
                        _(p(e.$t("_._.add")), 1)
                      ]),
                      _: 1
                    }),
                    l(u, {
                      type: "success",
                      onClick: (b) => m(s)
                    }, {
                      default: t(() => [
                        _(p(e.$t("_._.edit")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    l(u, {
                      type: "danger",
                      onClick: (b) => $(s)
                    }, {
                      default: t(() => [
                        _(p(e.$t("_._.del")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"])
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 1
            }, 8, ["label"])
          ]),
          _: 1
        }, 8, ["data"]),
        l(j, {
          ref_key: "lifecycleEditorDialogRef",
          ref: f
        }, null, 512)
      ], 64);
    };
  }
});
export {
  L as default
};
