"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                                                               */
require("../../../../node_modules/element-plus/theme-chalk/el-tooltip.css.js");
;/* empty css                                                                 */
;/* empty css                                                              */
;/* empty css                                                              */
;/* empty css                                                            */
;/* empty css                                                                     */
;/* empty css                                                               */
const Vue = require("vue");
const index$2 = require("../../../../node_modules/@element-plus/icons-vue/dist/index.js");
const common = require("../../packages/utils/common.js");
const index$5 = require("../../packages/form/aside/index.js");
const index$6 = require("../../packages/table/aside/index.js");
const ValueSelector = require("../../components/ValueSelector.vue.js");
;/* 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/button/index.js");
const index$3 = require("../../../../node_modules/element-plus/es/components/table/index.js");
const index$4 = require("../../../../node_modules/element-plus/es/components/input/index.js");
const index$7 = require("../../../../node_modules/element-plus/es/components/message/index.js");
const index$8 = require("../../../../node_modules/element-plus/es/components/message-box/index.js");
const _hoisted_1 = { class: "action-bar" };
const _hoisted_2 = { class: "left-buttons" };
const _hoisted_3 = { class: "count-info" };
const _hoisted_4 = { class: "field-list-container" };
const _hoisted_5 = { class: "field-name-cell" };
const _hoisted_6 = { class: "dialog-footer" };
const _sfc_main = {
  __name: "HiddenFieldDialog",
  props: {
    "modelValue": { required: true },
    "modelModifiers": {}
  },
  emits: ["update:modelValue"],
  setup(__props) {
    const dialogVisible = Vue.useModel(__props, "modelValue");
    const tableRef = Vue.ref(null);
    const selectedRows = Vue.ref([]);
    const editConfigData = Vue.computed(() => common.getEditConfigData());
    const hiddenFields = Vue.ref([]);
    Vue.watch(dialogVisible, (val) => {
      if (val) {
        loadHiddenFields();
      }
    });
    const loadHiddenFields = () => {
      var _a;
      hiddenFields.value = (((_a = editConfigData.value) == null ? void 0 : _a.hiddenFields) || []).map(
        (field) => ({
          ...field,
          value: field.value || field.defaultValue
        })
      );
    };
    function handleSelectionChange(rows) {
      selectedRows.value = rows;
    }
    function addHiddenField() {
      const newField = {
        id: Date.now(),
        fieldType: "text",
        type: "widgets",
        label: "",
        fieldName: "",
        value: ""
      };
      hiddenFields.value.push(newField);
      setTimeout(() => {
        const cells = document.querySelectorAll(".el-table__body .el-input input");
        if (cells.length > 0) {
          cells[cells.length - 3].focus();
          cells[cells.length - 3].select();
        }
      }, 100);
    }
    function handleSave() {
      for (const field of hiddenFields.value) {
        if (!field.label.trim()) {
          index$7.ElMessage.warning("标签名不能为空");
          return;
        }
        if (!field.fieldName.trim()) {
          index$7.ElMessage.warning("字段名不能为空");
          return;
        }
      }
      const hiddenFieldNames = hiddenFields.value.map((f) => f.fieldName);
      const formFieldNames = (common.getEditConfigDataFields() || []).map(
        (f) => f.fieldName
      );
      const hiddenDuplicates = hiddenFieldNames.filter(
        (name, index2) => hiddenFieldNames.indexOf(name) !== index2
      );
      if (hiddenDuplicates.length > 0) {
        index$7.ElMessage.error(`隐藏域字段名重复: ${hiddenDuplicates.join(", ")}`);
        return;
      }
      const conflictedFields = hiddenFieldNames.filter(
        (name) => formFieldNames.includes(name)
      );
      if (conflictedFields.length > 0) {
        index$7.ElMessage.error(`与表单字段冲突: ${conflictedFields.join(", ")}`);
        return;
      }
      if (editConfigData.value) {
        editConfigData.value.hiddenFields = common.cloneDeep(hiddenFields.value);
      }
      dialogVisible.value = false;
    }
    function deleteRow(row) {
      index$8.ElMessageBox.confirm("确定要删除此隐藏域吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        const index2 = hiddenFields.value.findIndex((f) => f.id === row.id);
        if (index2 !== -1) {
          hiddenFields.value.splice(index2, 1);
          index$7.ElMessage.success("删除成功");
          if (editConfigData.value) {
            editConfigData.value.hiddenFields = common.cloneDeep(hiddenFields.value);
          }
        }
      }).catch(() => {
      });
    }
    function batchDelete() {
      index$8.ElMessageBox.confirm(
        `确定要删除选中的 ${selectedRows.value.length} 个隐藏域吗？`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        selectedRows.value.forEach((row) => {
          const index2 = hiddenFields.value.findIndex((f) => f.id === row.id);
          if (index2 !== -1) {
            hiddenFields.value.splice(index2, 1);
          }
        });
        selectedRows.value = [];
        index$7.ElMessage.success("批量删除成功");
        if (editConfigData.value) {
          editConfigData.value.hiddenFields = common.cloneDeep(hiddenFields.value);
        }
      }).catch(() => {
      });
    }
    function handleRestore() {
      if (selectedRows.value.length === 0) return;
      if (!editConfigData.value.fieldsData) {
        editConfigData.value.fieldsData = [];
      }
      if (common.getEditingType() == "form") {
        const maxY = editConfigData.value.fieldsData.reduce(
          (max, item) => Math.max(max, item.y + item.h),
          0
        );
        let currentY = maxY;
        selectedRows.value.forEach((field) => {
          let component = common.cloneDeep(field);
          component.defaultValue = field.value;
          delete component.value;
          component.id = component.id + "";
          component.fieldType = component.fieldType || "text";
          component.type = component.type || "widgets";
          component = { ...index$5.defaultProperty, ...component };
          let finalWH = { w: 1, h: 1 };
          if (component.fieldType == "textarea") {
            finalWH = { w: 1, h: 2 };
          } else if (component.fieldType == "subTitle" || component.fieldType == "h2") {
            finalWH = {
              w: editConfigData.value.columns,
              h: 1,
              isResizable: false
            };
          } else if (component.fieldType == "subForm" || component.fieldType == "subTable" || component.fieldType == "approvalHistory") {
            finalWH = { w: editConfigData.value.columns, h: 2 };
          }
          finalWH.y = currentY;
          currentY += finalWH.h;
          const item = {
            x: 0,
            y: finalWH.y,
            w: finalWH.w,
            h: finalWH.h,
            i: component.id,
            isResizable: finalWH.isResizable === false ? false : true,
            component,
            id: component.id
          };
          editConfigData.value.fieldsData.push(item);
          const index2 = hiddenFields.value.findIndex((f) => f.id == field.id);
          if (index2 !== -1) {
            hiddenFields.value.splice(index2, 1);
          }
        });
      } else if (common.getEditingType() == "table") {
        selectedRows.value.forEach((field) => {
          let component = common.cloneDeep(field);
          component.id = component.id + "";
          component.fieldType = component.fieldType || "text";
          component.type = component.type || "widgets";
          component = { ...index$6.defaultProperty, ...component };
          editConfigData.value.fieldsData.push(component);
          const index2 = hiddenFields.value.findIndex((f) => f.id == field.id);
          if (index2 !== -1) {
            hiddenFields.value.splice(index2, 1);
          }
        });
      }
      editConfigData.value.hiddenFields = common.cloneDeep(hiddenFields.value);
      index$7.ElMessage.success(`已恢复 ${selectedRows.value.length} 个字段`);
      selectedRows.value = [];
    }
    return (_ctx, _cache) => {
      const _component_el_button = index$1.ElButton;
      const _component_el_table_column = index$3.ElTableColumn;
      const _component_el_input = index$4.ElInput;
      const _component_el_table = index$3.ElTable;
      const _component_el_dialog = index.ElDialog;
      return Vue.openBlock(), Vue.createBlock(_component_el_dialog, {
        modelValue: dialogVisible.value,
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => dialogVisible.value = $event),
        title: "隐藏域配置",
        width: "900px",
        draggable: "",
        overflow: "",
        "append-to-body": "",
        class: "fec-dev-designer-dialog"
      }, {
        footer: Vue.withCtx(() => [
          Vue.createElementVNode("div", _hoisted_6, [
            Vue.createVNode(_component_el_button, {
              onClick: _cache[0] || (_cache[0] = ($event) => dialogVisible.value = false)
            }, {
              default: Vue.withCtx(() => _cache[6] || (_cache[6] = [
                Vue.createTextVNode("取消")
              ])),
              _: 1
            }),
            Vue.createVNode(_component_el_button, {
              type: "primary",
              onClick: handleSave
            }, {
              default: Vue.withCtx(() => _cache[7] || (_cache[7] = [
                Vue.createTextVNode("保存")
              ])),
              _: 1
            })
          ])
        ]),
        default: Vue.withCtx(() => [
          Vue.createElementVNode("div", _hoisted_1, [
            Vue.createElementVNode("div", _hoisted_2, [
              Vue.createVNode(_component_el_button, {
                type: "primary",
                icon: Vue.unref(index$2.Plus),
                onClick: addHiddenField
              }, {
                default: Vue.withCtx(() => _cache[2] || (_cache[2] = [
                  Vue.createTextVNode(" 添加隐藏域 ")
                ])),
                _: 1
              }, 8, ["icon"]),
              Vue.createVNode(_component_el_button, {
                type: "primary",
                icon: Vue.unref(index$2.RefreshRight),
                disabled: selectedRows.value.length === 0,
                onClick: handleRestore
              }, {
                default: Vue.withCtx(() => _cache[3] || (_cache[3] = [
                  Vue.createTextVNode(" 恢复 ")
                ])),
                _: 1
              }, 8, ["icon", "disabled"]),
              Vue.createVNode(_component_el_button, {
                type: "danger",
                icon: Vue.unref(index$2.Delete),
                disabled: !selectedRows.value.length,
                onClick: batchDelete
              }, {
                default: Vue.withCtx(() => _cache[4] || (_cache[4] = [
                  Vue.createTextVNode(" 批量删除 ")
                ])),
                _: 1
              }, 8, ["icon", "disabled"])
            ]),
            Vue.createElementVNode("div", _hoisted_3, "共 " + Vue.toDisplayString(hiddenFields.value.length) + " 个隐藏域", 1)
          ]),
          Vue.createElementVNode("div", _hoisted_4, [
            Vue.createVNode(_component_el_table, {
              ref_key: "tableRef",
              ref: tableRef,
              data: hiddenFields.value,
              onSelectionChange: handleSelectionChange,
              height: "400"
            }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_table_column, {
                  type: "selection",
                  width: "50"
                }),
                Vue.createVNode(_component_el_table_column, {
                  label: "标签名",
                  width: "160"
                }, {
                  default: Vue.withCtx(({ row }) => [
                    Vue.createVNode(_component_el_input, {
                      modelValue: row.label,
                      "onUpdate:modelValue": ($event) => row.label = $event,
                      placeholder: "请输入标签名"
                    }, null, 8, ["modelValue", "onUpdate:modelValue"])
                  ]),
                  _: 1
                }),
                Vue.createVNode(_component_el_table_column, {
                  label: "字段名",
                  width: "160"
                }, {
                  default: Vue.withCtx(({ row }) => [
                    Vue.createElementVNode("div", _hoisted_5, [
                      Vue.createVNode(_component_el_input, {
                        modelValue: row.fieldName,
                        "onUpdate:modelValue": ($event) => row.fieldName = $event,
                        placeholder: "请输入字段名"
                      }, null, 8, ["modelValue", "onUpdate:modelValue"])
                    ])
                  ]),
                  _: 1
                }),
                Vue.createVNode(_component_el_table_column, { label: "初值" }, {
                  default: Vue.withCtx(({ row }) => [
                    Vue.createVNode(ValueSelector.default, {
                      modelValue: row.value,
                      "onUpdate:modelValue": ($event) => row.value = $event,
                      size: "default"
                    }, null, 8, ["modelValue", "onUpdate:modelValue"])
                  ]),
                  _: 1
                }),
                Vue.createVNode(_component_el_table_column, {
                  label: "操作",
                  width: "120",
                  fixed: "right"
                }, {
                  default: Vue.withCtx(({ row }) => [
                    Vue.createVNode(_component_el_button, {
                      link: "",
                      type: "danger",
                      icon: Vue.unref(index$2.Delete),
                      onClick: ($event) => deleteRow(row)
                    }, {
                      default: Vue.withCtx(() => _cache[5] || (_cache[5] = [
                        Vue.createTextVNode(" 删除 ")
                      ])),
                      _: 2
                    }, 1032, ["icon", "onClick"])
                  ]),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["data"])
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
};
const HiddenFieldDialog = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-b2acaeb1"]]);
exports.default = HiddenFieldDialog;
