import { defineComponent as P, inject as $, ref as x, computed as U, resolveComponent as i, openBlock as d, createBlock as v, withCtx as a, createElementVNode as L, createVNode as e, createTextVNode as f, createCommentVNode as q, createElementBlock as E, Fragment as M, renderList as D } from "vue";
import { d as N, i as R, h as I } from "./index-a857af7d.mjs";
const F = { class: "dialog-footer" }, S = /* @__PURE__ */ P({
  __name: "ApiEditorDialog",
  setup(A, { expose: y }) {
    const k = $("context");
    function V(s, l) {
      o.value = s, b = l, c.value = !0;
    }
    const c = x(!1), o = x({});
    let b;
    const g = x(), T = async (s) => {
      s && await s.validate((l) => {
        l && (c.value = !1, b && b(o.value));
      });
    }, _ = U(() => k.codeManager.getCode().data), r = U(() => k.codeManager.getCode().computed);
    return y({ show: V }), (s, l) => {
      const m = i("el-input"), u = i("el-form-item"), n = i("el-option"), p = i("el-select"), C = i("el-form"), w = i("el-button"), B = i("el-dialog");
      return d(), v(B, {
        modelValue: c.value,
        "onUpdate:modelValue": l[13] || (l[13] = (t) => c.value = t),
        title: "API editor",
        "close-on-click-modal": !1,
        "close-on-press-escape": !1
      }, {
        footer: a(() => [
          L("span", F, [
            e(w, {
              onClick: l[11] || (l[11] = (t) => c.value = !1)
            }, {
              default: a(() => [
                f("Cancel")
              ]),
              _: 1
            }),
            e(w, {
              type: "primary",
              onClick: l[12] || (l[12] = (t) => T(g.value))
            }, {
              default: a(() => [
                f(" Save ")
              ]),
              _: 1
            })
          ])
        ]),
        default: a(() => [
          e(C, {
            ref_key: "dataEditorFormRef",
            ref: g,
            model: o.value,
            "label-width": "240px"
          }, {
            default: a(() => [
              e(u, {
                label: "Key",
                prop: "key",
                required: ""
              }, {
                default: a(() => [
                  e(m, {
                    modelValue: o.value.key,
                    "onUpdate:modelValue": l[0] || (l[0] = (t) => o.value.key = t)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              e(u, {
                label: "Description",
                prop: "description"
              }, {
                default: a(() => [
                  e(m, {
                    modelValue: o.value.description,
                    "onUpdate:modelValue": l[1] || (l[1] = (t) => o.value.description = t)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              e(u, {
                label: "Method",
                prop: "method",
                required: ""
              }, {
                default: a(() => [
                  e(p, {
                    modelValue: o.value.method,
                    "onUpdate:modelValue": l[2] || (l[2] = (t) => o.value.method = t)
                  }, {
                    default: a(() => [
                      e(n, {
                        label: "GET",
                        value: "GET"
                      }),
                      e(n, {
                        label: "PUT",
                        value: "PUT"
                      }),
                      e(n, {
                        label: "POST",
                        value: "POST"
                      }),
                      e(n, {
                        label: "DELETE",
                        value: "DELETE"
                      })
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }),
              e(u, {
                label: "URL",
                prop: "url",
                required: ""
              }, {
                default: a(() => [
                  e(m, {
                    modelValue: o.value.url,
                    "onUpdate:modelValue": l[3] || (l[3] = (t) => o.value.url = t)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              e(u, {
                label: "Request type",
                prop: "requestType",
                required: ""
              }, {
                default: a(() => [
                  e(p, {
                    modelValue: o.value.requestType,
                    "onUpdate:modelValue": l[4] || (l[4] = (t) => o.value.requestType = t)
                  }, {
                    default: a(() => [
                      e(n, {
                        label: "None",
                        value: "none"
                      }),
                      e(n, {
                        label: "Para",
                        value: "para"
                      })
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }),
              o.value.requestType != "none" ? (d(), v(u, {
                key: 0,
                label: "Request content mode",
                prop: "requestMode",
                required: ""
              }, {
                default: a(() => [
                  e(p, {
                    modelValue: o.value.requestMode,
                    "onUpdate:modelValue": l[5] || (l[5] = (t) => o.value.requestMode = t)
                  }, {
                    default: a(() => [
                      e(n, {
                        label: "Data",
                        value: "data"
                      }),
                      e(n, {
                        label: "Computed",
                        value: "computed"
                      })
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              })) : q("", !0),
              o.value.requestMode == "data" ? (d(), v(u, {
                key: 1,
                label: "Request content value[Data]",
                prop: "requestContentValueData",
                required: ""
              }, {
                default: a(() => [
                  e(p, {
                    modelValue: o.value.requestContentValueData,
                    "onUpdate:modelValue": l[6] || (l[6] = (t) => o.value.requestContentValueData = t)
                  }, {
                    default: a(() => [
                      (d(!0), E(M, null, D(_.value, (t) => (d(), v(n, {
                        key: t.key,
                        label: t.description,
                        value: t.key
                      }, null, 8, ["label", "value"]))), 128))
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              })) : q("", !0),
              o.value.requestMode == "computed" ? (d(), v(u, {
                key: 2,
                label: "Request content value[Computed]",
                prop: "requestContentValueComputed",
                required: ""
              }, {
                default: a(() => [
                  e(p, {
                    modelValue: o.value.requestContentValueComputed,
                    "onUpdate:modelValue": l[7] || (l[7] = (t) => o.value.requestContentValueComputed = t)
                  }, {
                    default: a(() => [
                      (d(!0), E(M, null, D(r.value, (t) => (d(), v(n, {
                        key: t.key,
                        label: t.description,
                        value: t.key
                      }, null, 8, ["label", "value"]))), 128))
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              })) : q("", !0),
              e(u, {
                label: "Response mode",
                prop: "responseMode",
                required: ""
              }, {
                default: a(() => [
                  e(p, {
                    modelValue: o.value.responseMode,
                    "onUpdate:modelValue": l[8] || (l[8] = (t) => o.value.responseMode = t)
                  }, {
                    default: a(() => [
                      e(n, {
                        label: "None",
                        value: "none"
                      }),
                      e(n, {
                        label: "Data",
                        value: "data"
                      })
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              }),
              o.value.responseMode != "none" ? (d(), v(u, {
                key: 3,
                label: "Response value",
                prop: "responseValue",
                required: ""
              }, {
                default: a(() => [
                  e(p, {
                    modelValue: o.value.responseValue,
                    "onUpdate:modelValue": l[9] || (l[9] = (t) => o.value.responseValue = t)
                  }, {
                    default: a(() => [
                      (d(!0), E(M, null, D(_.value, (t) => (d(), v(n, {
                        key: t.key,
                        label: t.description,
                        value: t.key
                      }, null, 8, ["label", "value"]))), 128))
                    ]),
                    _: 1
                  }, 8, ["modelValue"])
                ]),
                _: 1
              })) : q("", !0),
              o.value.responseMode != "none" ? (d(), v(u, {
                key: 4,
                label: "Response expression",
                prop: "responseExpression"
              }, {
                default: a(() => [
                  e(m, {
                    modelValue: o.value.responseExpression,
                    "onUpdate:modelValue": l[10] || (l[10] = (t) => o.value.responseExpression = t)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              })) : q("", !0)
            ]),
            _: 1
          }, 8, ["model"])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), O = /* @__PURE__ */ P({
  __name: "index",
  setup(A) {
    const y = x(), k = $("context");
    let V = -1;
    function c() {
      V = -1, y.value.show({ method: "GET", requestType: "none", responseMode: "none" }, b);
    }
    function o(r) {
      V = r.$index;
      const s = N(r.row);
      y.value.show(s, b);
    }
    const b = (r) => {
      V < 0 ? _.value.push(r) : _.value[V] = r;
    }, g = (r) => {
      R.confirm(
        "Will you want to delete this API",
        "Warning",
        {
          confirmButtonText: "Yes",
          cancelButtonText: "No",
          type: "warning"
        }
      ).then(() => {
        _.value.splice(r.$index, 1);
      });
    }, T = (r) => {
      R.confirm(
        "Will you want to call this API",
        "Warning",
        {
          confirmButtonText: "Yes",
          cancelButtonText: "No",
          type: "warning"
        }
      ).then(() => {
        k.apiManager.invoke(r.row.key), I({
          message: "API is called.",
          type: "success"
        });
      });
    }, _ = U(() => k.codeManager.getCode().apis);
    return (r, s) => {
      const l = i("el-table-column"), m = i("el-button"), u = i("el-button-group"), n = i("el-table");
      return d(), E(M, null, [
        e(n, {
          data: _.value,
          border: ""
        }, {
          empty: a(() => [
            f(" Please "),
            e(m, {
              type: "primary",
              onClick: s[1] || (s[1] = (p) => c())
            }, {
              default: a(() => [
                f("Add")
              ]),
              _: 1
            }),
            f(" a new record ")
          ]),
          default: a(() => [
            e(l, {
              prop: "key",
              label: "Key"
            }),
            e(l, {
              prop: "description",
              label: "Description"
            }),
            e(l, {
              prop: "method",
              label: "Method"
            }),
            e(l, {
              prop: "url",
              label: "URL"
            }),
            e(l, {
              fixed: "right",
              label: "Operations",
              width: "280px"
            }, {
              default: a((p) => [
                e(u, null, {
                  default: a(() => [
                    e(m, {
                      type: "primary",
                      onClick: s[0] || (s[0] = (C) => c())
                    }, {
                      default: a(() => [
                        f("Add")
                      ]),
                      _: 1
                    }),
                    e(m, {
                      type: "success",
                      onClick: (C) => o(p)
                    }, {
                      default: a(() => [
                        f("Edit")
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    e(m, {
                      type: "danger",
                      onClick: (C) => g(p)
                    }, {
                      default: a(() => [
                        f("Delete")
                      ]),
                      _: 2
                    }, 1032, ["onClick"]),
                    e(m, {
                      type: "warning",
                      onClick: (C) => T(p)
                    }, {
                      default: a(() => [
                        f("Call")
                      ]),
                      _: 2
                    }, 1032, ["onClick"])
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 1
            })
          ]),
          _: 1
        }, 8, ["data"]),
        e(S, {
          ref_key: "apiEditorDialogRef",
          ref: y
        }, null, 512)
      ], 64);
    };
  }
});
export {
  O as default
};
