import { defineComponent as L, inject as F, ref as M, computed as D, resolveComponent as s, openBlock as i, createBlock as b, withCtx as n, createElementVNode as A, createVNode as e, createTextVNode as g, toDisplayString as V, createCommentVNode as c, createElementBlock as I, Fragment as T, renderList as U } from "vue";
import { d as G, o as P, n as v, k as N } from "./index-e250a75e.mjs";
const O = { class: "dialog-footer" }, j = /* @__PURE__ */ L({
  __name: "ApiEditorDialog",
  setup(R, { expose: k }) {
    const $ = F("context");
    function y(o, l) {
      a.value = o, E = l, _.value = !0;
    }
    const _ = M(!1), a = M({});
    let E;
    const C = M(), w = async (o) => {
      o && await o.validate((l) => {
        l && (_.value = !1, E && E(a.value));
      });
    }, f = D(() => $.codeManager.getCode().data), u = D(() => $.codeManager.getCode().computed);
    return k({ show: y }), (o, l) => {
      const m = s("el-input"), r = s("el-form-item"), d = s("el-option"), p = s("el-select"), q = s("el-form"), B = s("el-button"), S = s("el-dialog");
      return i(), b(S, {
        modelValue: _.value,
        "onUpdate:modelValue": l[13] || (l[13] = (t) => _.value = t),
        title: o.$t("_.builtIn.plugin.apiEditor.dialogTitle"),
        "close-on-click-modal": !1,
        "close-on-press-escape": !1
      }, {
        footer: n(() => [
          A("span", O, [
            e(B, {
              onClick: l[11] || (l[11] = (t) => _.value = !1)
            }, {
              default: n(() => [
                g(V(o.$t("_._.cancel")), 1)
              ]),
              _: 1
            }),
            e(B, {
              type: "primary",
              onClick: l[12] || (l[12] = (t) => w(C.value))
            }, {
              default: n(() => [
                g(V(o.$t("_._.save")), 1)
              ]),
              _: 1
            })
          ])
        ]),
        default: n(() => [
          e(q, {
            ref_key: "dataEditorFormRef",
            ref: C,
            model: a.value,
            "label-width": "240px"
          }, {
            default: n(() => [
              e(r, {
                label: o.$t("_._.key"),
                prop: "key",
                required: ""
              }, {
                default: n(() => [
                  e(m, {
                    modelValue: a.value.key,
                    "onUpdate:modelValue": l[0] || (l[0] = (t) => a.value.key = t)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              e(r, {
                label: o.$t("_._.description"),
                prop: "description"
              }, {
                default: n(() => [
                  e(m, {
                    modelValue: a.value.description,
                    "onUpdate:modelValue": l[1] || (l[1] = (t) => a.value.description = t)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              e(r, {
                label: o.$t("_.builtIn.plugin.apiEditor.data.method"),
                prop: "method",
                required: ""
              }, {
                default: n(() => [
                  e(p, {
                    modelValue: a.value.method,
                    "onUpdate:modelValue": l[2] || (l[2] = (t) => a.value.method = t)
                  }, {
                    default: n(() => [
                      e(d, {
                        label: "GET",
                        value: "GET"
                      }),
                      e(d, {
                        label: "PUT",
                        value: "PUT"
                      }),
                      e(d, {
                        label: "POST",
                        value: "POST"
                      }),
                      e(d, {
                        label: "DELETE",
                        value: "DELETE"
                      })
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              e(r, {
                label: o.$t("_.builtIn.plugin.apiEditor.data.url"),
                prop: "url",
                required: ""
              }, {
                default: n(() => [
                  e(m, {
                    modelValue: a.value.url,
                    "onUpdate:modelValue": l[3] || (l[3] = (t) => a.value.url = t)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              e(r, {
                label: o.$t("_.builtIn.plugin.apiEditor.data.requestType"),
                prop: "requestType",
                required: ""
              }, {
                default: n(() => [
                  e(p, {
                    modelValue: a.value.requestType,
                    "onUpdate:modelValue": l[4] || (l[4] = (t) => a.value.requestType = t)
                  }, {
                    default: n(() => [
                      e(d, {
                        label: o.$t("_.builtIn.plugin.apiEditor.data.requestType_none"),
                        value: "none"
                      }, null, 8, ["label"]),
                      e(d, {
                        label: o.$t("_.builtIn.plugin.apiEditor.data.requestType_para"),
                        value: "para"
                      }, null, 8, ["label"])
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              a.value.requestType != "none" ? (i(), b(r, {
                key: 0,
                label: o.$t("_.builtIn.plugin.apiEditor.data.requestMode"),
                prop: "requestMode",
                required: ""
              }, {
                default: n(() => [
                  e(p, {
                    modelValue: a.value.requestMode,
                    "onUpdate:modelValue": l[5] || (l[5] = (t) => a.value.requestMode = t)
                  }, {
                    default: n(() => [
                      e(d, {
                        label: o.$t("_.builtIn.plugin.apiEditor.data.requestMode_data"),
                        value: "data"
                      }, null, 8, ["label"]),
                      e(d, {
                        label: o.$t("_.builtIn.plugin.apiEditor.data.requestMode_computed"),
                        value: "computed"
                      }, null, 8, ["label"])
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"])) : c("", !0),
              a.value.requestMode == "data" ? (i(), b(r, {
                key: 1,
                label: o.$t("_.builtIn.plugin.apiEditor.data.requestMode_data"),
                prop: "requestContentValueData",
                required: ""
              }, {
                default: n(() => [
                  e(p, {
                    modelValue: a.value.requestContentValueData,
                    "onUpdate:modelValue": l[6] || (l[6] = (t) => a.value.requestContentValueData = t)
                  }, {
                    default: n(() => [
                      (i(!0), I(T, null, U(f.value, (t) => (i(), b(d, {
                        key: t.key,
                        label: t.description,
                        value: t.key
                      }, null, 8, ["label", "value"]))), 128))
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"])) : c("", !0),
              a.value.requestMode == "computed" ? (i(), b(r, {
                key: 2,
                label: o.$t("_.builtIn.plugin.apiEditor.data.requestMode_computed"),
                prop: "requestContentValueComputed",
                required: ""
              }, {
                default: n(() => [
                  e(p, {
                    modelValue: a.value.requestContentValueComputed,
                    "onUpdate:modelValue": l[7] || (l[7] = (t) => a.value.requestContentValueComputed = t)
                  }, {
                    default: n(() => [
                      (i(!0), I(T, null, U(u.value, (t) => (i(), b(d, {
                        key: t.key,
                        label: t.description,
                        value: t.key
                      }, null, 8, ["label", "value"]))), 128))
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"])) : c("", !0),
              e(r, {
                label: o.$t("_.builtIn.plugin.apiEditor.data.responseMode"),
                prop: "responseMode",
                required: ""
              }, {
                default: n(() => [
                  e(p, {
                    modelValue: a.value.responseMode,
                    "onUpdate:modelValue": l[8] || (l[8] = (t) => a.value.responseMode = t)
                  }, {
                    default: n(() => [
                      e(d, {
                        label: o.$t("_.builtIn.plugin.apiEditor.data.responseMode_none"),
                        value: "none"
                      }, null, 8, ["label"]),
                      e(d, {
                        label: o.$t("_.builtIn.plugin.apiEditor.data.responseMode_data"),
                        value: "data"
                      }, null, 8, ["label"])
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"]),
              a.value.responseMode != "none" ? (i(), b(r, {
                key: 3,
                label: o.$t("_.builtIn.plugin.apiEditor.data.responseValue"),
                prop: "responseValue",
                required: ""
              }, {
                default: n(() => [
                  e(p, {
                    modelValue: a.value.responseValue,
                    "onUpdate:modelValue": l[9] || (l[9] = (t) => a.value.responseValue = t)
                  }, {
                    default: n(() => [
                      (i(!0), I(T, null, U(f.value, (t) => (i(), b(d, {
                        key: t.key,
                        label: t.description,
                        value: t.key
                      }, null, 8, ["label", "value"]))), 128))
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"])) : c("", !0),
              a.value.responseMode != "none" ? (i(), b(r, {
                key: 4,
                label: o.$t("_.builtIn.plugin.apiEditor.data.responseExpression"),
                prop: "responseExpression"
              }, {
                default: n(() => [
                  e(m, {
                    modelValue: a.value.responseExpression,
                    "onUpdate:modelValue": l[10] || (l[10] = (t) => a.value.responseExpression = t)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }, 8, ["label"])) : c("", !0)
            ]),
            _: 1
          }, 8, ["model"])
        ]),
        _: 1
      }, 8, ["modelValue", "title"]);
    };
  }
}), J = /* @__PURE__ */ L({
  __name: "index",
  setup(R) {
    const k = M(), $ = F("context");
    let y = -1;
    function _() {
      y = -1, k.value.show({ method: "GET", requestType: "none", responseMode: "none" }, E);
    }
    function a(u) {
      y = u.$index;
      const o = G(u.row);
      k.value.show(o, E);
    }
    const E = (u) => {
      y < 0 ? f.value.push(u) : f.value[y] = u;
    }, C = (u) => {
      P.confirm(
        v("_.builtIn.plugin.apiEditor.deletePrompt"),
        v("_._.warning"),
        {
          confirmButtonText: v("_._.yes"),
          cancelButtonText: v("_._.no"),
          type: "warning"
        }
      ).then(() => {
        f.value.splice(u.$index, 1);
      });
    }, w = (u) => {
      P.confirm(
        v("_.builtIn.plugin.apiEditor.callPrompt"),
        v("_._.warning"),
        {
          confirmButtonText: v("_._.yes"),
          cancelButtonText: v("_._.no"),
          type: "warning"
        }
      ).then(() => {
        $.apiManager.invoke(u.row.key), N({
          message: "API is called.",
          type: "success"
        });
      });
    }, f = D(() => $.codeManager.getCode().apis);
    return (u, o) => {
      const l = s("el-table-column"), m = s("el-button"), r = s("el-button-group"), d = s("el-table");
      return i(), I(T, null, [
        e(d, {
          data: f.value,
          border: ""
        }, {
          empty: n(() => [
            e(m, {
              type: "primary",
              onClick: o[1] || (o[1] = (p) => _())
            }, {
              default: n(() => [
                g(V(u.$t("_._.add")), 1)
              ]),
              _: 1
            })
          ]),
          default: n(() => [
            e(l, {
              prop: "key",
              label: u.$t("_._.key")
            }, null, 8, ["label"]),
            e(l, {
              prop: "description",
              label: u.$t("_._.description")
            }, null, 8, ["label"]),
            e(l, {
              prop: "method",
              label: u.$t("_.builtIn.plugin.apiEditor.data.method")
            }, null, 8, ["label"]),
            e(l, {
              prop: "url",
              label: u.$t("_.builtIn.plugin.apiEditor.data.url")
            }, null, 8, ["label"]),
            e(l, {
              fixed: "right",
              label: u.$t("_._.operation"),
              width: "280px"
            }, {
              default: n((p) => [
                e(r, null, {
                  default: n(() => [
                    e(m, {
                      type: "primary",
                      onClick: o[0] || (o[0] = (q) => _())
                    }, {
                      default: n(() => [
                        g(V(u.$t("_._.add")), 1)
                      ]),
                      _: 1
                    }),
                    e(m, {
                      type: "success",
                      onClick: (q) => a(p)
                    }, {
                      default: n(() => [
                        g(V(u.$t("_._.edit")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    e(m, {
                      type: "danger",
                      onClick: (q) => C(p)
                    }, {
                      default: n(() => [
                        g(V(u.$t("_._.del")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    e(m, {
                      type: "warning",
                      onClick: (q) => w(p)
                    }, {
                      default: n(() => [
                        g(V(u.$t("_.builtIn.plugin.apiEditor.call")), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"])
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 1
            }, 8, ["label"])
          ]),
          _: 1
        }, 8, ["data"]),
        e(j, {
          ref_key: "apiEditorDialogRef",
          ref: k
        }, null, 512)
      ], 64);
    };
  }
});
export {
  J as default
};
