"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../node_modules/element-plus/es/index.js");
;/* empty css                                                          */
;/* empty css                                                                */
;/* empty css                                                               */
;/* empty css                                                              */
;/* empty css                                                                  */
;/* empty css                                                               */
;/* empty css                                                               */
;/* empty css                                                             */
;/* empty css                                                             */
;/* empty css                                                              */
;/* empty css                                                               */
const Vue = require("vue");
const index$3 = require("../../../../node_modules/@element-plus/icons-vue/dist/index.js");
const common = require("../utils/common.js");
const dataSource = require("./dataSource.vue.js");
;/* empty css                                                              */
;/* empty css                                                                */
;/* empty css            */
const _pluginVue_exportHelper = require("../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../node_modules/element-plus/es/components/dialog/index.js");
const index$1 = require("../../../../node_modules/element-plus/es/components/container/index.js");
const index$2 = require("../../../../node_modules/element-plus/es/components/button/index.js");
const index$4 = require("../../../../node_modules/element-plus/es/components/input/index.js");
const index$5 = require("../../../../node_modules/element-plus/es/components/link/index.js");
const index$6 = require("../../../../node_modules/element-plus/es/components/icon/index.js");
const index$7 = require("../../../../node_modules/element-plus/es/components/message/index.js");
const _hoisted_1 = { key: 0 };
const _hoisted_2 = { class: "data-source-menu-item is-editing" };
const _hoisted_3 = { class: "new-item-content" };
const _hoisted_4 = { class: "edit-actions" };
const _hoisted_5 = ["onClick"];
const _hoisted_6 = { class: "data-source-content" };
const _hoisted_7 = { class: "data-source-name-wrapper" };
const _hoisted_8 = {
  key: 1,
  class: "empty-selection"
};
const _hoisted_9 = { class: "dialog-footer" };
const _sfc_main = {
  __name: "index",
  props: {
    "modelValue": { required: true },
    "modelModifiers": {}
  },
  emits: ["update:modelValue"],
  setup(__props) {
    const dialogVisible = Vue.useModel(__props, "modelValue");
    const selectedDataSources = Vue.ref([]);
    const activeDataSourceIndex = Vue.ref(-1);
    Vue.watch(dialogVisible, (val) => {
      if (val) {
        isEditingNew.value = false;
        editingDataSourceIndex.value = -1;
        selectedDataSources.value = common.cloneDeep(common.getEditConfigDataSources());
        if (selectedDataSources.value.length > 0 && activeDataSourceIndex.value === -1) {
          activeDataSourceIndex.value = 0;
        }
      }
    });
    const isEditingNew = Vue.ref(false);
    const newDataSourceName = Vue.ref("");
    const editingDataSourceIndex = Vue.ref(-1);
    const editingDataSourceName = Vue.ref("");
    const startAddDataSource = () => {
      isEditingNew.value = true;
      newDataSourceName.value = "";
    };
    const confirmAddDataSource = () => {
      if (!newDataSourceName.value.trim()) {
        index$7.ElMessage.warning("请输入数据源名称");
        return;
      }
      selectedDataSources.value.push({
        id: Date.now(),
        name: newDataSourceName.value,
        serverName: "",
        url: "",
        method: "post",
        contentType: "json",
        params: []
      });
      isEditingNew.value = false;
      newDataSourceName.value = "";
      activeDataSourceIndex.value = selectedDataSources.value.length - 1;
    };
    const cancelAddDataSource = () => {
      isEditingNew.value = false;
      newDataSourceName.value = "";
    };
    const handleRemoveDataSource = (index2) => {
      selectedDataSources.value.splice(index2, 1);
      if (activeDataSourceIndex.value === index2) {
        activeDataSourceIndex.value = -1;
      } else if (activeDataSourceIndex.value > index2) {
        activeDataSourceIndex.value--;
      }
    };
    const startEditDataSource = (index2) => {
      editingDataSourceIndex.value = index2;
      editingDataSourceName.value = selectedDataSources.value[index2].name;
    };
    const onEditOutside = () => {
      if (editingDataSourceIndex.value !== -1) {
        if (!editingDataSourceName.value.trim()) {
          index$7.ElMessage.warning("请输入数据源名称");
          return;
        }
        selectedDataSources.value[editingDataSourceIndex.value].name = editingDataSourceName.value;
        editingDataSourceIndex.value = -1;
        editingDataSourceName.value = "";
      }
    };
    const onConfirm = () => {
      common.setEditConfigDataSources(selectedDataSources.value);
      dialogVisible.value = false;
    };
    return (_ctx, _cache) => {
      const _component_el_button = index$2.ElButton;
      const _component_el_header = index$1.ElHeader;
      const _component_el_input = index$4.ElInput;
      const _component_el_link = index$5.ElLink;
      const _component_el_icon = index$6.ElIcon;
      const _component_el_main = index$1.ElMain;
      const _component_el_container = index$1.ElContainer;
      const _component_el_aside = index$1.ElAside;
      const _component_el_dialog = index.ElDialog;
      return Vue.openBlock(), Vue.createBlock(_component_el_dialog, {
        modelValue: dialogVisible.value,
        "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => dialogVisible.value = $event),
        width: "50%",
        title: "数据源配置",
        draggable: "",
        overflow: "",
        "append-to-body": "",
        class: "fec-dev-designer-dialog"
      }, {
        footer: Vue.withCtx(() => [
          Vue.createElementVNode("div", _hoisted_9, [
            Vue.createVNode(_component_el_button, {
              onClick: _cache[2] || (_cache[2] = ($event) => dialogVisible.value = false)
            }, {
              default: Vue.withCtx(() => _cache[7] || (_cache[7] = [
                Vue.createTextVNode("取消")
              ])),
              _: 1
            }),
            Vue.createVNode(_component_el_button, {
              type: "primary",
              onClick: onConfirm
            }, {
              default: Vue.withCtx(() => _cache[8] || (_cache[8] = [
                Vue.createTextVNode("确定")
              ])),
              _: 1
            })
          ])
        ]),
        default: Vue.withCtx(() => [
          Vue.createVNode(_component_el_container, { style: { "border": "1px solid #ebeef5", "border-radius": "4px" } }, {
            default: Vue.withCtx(() => [
              Vue.createVNode(_component_el_aside, { width: "300px" }, {
                default: Vue.withCtx(() => [
                  Vue.createVNode(_component_el_container, { style: { "height": "600px" } }, {
                    default: Vue.withCtx(() => [
                      Vue.createVNode(_component_el_header, {
                        height: "40px",
                        style: { "background-color": "#f2f2f2", "line-height": "40px" }
                      }, {
                        default: Vue.withCtx(() => [
                          Vue.createVNode(_component_el_button, {
                            type: "primary",
                            link: "",
                            icon: Vue.unref(index$3.Plus),
                            onClick: startAddDataSource
                          }, {
                            default: Vue.withCtx(() => _cache[4] || (_cache[4] = [
                              Vue.createTextVNode(" 新增数据源 ")
                            ])),
                            _: 1
                          }, 8, ["icon"])
                        ]),
                        _: 1
                      }),
                      Vue.createVNode(_component_el_main, { style: { "padding": "10px" } }, {
                        default: Vue.withCtx(() => [
                          Vue.unref(isEditingNew) ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
                            Vue.createElementVNode("div", _hoisted_2, [
                              Vue.createElementVNode("div", _hoisted_3, [
                                Vue.createVNode(_component_el_input, {
                                  modelValue: Vue.unref(newDataSourceName),
                                  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => Vue.isRef(newDataSourceName) ? newDataSourceName.value = $event : null),
                                  placeholder: "请输入数据源名称",
                                  size: "default",
                                  onKeyup: Vue.withKeys(confirmAddDataSource, ["enter"]),
                                  class: "new-item-input"
                                }, null, 8, ["modelValue"]),
                                Vue.createElementVNode("div", _hoisted_4, [
                                  Vue.createVNode(_component_el_button, {
                                    size: "small",
                                    icon: Vue.unref(index$3.Close),
                                    onClick: cancelAddDataSource
                                  }, {
                                    default: Vue.withCtx(() => _cache[5] || (_cache[5] = [
                                      Vue.createTextVNode(" 取消 ")
                                    ])),
                                    _: 1
                                  }, 8, ["icon"]),
                                  Vue.createVNode(_component_el_button, {
                                    type: "primary",
                                    size: "small",
                                    icon: Vue.unref(index$3.Check),
                                    onClick: confirmAddDataSource
                                  }, {
                                    default: Vue.withCtx(() => _cache[6] || (_cache[6] = [
                                      Vue.createTextVNode(" 确认 ")
                                    ])),
                                    _: 1
                                  }, 8, ["icon"])
                                ])
                              ])
                            ])
                          ])) : Vue.createCommentVNode("", true),
                          (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(selectedDataSources), (dataSource2, index2) => {
                            return Vue.openBlock(), Vue.createElementBlock("div", {
                              key: index2,
                              class: Vue.normalizeClass([
                                "data-source-menu-item",
                                { "is-active": Vue.unref(activeDataSourceIndex) === index2 }
                              ]),
                              onClick: ($event) => activeDataSourceIndex.value = index2
                            }, [
                              Vue.createElementVNode("div", _hoisted_6, [
                                Vue.createElementVNode("div", _hoisted_7, [
                                  Vue.withDirectives(Vue.createVNode(_component_el_input, {
                                    onBlur: ($event) => onEditOutside(),
                                    maxlength: "30",
                                    modelValue: Vue.unref(editingDataSourceName),
                                    "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => Vue.isRef(editingDataSourceName) ? editingDataSourceName.value = $event : null),
                                    size: "small"
                                  }, null, 8, ["onBlur", "modelValue"]), [
                                    [Vue.vShow, Vue.unref(editingDataSourceIndex) === index2]
                                  ]),
                                  Vue.withDirectives(Vue.createVNode(_component_el_link, {
                                    icon: "Edit",
                                    onClick: Vue.withModifiers(($event) => startEditDataSource(index2), ["stop"])
                                  }, {
                                    default: Vue.withCtx(() => [
                                      Vue.createTextVNode(Vue.toDisplayString(dataSource2.name), 1)
                                    ]),
                                    _: 2
                                  }, 1032, ["onClick"]), [
                                    [Vue.vShow, Vue.unref(editingDataSourceIndex) !== index2]
                                  ])
                                ]),
                                Vue.createVNode(_component_el_icon, {
                                  class: "delete-icon",
                                  onClick: Vue.withModifiers(($event) => handleRemoveDataSource(index2), ["stop"])
                                }, {
                                  default: Vue.withCtx(() => [
                                    Vue.createVNode(Vue.unref(index$3.Delete))
                                  ]),
                                  _: 2
                                }, 1032, ["onClick"])
                              ])
                            ], 10, _hoisted_5);
                          }), 128))
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }),
              Vue.createVNode(_component_el_main, { style: { "border-left": "1px solid #ebeef5", "padding": "0" } }, {
                default: Vue.withCtx(() => [
                  Vue.unref(activeDataSourceIndex) !== -1 ? (Vue.openBlock(), Vue.createBlock(dataSource.default, {
                    key: 0,
                    requestConfigData: Vue.unref(selectedDataSources)[Vue.unref(activeDataSourceIndex)]
                  }, null, 8, ["requestConfigData"])) : (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_8, "请从左侧选择一个数据源"))
                ]),
                _: 1
              })
            ]),
            _: 1
          })
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
};
const DataSourceDialog = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-5fe0fbb7"]]);
exports.default = DataSourceDialog;
