"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                                                               */
;/* empty css                                                                  */
const Vue = require("vue");
const index$6 = require("../../../../node_modules/@element-plus/icons-vue/dist/index.js");
const common = require("../utils/common.js");
const ValueSelector = require("../../components/ValueSelector.vue.js");
const index = require("../../api/index.js");
;/* empty css            */
const _pluginVue_exportHelper = require("../../../../_virtual/_plugin-vue_export-helper.js");
const index$1 = require("../../../../node_modules/element-plus/es/components/message/index.js");
const index$2 = require("../../../../node_modules/element-plus/es/components/dialog/index.js");
const index$3 = require("../../../../node_modules/element-plus/es/components/form/index.js");
const index$4 = require("../../../../node_modules/element-plus/es/components/select/index.js");
const index$5 = require("../../../../node_modules/element-plus/es/components/button/index.js");
const _hoisted_1 = { class: "config-list" };
const _hoisted_2 = { class: "config-row" };
const _hoisted_3 = { class: "config-list" };
const _hoisted_4 = { class: "config-row" };
const _hoisted_5 = { class: "config-list" };
const _hoisted_6 = { class: "config-row" };
const _hoisted_7 = {
  class: "config-row",
  style: { "margin-top": "10px" }
};
const _hoisted_8 = { class: "dialog-footer" };
const _sfc_main = {
  __name: "index",
  props: {
    "modelValue": { required: true },
    "modelModifiers": {}
  },
  emits: ["update:modelValue"],
  setup(__props, { expose: __expose }) {
    var _a;
    const currentInstance = Vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const dialogVisible = Vue.useModel(__props, "modelValue");
    const prodConfig = Vue.ref(((_a = common.getEditConfigData()) == null ? void 0 : _a.prodConfig) || {});
    Vue.watch(
      () => dialogVisible.value,
      (newVisible) => {
        var _a2;
        if (newVisible) {
          const savedConfig = ((_a2 = common.getEditConfigData()) == null ? void 0 : _a2.prodConfig) || {};
          if (savedConfig.optionConfigs) {
            optionConfigs.value = savedConfig.optionConfigs.map((item) => ({
              ...item,
              id: generateId()
            }));
          }
          if (savedConfig.defaultValueConfigs) {
            defaultValueConfigs.value = savedConfig.defaultValueConfigs.map(
              (item) => ({
                ...item,
                id: generateId()
              })
            );
          }
          if (savedConfig.validationConfigs) {
            validationConfigs.value = savedConfig.validationConfigs.map((item) => ({
              ...item,
              id: generateId()
            }));
          }
          fetchProductConfig();
        }
      }
    );
    const fieldsDataAll = Vue.computed(() => {
      var _a2;
      return [
        ...common.getEditConfigDataFields(),
        ...((_a2 = common.getEditConfigData()) == null ? void 0 : _a2.hiddenFields) || []
      ];
    });
    const parsedConfig = Vue.ref([]);
    const optionConfigs = Vue.ref([]);
    const defaultValueConfigs = Vue.ref([]);
    const validationConfigs = Vue.ref([]);
    function generateId() {
      return Date.now() + Math.random().toString(36).substr(2, 9);
    }
    function addOptionConfig() {
      optionConfigs.value.push({
        id: generateId(),
        pageField: "",
        productConfigField: ""
      });
    }
    function removeOptionConfig(index2) {
      optionConfigs.value.splice(index2, 1);
    }
    function addDefaultValueConfig() {
      defaultValueConfigs.value.push({
        id: generateId(),
        pageField: "",
        productConfigField: ""
      });
    }
    function removeDefaultValueConfig(index2) {
      defaultValueConfigs.value.splice(index2, 1);
    }
    function addValidationConfig() {
      validationConfigs.value.push({
        id: generateId(),
        pageField: "",
        format: "default",
        minProductField: "",
        maxProductField: ""
      });
    }
    function removeValidationConfig(index2) {
      validationConfigs.value.splice(index2, 1);
    }
    const handleClose = (done) => {
      handleCancel();
      done();
    };
    const handleCancel = () => {
      optionConfigs.value = [
        {
          id: generateId(),
          pageField: "",
          productConfigField: ""
        }
      ];
      defaultValueConfigs.value = [
        {
          id: generateId(),
          pageField: "",
          productConfigField: ""
        }
      ];
      validationConfigs.value = [
        {
          id: generateId(),
          pageField: "",
          minProductField: "",
          maxProductField: ""
        }
      ];
      parsedConfig.value = [];
      dialogVisible.value = false;
    };
    const handleConfirm = () => {
      const editConfig = common.getEditConfigData();
      console.log("🚀 ~ handleConfirm ~ finalConfig.value:", finalConfig.value);
      const updatedConfig = {
        ...editConfig,
        prodConfig: finalConfig.value
      };
      common.setEditConfigData(updatedConfig);
      handleCancel();
    };
    const fetchProductConfig = async () => {
      try {
        const response = await index.default.getProductConfig(ctx.$http);
        parsedConfig.value = response.map((item) => ({
          fieldName: item.fieldName || "",
          fieldDesc: item.label || item.fieldName || "",
          // 保留原始数据中的其他字段
          ...item
        }));
        if (parsedConfig.value.length === 0) {
          index$1.ElMessage.warning("未获取到产品配置数据");
        }
      } catch (error) {
        index$1.ElMessage.error("获取产品配置失败");
        console.error("获取产品配置失败:", error);
        parsedConfig.value = [];
      }
    };
    const finalConfig = Vue.computed(() => {
      const result = {
        prodId: prodConfig.value.prodId,
        optionConfigs: optionConfigs.value,
        defaultValueConfigs: defaultValueConfigs.value,
        validationConfigs: validationConfigs.value
      };
      return result;
    });
    __expose({});
    return (_ctx, _cache) => {
      const _component_el_form_item = index$3.ElFormItem;
      const _component_el_option = index$4.ElOption;
      const _component_el_select = index$4.ElSelect;
      const _component_el_button = index$5.ElButton;
      const _component_el_form = index$3.ElForm;
      const _component_el_dialog = index$2.ElDialog;
      return Vue.openBlock(), Vue.createBlock(_component_el_dialog, {
        modelValue: dialogVisible.value,
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => dialogVisible.value = $event),
        title: "产品配置",
        width: "600px",
        "close-on-click-modal": false,
        "before-close": handleClose,
        draggable: "",
        overflow: "",
        "append-to-body": "",
        class: "fec-dev-designer-dialog"
      }, {
        footer: Vue.withCtx(() => [
          Vue.createElementVNode("span", _hoisted_8, [
            Vue.createVNode(_component_el_button, { onClick: handleCancel }, {
              default: Vue.withCtx(() => _cache[12] || (_cache[12] = [
                Vue.createTextVNode("取消")
              ])),
              _: 1
            }),
            Vue.createVNode(_component_el_button, {
              type: "primary",
              onClick: handleConfirm
            }, {
              default: Vue.withCtx(() => _cache[13] || (_cache[13] = [
                Vue.createTextVNode(" 确定 ")
              ])),
              _: 1
            })
          ])
        ]),
        default: Vue.withCtx(() => [
          Vue.createVNode(_component_el_form, {
            "label-position": "top",
            "label-width": "auto",
            model: prodConfig.value
          }, {
            default: Vue.withCtx(() => [
              Vue.createVNode(_component_el_form_item, null, {
                label: Vue.withCtx(() => _cache[2] || (_cache[2] = [
                  Vue.createElementVNode("span", { class: "prod-config-label" }, "产品ID字段", -1)
                ])),
                default: Vue.withCtx(() => [
                  Vue.createVNode(ValueSelector.default, {
                    modelValue: prodConfig.value.prodId,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => prodConfig.value.prodId = $event),
                    readOnly: "",
                    size: "default"
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              Vue.createVNode(_component_el_form_item, null, {
                label: Vue.withCtx(() => _cache[3] || (_cache[3] = [
                  Vue.createElementVNode("span", { class: "prod-config-label" }, "可选项配置", -1)
                ])),
                default: Vue.withCtx(() => [
                  Vue.createElementVNode("div", _hoisted_1, [
                    (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(optionConfigs.value, (item, index2) => {
                      return Vue.openBlock(), Vue.createElementBlock("div", {
                        key: item.id,
                        class: "config-item"
                      }, [
                        Vue.createElementVNode("div", _hoisted_2, [
                          Vue.createVNode(_component_el_select, {
                            modelValue: item.pageField,
                            "onUpdate:modelValue": ($event) => item.pageField = $event,
                            placeholder: "选择页面字段",
                            filterable: "",
                            clearable: "",
                            style: { "width": "200px", "margin-right": "10px" }
                          }, {
                            default: Vue.withCtx(() => [
                              (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(fieldsDataAll.value, (field) => {
                                return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                  key: field.id,
                                  label: field.label,
                                  value: field.id
                                }, null, 8, ["label", "value"]);
                              }), 128))
                            ]),
                            _: 2
                          }, 1032, ["modelValue", "onUpdate:modelValue"]),
                          Vue.createVNode(_component_el_select, {
                            modelValue: item.productConfigField,
                            "onUpdate:modelValue": ($event) => item.productConfigField = $event,
                            placeholder: "选择产品配置项",
                            filterable: "",
                            clearable: "",
                            style: { "width": "250px", "margin-right": "10px" }
                          }, {
                            default: Vue.withCtx(() => [
                              (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(parsedConfig.value, (config) => {
                                return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                  key: config.fieldName,
                                  label: config.fieldDesc,
                                  value: config.fieldName
                                }, null, 8, ["label", "value"]);
                              }), 128))
                            ]),
                            _: 2
                          }, 1032, ["modelValue", "onUpdate:modelValue"]),
                          Vue.createVNode(_component_el_button, {
                            type: "danger",
                            size: "small",
                            link: "",
                            onClick: ($event) => removeOptionConfig(index2)
                          }, {
                            default: Vue.withCtx(() => _cache[4] || (_cache[4] = [
                              Vue.createTextVNode(" 删除 ")
                            ])),
                            _: 2
                          }, 1032, ["onClick"])
                        ])
                      ]);
                    }), 128)),
                    Vue.createVNode(_component_el_button, {
                      type: "primary",
                      size: "small",
                      icon: Vue.unref(index$6.Plus),
                      link: "",
                      onClick: addOptionConfig
                    }, {
                      default: Vue.withCtx(() => _cache[5] || (_cache[5] = [
                        Vue.createTextVNode(" 新增 ")
                      ])),
                      _: 1
                    }, 8, ["icon"])
                  ])
                ]),
                _: 1
              }),
              Vue.createVNode(_component_el_form_item, null, {
                label: Vue.withCtx(() => _cache[6] || (_cache[6] = [
                  Vue.createElementVNode("span", { class: "prod-config-label" }, "默认值配置", -1)
                ])),
                default: Vue.withCtx(() => [
                  Vue.createElementVNode("div", _hoisted_3, [
                    (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(defaultValueConfigs.value, (item, index2) => {
                      return Vue.openBlock(), Vue.createElementBlock("div", {
                        key: item.id,
                        class: "config-item"
                      }, [
                        Vue.createElementVNode("div", _hoisted_4, [
                          Vue.createVNode(_component_el_select, {
                            modelValue: item.pageField,
                            "onUpdate:modelValue": ($event) => item.pageField = $event,
                            placeholder: "选择页面字段",
                            filterable: "",
                            clearable: "",
                            style: { "width": "200px", "margin-right": "10px" }
                          }, {
                            default: Vue.withCtx(() => [
                              (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(fieldsDataAll.value, (field) => {
                                return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                  key: field.id,
                                  label: field.label,
                                  value: field.id
                                }, null, 8, ["label", "value"]);
                              }), 128))
                            ]),
                            _: 2
                          }, 1032, ["modelValue", "onUpdate:modelValue"]),
                          Vue.createVNode(_component_el_select, {
                            modelValue: item.productConfigField,
                            "onUpdate:modelValue": ($event) => item.productConfigField = $event,
                            placeholder: "选择产品配置项",
                            filterable: "",
                            clearable: "",
                            style: { "width": "250px", "margin-right": "10px" }
                          }, {
                            default: Vue.withCtx(() => [
                              (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(parsedConfig.value, (config) => {
                                return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                  key: config.fieldName,
                                  label: config.fieldDesc,
                                  value: config.fieldName
                                }, null, 8, ["label", "value"]);
                              }), 128))
                            ]),
                            _: 2
                          }, 1032, ["modelValue", "onUpdate:modelValue"]),
                          Vue.createVNode(_component_el_button, {
                            type: "danger",
                            size: "small",
                            link: "",
                            onClick: ($event) => removeDefaultValueConfig(index2)
                          }, {
                            default: Vue.withCtx(() => _cache[7] || (_cache[7] = [
                              Vue.createTextVNode(" 删除 ")
                            ])),
                            _: 2
                          }, 1032, ["onClick"])
                        ])
                      ]);
                    }), 128)),
                    Vue.createVNode(_component_el_button, {
                      type: "primary",
                      size: "small",
                      icon: Vue.unref(index$6.Plus),
                      link: "",
                      onClick: addDefaultValueConfig
                    }, {
                      default: Vue.withCtx(() => _cache[8] || (_cache[8] = [
                        Vue.createTextVNode(" 新增 ")
                      ])),
                      _: 1
                    }, 8, ["icon"])
                  ])
                ]),
                _: 1
              }),
              Vue.createVNode(_component_el_form_item, null, {
                label: Vue.withCtx(() => _cache[9] || (_cache[9] = [
                  Vue.createElementVNode("span", { class: "prod-config-label" }, "校验配置", -1)
                ])),
                default: Vue.withCtx(() => [
                  Vue.createElementVNode("div", _hoisted_5, [
                    (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(validationConfigs.value, (item, index2) => {
                      return Vue.openBlock(), Vue.createElementBlock("div", {
                        key: item.id,
                        class: "config-item"
                      }, [
                        Vue.createElementVNode("div", _hoisted_6, [
                          Vue.createVNode(_component_el_select, {
                            modelValue: item.pageField,
                            "onUpdate:modelValue": ($event) => item.pageField = $event,
                            placeholder: "选择页面字段",
                            filterable: "",
                            clearable: "",
                            style: { "width": "235px", "margin-right": "10px" }
                          }, {
                            default: Vue.withCtx(() => [
                              (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(fieldsDataAll.value, (field) => {
                                return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                  key: field.id,
                                  label: field.label,
                                  value: field.id
                                }, null, 8, ["label", "value"]);
                              }), 128))
                            ]),
                            _: 2
                          }, 1032, ["modelValue", "onUpdate:modelValue"]),
                          Vue.createVNode(_component_el_select, {
                            modelValue: item.format,
                            "onUpdate:modelValue": ($event) => item.format = $event,
                            placeholder: "格式",
                            clearable: "",
                            style: { "width": "235px", "margin-right": "10px" }
                          }, {
                            default: Vue.withCtx(() => [
                              Vue.createVNode(_component_el_option, {
                                label: "默认格式",
                                value: "default"
                              }),
                              Vue.createVNode(_component_el_option, {
                                label: "金额",
                                value: "amount"
                              }),
                              Vue.createVNode(_component_el_option, {
                                label: "百分比",
                                value: "percent"
                              })
                            ]),
                            _: 2
                          }, 1032, ["modelValue", "onUpdate:modelValue"]),
                          Vue.createVNode(_component_el_button, {
                            type: "danger",
                            size: "small",
                            link: "",
                            onClick: ($event) => removeValidationConfig(index2)
                          }, {
                            default: Vue.withCtx(() => _cache[10] || (_cache[10] = [
                              Vue.createTextVNode(" 删除 ")
                            ])),
                            _: 2
                          }, 1032, ["onClick"])
                        ]),
                        Vue.createElementVNode("div", _hoisted_7, [
                          Vue.createVNode(_component_el_select, {
                            modelValue: item.minProductField,
                            "onUpdate:modelValue": ($event) => item.minProductField = $event,
                            placeholder: "最小值配置项",
                            filterable: "",
                            clearable: "",
                            style: { "width": "235px", "margin-right": "10px" }
                          }, {
                            default: Vue.withCtx(() => [
                              (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(parsedConfig.value, (config) => {
                                return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                  key: config.fieldName,
                                  label: config.fieldDesc,
                                  value: config.fieldName
                                }, null, 8, ["label", "value"]);
                              }), 128))
                            ]),
                            _: 2
                          }, 1032, ["modelValue", "onUpdate:modelValue"]),
                          Vue.createVNode(_component_el_select, {
                            modelValue: item.maxProductField,
                            "onUpdate:modelValue": ($event) => item.maxProductField = $event,
                            placeholder: "最大值配置项",
                            filterable: "",
                            clearable: "",
                            style: { "width": "235px", "margin-right": "10px" }
                          }, {
                            default: Vue.withCtx(() => [
                              (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(parsedConfig.value, (config) => {
                                return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                  key: config.fieldName,
                                  label: config.fieldDesc,
                                  value: config.fieldName
                                }, null, 8, ["label", "value"]);
                              }), 128))
                            ]),
                            _: 2
                          }, 1032, ["modelValue", "onUpdate:modelValue"])
                        ])
                      ]);
                    }), 128)),
                    Vue.createVNode(_component_el_button, {
                      type: "primary",
                      size: "small",
                      icon: Vue.unref(index$6.Plus),
                      link: "",
                      onClick: addValidationConfig
                    }, {
                      default: Vue.withCtx(() => _cache[11] || (_cache[11] = [
                        Vue.createTextVNode(" 新增 ")
                      ])),
                      _: 1
                    }, 8, ["icon"])
                  ])
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["model"])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
};
const ProdDialog = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-cc93f7f2"]]);
exports.default = ProdDialog;
