"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                                                               */
const Vue = require("vue");
const index$2 = require("../../../../node_modules/@element-plus/icons-vue/dist/index.js");
const common = require("../../packages/utils/common.js");
;/* empty css                                                              */
;/* empty css                                                                */
;/* 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/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/message/index.js");
const index$5 = 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: "field-list-container" };
const _sfc_main = {
  __name: "fieldRecycleBin",
  props: {
    "modelValue": { required: true },
    "modelModifiers": {}
  },
  emits: ["update:modelValue"],
  setup(__props) {
    const dialogVisible = Vue.useModel(__props, "modelValue");
    const editConfigData = Vue.computed(() => {
      return common.getEditConfigData();
    });
    const deletedFields = Vue.ref([]);
    const selectedFields = Vue.ref([]);
    const tableRef = Vue.ref(null);
    Vue.watch(dialogVisible, (val) => {
      if (val) {
        loadDeletedFields();
      }
    });
    const loadDeletedFields = () => {
      deletedFields.value = editConfigData.value.deletedFields || [];
    };
    const handleSelectionChange = (selection) => {
      selectedFields.value = selection;
    };
    const handleRestore = () => {
      if (selectedFields.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;
        selectedFields.value.forEach((field) => {
          const restoredItem = common.cloneDeep(field.data);
          restoredItem.y = currentY;
          currentY += restoredItem.h;
          editConfigData.value.fieldsData.push(restoredItem);
          const index2 = deletedFields.value.findIndex((f) => f === field);
          if (index2 !== -1) {
            deletedFields.value.splice(index2, 1);
          }
        });
      } else if (common.getEditingType() == "table") {
        selectedFields.value.forEach((field) => {
          const restoredItem = common.cloneDeep(field.data);
          editConfigData.value.fieldsData.push(restoredItem);
          const index2 = deletedFields.value.findIndex((f) => f === field);
          if (index2 !== -1) {
            deletedFields.value.splice(index2, 1);
          }
        });
      }
      editConfigData.value.deletedFields = common.cloneDeep(deletedFields.value);
      index$4.ElMessage.success(`已恢复 ${selectedFields.value.length} 个字段`);
      selectedFields.value = [];
    };
    const handlePermanentDelete = async () => {
      if (selectedFields.value.length === 0) return;
      try {
        await index$5.ElMessageBox.confirm(
          `确定要彻底删除选中的 ${selectedFields.value.length} 个字段吗？此操作不可恢复。`,
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
        );
        selectedFields.value.forEach((field) => {
          const index2 = deletedFields.value.findIndex((f) => f === field);
          if (index2 !== -1) {
            deletedFields.value.splice(index2, 1);
          }
        });
        editConfigData.value.deletedFields = common.cloneDeep(deletedFields.value);
        selectedFields.value = [];
        index$4.ElMessage.success("字段已彻底删除");
      } catch {
      }
    };
    const handleClearRecycleBin = async () => {
      if (deletedFields.value.length === 0) return;
      try {
        await index$5.ElMessageBox.confirm(
          "确定要清空回收站吗？此操作将永久删除所有字段，不可恢复。",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
        );
        deletedFields.value = [];
        editConfigData.value.deletedFields = [];
        index$4.ElMessage.success("回收站已清空");
      } catch {
      }
    };
    return (_ctx, _cache) => {
      const _component_el_button = index$1.ElButton;
      const _component_el_table_column = index$3.ElTableColumn;
      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.createVNode(_component_el_button, {
            onClick: _cache[0] || (_cache[0] = ($event) => dialogVisible.value = false)
          }, {
            default: Vue.withCtx(() => _cache[5] || (_cache[5] = [
              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.RefreshRight),
                disabled: selectedFields.value.length === 0,
                onClick: handleRestore
              }, {
                default: Vue.withCtx(() => _cache[2] || (_cache[2] = [
                  Vue.createTextVNode(" 恢复 ")
                ])),
                _: 1
              }, 8, ["icon", "disabled"]),
              Vue.createVNode(_component_el_button, {
                type: "danger",
                icon: Vue.unref(index$2.Delete),
                disabled: selectedFields.value.length === 0,
                onClick: handlePermanentDelete
              }, {
                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),
              plain: "",
              disabled: deletedFields.value.length === 0,
              onClick: handleClearRecycleBin
            }, {
              default: Vue.withCtx(() => _cache[4] || (_cache[4] = [
                Vue.createTextVNode(" 清空回收站 ")
              ])),
              _: 1
            }, 8, ["icon", "disabled"])
          ]),
          Vue.createElementVNode("div", _hoisted_3, [
            Vue.createVNode(_component_el_table, {
              ref_key: "tableRef",
              ref: tableRef,
              data: deletedFields.value,
              onSelectionChange: handleSelectionChange,
              height: "400"
            }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_table_column, {
                  type: "selection",
                  width: "55"
                }),
                Vue.createVNode(_component_el_table_column, {
                  prop: "label",
                  label: "字段标签",
                  "min-width": "120"
                }),
                Vue.createVNode(_component_el_table_column, {
                  prop: "fieldName",
                  label: "字段名称",
                  "min-width": "120"
                }),
                Vue.createVNode(_component_el_table_column, {
                  prop: "fieldType",
                  label: "字段类型",
                  width: "100"
                }),
                Vue.createVNode(_component_el_table_column, {
                  prop: "deleteTime",
                  label: "删除时间",
                  width: "180"
                })
              ]),
              _: 1
            }, 8, ["data"])
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
};
const FieldRecycleBin = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-d770fcac"]]);
exports.default = FieldRecycleBin;
