import "../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                          */
/* empty css                                                                */
/* empty css                                                               */
/* empty css                                                             */
/* empty css                                                                  */
import "../../../../node_modules/element-plus/theme-chalk/el-tab-pane.css.mjs";
/* empty css                                                              */
/* empty css                                                                  */
/* empty css                                                               */
/* empty css                                                               */
/* empty css                                                             */
/* empty css                                                            */
/* empty css                                                              */
/* empty css                                                               */
import { useModel, computed, ref, watch, createBlock, openBlock, withCtx, createVNode, unref, createTextVNode, createElementBlock, createCommentVNode, createElementVNode, withKeys, Fragment, renderList, normalizeClass, withDirectives, vShow, toDisplayString, withModifiers } from "vue";
import { Plus as plus_default, Close as close_default, Check as check_default, Edit as edit_default, Delete as delete_default } from "../../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import { getEditConfigData, cloneDeep, getEditConfigDataFields } from "../utils/common.mjs";
import FieldSelection from "./fieldSelection.vue.mjs";
/* empty css                                                              */
/* empty css                                                                */
/* empty css            */
import _export_sfc from "../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElDialog } from "../../../../node_modules/element-plus/es/components/dialog/index.mjs";
import { ElContainer, ElAside, ElHeader, ElMain } from "../../../../node_modules/element-plus/es/components/container/index.mjs";
import { ElButton } from "../../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElInput } from "../../../../node_modules/element-plus/es/components/input/index.mjs";
import { ElTag } from "../../../../node_modules/element-plus/es/components/tag/index.mjs";
import { ElTabs, ElTabPane } from "../../../../node_modules/element-plus/es/components/tabs/index.mjs";
import { ElScrollbar } from "../../../../node_modules/element-plus/es/components/scrollbar/index.mjs";
import { ElMessage } from "../../../../node_modules/element-plus/es/components/message/index.mjs";
const _hoisted_1 = { key: 0 };
const _hoisted_2 = { class: "mode-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: "mode-content" };
const _hoisted_7 = { class: "mode-info-wrapper" };
const _hoisted_8 = { class: "mode-edit-wrapper" };
const _hoisted_9 = { class: "edit-input-group" };
const _hoisted_10 = { class: "edit-actions" };
const _hoisted_11 = { class: "mode-display" };
const _hoisted_12 = { class: "mode-display-content" };
const _hoisted_13 = { class: "mode-name" };
const _hoisted_14 = { class: "mode-key" };
const _hoisted_15 = {
  key: 0,
  class: "mode-actions"
};
const _hoisted_16 = {
  key: 1,
  class: "mode-actions"
};
const _hoisted_17 = { key: 0 };
const _hoisted_18 = {
  key: 1,
  class: "empty-selection"
};
const _hoisted_19 = { class: "dialog-footer" };
const _sfc_main = {
  __name: "index",
  props: {
    "modelValue": { required: true },
    "modelModifiers": {}
  },
  emits: ["update:modelValue"],
  setup(__props) {
    const dialogVisible = useModel(__props, "modelValue");
    const editConfigData = computed(() => {
      return getEditConfigData();
    });
    const modesData = cloneDeep(editConfigData.value.mode || []);
    const fields = computed(() => {
      return getEditConfigDataFields() || [];
    });
    const activeModeIndex = ref(-1);
    const activeTab = ref("fields");
    watch(dialogVisible, (val) => {
      if (val) {
        isEditingNew.value = false;
        editingModeIndex.value = -1;
        if (modesData.length > 0 && activeModeIndex.value === -1) {
          activeModeIndex.value = 0;
        }
      }
    });
    const isEditingNew = ref(false);
    const newModeName = ref("");
    const newModeKey = ref("");
    const editingModeIndex = ref(-1);
    ref("");
    const editingModeName = ref("");
    const editingModeKey = ref("");
    const startAddMode = () => {
      isEditingNew.value = true;
      newModeName.value = "";
      newModeKey.value = "";
    };
    const confirmAddMode = () => {
      if (!newModeName.value.trim() || !newModeKey.value.trim()) {
        ElMessage.warning("请输入模式名称和标识");
        return;
      }
      if (modesData.some((mode) => mode.key === newModeKey.value)) {
        ElMessage.warning("模式标识已存在");
        return;
      }
      modesData.push({
        id: Date.now(),
        name: newModeName.value,
        key: newModeKey.value,
        showFields: [],
        editFields: []
      });
      isEditingNew.value = false;
      newModeName.value = "";
      newModeKey.value = "";
      activeModeIndex.value = modesData.length - 1;
    };
    const cancelAddMode = () => {
      isEditingNew.value = false;
      newModeName.value = "";
      newModeKey.value = "";
    };
    const handleRemoveMode = (index) => {
      modesData.splice(index, 1);
      if (activeModeIndex.value === index) {
        activeModeIndex.value = -1;
      } else if (activeModeIndex.value > index) {
        activeModeIndex.value--;
      }
    };
    const startEditMode = (index) => {
      editingModeIndex.value = index;
      editingModeName.value = modesData[index].name;
      editingModeKey.value = modesData[index].key;
    };
    const confirmEditMode = () => {
      if (editingModeIndex.value === -1) return;
      if (!editingModeName.value.trim()) {
        ElMessage.warning("请输入模式名称");
        return;
      }
      if (!editingModeKey.value.trim()) {
        ElMessage.warning("请输入模式标识");
        return;
      }
      if (modesData.some(
        (mode, idx) => idx !== editingModeIndex.value && mode.key === editingModeKey.value
      )) {
        ElMessage.warning("模式标识已存在");
        return;
      }
      modesData[editingModeIndex.value].name = editingModeName.value;
      modesData[editingModeIndex.value].key = editingModeKey.value;
      editingModeIndex.value = -1;
      editingModeName.value = "";
      editingModeKey.value = "";
    };
    const cancelEditMode = () => {
      editingModeIndex.value = -1;
      editingModeName.value = "";
      editingModeKey.value = "";
    };
    const onConfirm = () => {
      editConfigData.value.mode = modesData;
      dialogVisible.value = false;
    };
    return (_ctx, _cache) => {
      const _component_el_button = ElButton;
      const _component_el_header = ElHeader;
      const _component_el_input = ElInput;
      const _component_el_tag = ElTag;
      const _component_el_main = ElMain;
      const _component_el_container = ElContainer;
      const _component_el_aside = ElAside;
      const _component_el_tab_pane = ElTabPane;
      const _component_el_scrollbar = ElScrollbar;
      const _component_el_tabs = ElTabs;
      const _component_el_dialog = ElDialog;
      return openBlock(), createBlock(_component_el_dialog, {
        modelValue: dialogVisible.value,
        "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => dialogVisible.value = $event),
        width: "60%",
        title: "模式配置",
        draggable: "",
        overflow: "",
        "append-to-body": "",
        class: "fec-dev-designer-dialog"
      }, {
        footer: withCtx(() => [
          createElementVNode("div", _hoisted_19, [
            createVNode(_component_el_button, {
              onClick: _cache[5] || (_cache[5] = ($event) => dialogVisible.value = false)
            }, {
              default: withCtx(() => _cache[14] || (_cache[14] = [
                createTextVNode("取消")
              ])),
              _: 1
            }),
            createVNode(_component_el_button, {
              type: "primary",
              onClick: onConfirm
            }, {
              default: withCtx(() => _cache[15] || (_cache[15] = [
                createTextVNode("确定")
              ])),
              _: 1
            })
          ])
        ]),
        default: withCtx(() => [
          createVNode(_component_el_container, { style: { "border": "1px solid #ebeef5", "border-radius": "4px" } }, {
            default: withCtx(() => [
              createVNode(_component_el_aside, { width: "300px" }, {
                default: withCtx(() => [
                  createVNode(_component_el_container, { style: { "height": "600px" } }, {
                    default: withCtx(() => [
                      createVNode(_component_el_header, {
                        height: "40px",
                        style: { "background-color": "#f2f2f2", "line-height": "40px" }
                      }, {
                        default: withCtx(() => [
                          createVNode(_component_el_button, {
                            type: "primary",
                            link: "",
                            icon: unref(plus_default),
                            onClick: startAddMode
                          }, {
                            default: withCtx(() => _cache[7] || (_cache[7] = [
                              createTextVNode(" 新增模式 ")
                            ])),
                            _: 1
                          }, 8, ["icon"])
                        ]),
                        _: 1
                      }),
                      createVNode(_component_el_main, { style: { "padding": "10px" } }, {
                        default: withCtx(() => [
                          isEditingNew.value ? (openBlock(), createElementBlock("div", _hoisted_1, [
                            createElementVNode("div", _hoisted_2, [
                              createElementVNode("div", _hoisted_3, [
                                createVNode(_component_el_input, {
                                  modelValue: newModeName.value,
                                  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => newModeName.value = $event),
                                  placeholder: "模式名称",
                                  size: "default",
                                  onKeyup: withKeys(confirmAddMode, ["enter"]),
                                  class: "new-item-input"
                                }, null, 8, ["modelValue"]),
                                createVNode(_component_el_input, {
                                  modelValue: newModeKey.value,
                                  "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => newModeKey.value = $event),
                                  placeholder: "模式标识",
                                  size: "default",
                                  onKeyup: withKeys(confirmAddMode, ["enter"]),
                                  class: "new-item-input"
                                }, null, 8, ["modelValue"]),
                                createElementVNode("div", _hoisted_4, [
                                  createVNode(_component_el_button, {
                                    size: "small",
                                    icon: unref(close_default),
                                    onClick: cancelAddMode
                                  }, {
                                    default: withCtx(() => _cache[8] || (_cache[8] = [
                                      createTextVNode(" 取消 ")
                                    ])),
                                    _: 1
                                  }, 8, ["icon"]),
                                  createVNode(_component_el_button, {
                                    type: "primary",
                                    size: "small",
                                    icon: unref(check_default),
                                    onClick: confirmAddMode
                                  }, {
                                    default: withCtx(() => _cache[9] || (_cache[9] = [
                                      createTextVNode(" 确认 ")
                                    ])),
                                    _: 1
                                  }, 8, ["icon"])
                                ])
                              ])
                            ])
                          ])) : createCommentVNode("", true),
                          (openBlock(true), createElementBlock(Fragment, null, renderList(unref(modesData), (mode, index) => {
                            return openBlock(), createElementBlock("div", {
                              key: index,
                              class: normalizeClass([
                                "mode-menu-item",
                                {
                                  "is-active": activeModeIndex.value === index,
                                  "is-default": mode.key === "default"
                                }
                              ]),
                              onClick: ($event) => activeModeIndex.value = index
                            }, [
                              createElementVNode("div", _hoisted_6, [
                                createElementVNode("div", _hoisted_7, [
                                  withDirectives(createElementVNode("div", _hoisted_8, [
                                    createElementVNode("div", _hoisted_9, [
                                      createVNode(_component_el_input, {
                                        maxlength: "30",
                                        modelValue: editingModeName.value,
                                        "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => editingModeName.value = $event),
                                        placeholder: "模式名称",
                                        size: "small",
                                        onKeyup: withKeys(confirmEditMode, ["enter"])
                                      }, null, 8, ["modelValue"]),
                                      createVNode(_component_el_input, {
                                        maxlength: "30",
                                        modelValue: editingModeKey.value,
                                        "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => editingModeKey.value = $event),
                                        placeholder: "模式标识",
                                        size: "small",
                                        onKeyup: withKeys(confirmEditMode, ["enter"])
                                      }, null, 8, ["modelValue"])
                                    ]),
                                    createElementVNode("div", _hoisted_10, [
                                      createVNode(_component_el_button, {
                                        size: "small",
                                        icon: unref(close_default),
                                        onClick: cancelEditMode
                                      }, {
                                        default: withCtx(() => _cache[10] || (_cache[10] = [
                                          createTextVNode("取消")
                                        ])),
                                        _: 1
                                      }, 8, ["icon"]),
                                      createVNode(_component_el_button, {
                                        type: "primary",
                                        size: "small",
                                        icon: unref(check_default),
                                        onClick: confirmEditMode
                                      }, {
                                        default: withCtx(() => _cache[11] || (_cache[11] = [
                                          createTextVNode("确认")
                                        ])),
                                        _: 1
                                      }, 8, ["icon"])
                                    ])
                                  ], 512), [
                                    [vShow, editingModeIndex.value === index]
                                  ]),
                                  withDirectives(createElementVNode("div", _hoisted_11, [
                                    createElementVNode("div", _hoisted_12, [
                                      createElementVNode("div", _hoisted_13, [
                                        createTextVNode(toDisplayString(mode.name) + " ", 1),
                                        mode.key === "default" ? (openBlock(), createBlock(_component_el_tag, {
                                          key: 0,
                                          size: "small",
                                          type: "info",
                                          class: "default-tag"
                                        }, {
                                          default: withCtx(() => _cache[12] || (_cache[12] = [
                                            createTextVNode("系统")
                                          ])),
                                          _: 1
                                        })) : createCommentVNode("", true)
                                      ]),
                                      createElementVNode("div", _hoisted_14, toDisplayString(mode.key), 1)
                                    ]),
                                    mode.key !== "default" ? (openBlock(), createElementBlock("div", _hoisted_15, [
                                      createVNode(_component_el_button, {
                                        size: "small",
                                        text: "",
                                        icon: unref(edit_default),
                                        onClick: withModifiers(($event) => startEditMode(index), ["stop"]),
                                        title: "编辑模式"
                                      }, null, 8, ["icon", "onClick"]),
                                      createVNode(_component_el_button, {
                                        size: "small",
                                        text: "",
                                        type: "danger",
                                        icon: unref(delete_default),
                                        onClick: withModifiers(($event) => handleRemoveMode(index), ["stop"]),
                                        title: "删除模式"
                                      }, null, 8, ["icon", "onClick"])
                                    ])) : (openBlock(), createElementBlock("div", _hoisted_16, [
                                      createVNode(_component_el_button, {
                                        size: "small",
                                        text: "",
                                        icon: unref(edit_default),
                                        disabled: "",
                                        title: "系统模式不可编辑"
                                      }, null, 8, ["icon"]),
                                      createVNode(_component_el_button, {
                                        size: "small",
                                        text: "",
                                        type: "danger",
                                        icon: unref(delete_default),
                                        disabled: "",
                                        title: "系统模式不可删除"
                                      }, null, 8, ["icon"])
                                    ]))
                                  ], 512), [
                                    [vShow, editingModeIndex.value !== index]
                                  ])
                                ])
                              ])
                            ], 10, _hoisted_5);
                          }), 128))
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }),
              createVNode(_component_el_main, { style: { "border-left": "1px solid #ebeef5", "padding": "0" } }, {
                default: withCtx(() => [
                  activeModeIndex.value !== -1 ? (openBlock(), createElementBlock("div", _hoisted_17, [
                    createVNode(_component_el_tabs, {
                      modelValue: activeTab.value,
                      "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => activeTab.value = $event),
                      class: "mode-tab"
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_el_scrollbar, { height: "540px" }, {
                          default: withCtx(() => [
                            createVNode(_component_el_tab_pane, {
                              label: "字段",
                              name: "fields"
                            }, {
                              default: withCtx(() => [
                                createVNode(FieldSelection, {
                                  mode: unref(modesData)[activeModeIndex.value],
                                  fields: fields.value
                                }, null, 8, ["mode", "fields"])
                              ]),
                              _: 1
                            }),
                            createVNode(_component_el_tab_pane, {
                              label: "预留",
                              name: "reserved"
                            }, {
                              default: withCtx(() => _cache[13] || (_cache[13] = [
                                createElementVNode("div", { class: "reserved-content" }, [
                                  createElementVNode("p", null, "预留配置区域")
                                ], -1)
                              ])),
                              _: 1
                            })
                          ]),
                          _: 1
                        })
                      ]),
                      _: 1
                    }, 8, ["modelValue"])
                  ])) : (openBlock(), createElementBlock("div", _hoisted_18, "请从左侧选择一个模式"))
                ]),
                _: 1
              })
            ]),
            _: 1
          })
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
};
const ModeDialog = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-c0bb64e8"]]);
export {
  ModeDialog as default
};
