import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
/* empty css                                                                    */
/* empty css                                                                         */
/* empty css                                                                */
/* empty css                                                                     */
/* empty css                                                                  */
/* empty css                                                                  */
/* empty css                                                                        */
/* empty css                                                                    */
import "../../../../../node_modules/element-plus/theme-chalk/el-dropdown-menu.css.mjs";
import "../../../../../node_modules/element-plus/theme-chalk/el-dropdown-item.css.mjs";
/* empty css                                                                 */
/* empty css                                                                        */
/* empty css                                                               */
/* empty css                                                                  */
/* empty css                                                                        */
/* empty css                                                                  */
/* empty css                                                                  */
/* empty css                                                                 */
/* empty css                                                                       */
/* empty css                                                                        */
/* empty css                                                                     */
import { getCurrentInstance, computed, ref, watch, createBlock, openBlock, withCtx, createVNode, createElementBlock, createCommentVNode, createTextVNode, Fragment, renderList, createElementVNode, toDisplayString } from "vue";
import { getCurrentItem, getEditConfigData } from "../../utils/common.mjs";
import TemplateSelector from "../../../components/TemplateSelector.vue2.mjs";
import emitter from "../../utils/eventBus.mjs";
import ParamsConfig from "../../../components/ParamsConfig.vue2.mjs";
import api from "../../../api/index.mjs";
import OnlyFLowConfigButton from "../../../components/OnlyFLowConfigButton.vue2.mjs";
/* empty css               */
import _export_sfc from "../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElCollapse, ElCollapseItem } from "../../../../../node_modules/element-plus/es/components/collapse/index.mjs";
import { ElForm, ElFormItem } from "../../../../../node_modules/element-plus/es/components/form/index.mjs";
import { ElInput } from "../../../../../node_modules/element-plus/es/components/input/index.mjs";
import { ElRadioGroup, ElRadioButton } from "../../../../../node_modules/element-plus/es/components/radio/index.mjs";
import { ElSwitch } from "../../../../../node_modules/element-plus/es/components/switch/index.mjs";
import { ElSelect, ElOption } from "../../../../../node_modules/element-plus/es/components/select/index.mjs";
import { ElInputNumber } from "../../../../../node_modules/element-plus/es/components/input-number/index.mjs";
import { ElButton } from "../../../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElDropdown, ElDropdownMenu, ElDropdownItem } from "../../../../../node_modules/element-plus/es/components/dropdown/index.mjs";
const _hoisted_1 = { class: "buttons-config-container" };
const _hoisted_2 = {
  key: 0,
  class: "buttons-table"
};
const _hoisted_3 = { class: "buttons-body" };
const _hoisted_4 = { class: "buttons-cell name-cell" };
const _hoisted_5 = { class: "buttons-cell action-cell" };
const _hoisted_6 = { class: "buttons-footer" };
const _hoisted_7 = { class: "button-dropdown-content" };
const _hoisted_8 = { class: "button-name" };
const _hoisted_9 = { class: "button-type" };
const _sfc_main = {
  __name: "subTable",
  setup(__props) {
    const currentInstance = getCurrentInstance();
    const ctx = currentInstance.proxy;
    const currentItem = computed(() => {
      const item = getCurrentItem();
      if (!item.btnRollback) {
        item.btnRollback = [];
      }
      if (!item.subTableHeightType) {
        item.subTableHeightType = "auto";
      }
      if (!item.subTableMaxHeight) {
        item.subTableMaxHeight = 300;
      }
      return item;
    });
    const activeName = ref(["common"]);
    const subTableOptions = ref(null);
    const subTableBtns = computed(() => {
      var _a, _b, _c;
      const customBtns = ((_b = subTableOptions.value) == null ? void 0 : _b.customBtns.left.concat(
        (_a = subTableOptions.value) == null ? void 0 : _a.customBtns.right
      )) || [];
      return customBtns.concat(((_c = subTableOptions.value) == null ? void 0 : _c.optBtns) || []);
    });
    watch(
      () => {
        var _a;
        return (_a = currentItem.value) == null ? void 0 : _a.subTableId;
      },
      (pkId) => {
        if (pkId) {
          api.getById(ctx.$http, pkId).then((data) => {
            subTableOptions.value = JSON.parse(data.context);
          });
        }
      },
      {
        immediate: true
      }
    );
    function templateSelectorConfirm(data) {
      subTableOptions.value = data;
      currentItem.value.subTableMode = null;
    }
    const tableMode = computed(() => {
      var _a;
      return ((_a = subTableOptions.value) == null ? void 0 : _a.mode) || [];
    });
    function handleTitleModeChange(value) {
      const item = currentItem.value;
      const fieldsData = getEditConfigData().fieldsData;
      const fieldInData = fieldsData == null ? void 0 : fieldsData.find((f) => {
        var _a;
        return ((_a = f.component) == null ? void 0 : _a.id) === item.id;
      });
      if (fieldInData) {
        fieldInData.h = value === "none" ? 2 : 3;
        emitter.emit("resizeEvent");
      }
    }
    function handleButtonSelect(buttonConfig) {
      addButton(buttonConfig);
    }
    function addButton(buttonConfig) {
      if (!currentItem.value.btnRollback) {
        currentItem.value.btnRollback = [];
      }
      currentItem.value.btnRollback.push({
        id: buttonConfig.id,
        label: buttonConfig.label,
        type: buttonConfig.type
      });
    }
    function removeButton(index) {
      if (currentItem.value.btnRollback && index >= 0 && index < currentItem.value.btnRollback.length) {
        currentItem.value.btnRollback.splice(index, 1);
      }
    }
    function handleOnlyFlowConfirm(button, data) {
      button.callbackEventConfig = data;
    }
    return (_ctx, _cache) => {
      const _component_el_input = ElInput;
      const _component_el_form_item = ElFormItem;
      const _component_el_radio_button = ElRadioButton;
      const _component_el_radio_group = ElRadioGroup;
      const _component_el_switch = ElSwitch;
      const _component_el_option = ElOption;
      const _component_el_select = ElSelect;
      const _component_el_input_number = ElInputNumber;
      const _component_el_button = ElButton;
      const _component_el_dropdown_item = ElDropdownItem;
      const _component_el_dropdown_menu = ElDropdownMenu;
      const _component_el_dropdown = ElDropdown;
      const _component_el_form = ElForm;
      const _component_el_collapse_item = ElCollapseItem;
      const _component_el_collapse = ElCollapse;
      return openBlock(), createBlock(_component_el_collapse, {
        class: "setting",
        modelValue: activeName.value,
        "onUpdate:modelValue": _cache[16] || (_cache[16] = ($event) => activeName.value = $event)
      }, {
        default: withCtx(() => [
          createVNode(_component_el_collapse_item, {
            name: "common",
            title: "基本属性"
          }, {
            default: withCtx(() => [
              (openBlock(), createBlock(_component_el_form, {
                "label-position": "top",
                "label-width": "auto",
                model: currentItem.value,
                key: currentItem.value.id
              }, {
                default: withCtx(() => [
                  createVNode(_component_el_form_item, {
                    label: "标题",
                    required: ""
                  }, {
                    default: withCtx(() => [
                      createVNode(_component_el_input, {
                        modelValue: currentItem.value.label,
                        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => currentItem.value.label = $event)
                      }, null, 8, ["modelValue"])
                    ]),
                    _: 1
                  }),
                  createVNode(_component_el_form_item, { label: "标题模式" }, {
                    default: withCtx(() => [
                      createVNode(_component_el_radio_group, {
                        modelValue: currentItem.value.titleMode,
                        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => currentItem.value.titleMode = $event),
                        size: "small",
                        onChange: handleTitleModeChange
                      }, {
                        default: withCtx(() => [
                          createVNode(_component_el_radio_button, { value: "none" }, {
                            default: withCtx(() => _cache[17] || (_cache[17] = [
                              createTextVNode("无")
                            ])),
                            _: 1
                          }),
                          createVNode(_component_el_radio_button, { value: "label" }, {
                            default: withCtx(() => _cache[18] || (_cache[18] = [
                              createTextVNode("标题")
                            ])),
                            _: 1
                          }),
                          createVNode(_component_el_radio_button, { value: "subLabel" }, {
                            default: withCtx(() => _cache[19] || (_cache[19] = [
                              createTextVNode("子标题")
                            ])),
                            _: 1
                          })
                        ]),
                        _: 1
                      }, 8, ["modelValue"])
                    ]),
                    _: 1
                  }),
                  currentItem.value.titleMode != "none" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
                    currentItem.value.titleMode == "label" ? (openBlock(), createBlock(_component_el_form_item, {
                      key: 0,
                      label: "副标题"
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_el_input, {
                          modelValue: currentItem.value.subLabel,
                          "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => currentItem.value.subLabel = $event),
                          rows: 2,
                          type: "textarea",
                          resize: "none"
                        }, null, 8, ["modelValue"])
                      ]),
                      _: 1
                    })) : createCommentVNode("", true)
                  ], 64)) : createCommentVNode("", true),
                  createVNode(_component_el_form_item, { label: "数据来源" }, {
                    default: withCtx(() => [
                      createVNode(_component_el_radio_group, {
                        modelValue: currentItem.value.dataSourceFrom,
                        "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => currentItem.value.dataSourceFrom = $event),
                        size: "small"
                      }, {
                        default: withCtx(() => [
                          createVNode(_component_el_radio_button, { value: "main" }, {
                            default: withCtx(() => _cache[20] || (_cache[20] = [
                              createTextVNode("主页面获取")
                            ])),
                            _: 1
                          }),
                          createVNode(_component_el_radio_button, { value: "self" }, {
                            default: withCtx(() => _cache[21] || (_cache[21] = [
                              createTextVNode("子列表自加载")
                            ])),
                            _: 1
                          })
                        ]),
                        _: 1
                      }, 8, ["modelValue"])
                    ]),
                    _: 1
                  }),
                  currentItem.value.dataSourceFrom == "main" ? (openBlock(), createBlock(_component_el_form_item, {
                    key: 1,
                    label: "字段名称"
                  }, {
                    default: withCtx(() => [
                      createVNode(_component_el_input, {
                        modelValue: currentItem.value.fieldName,
                        "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => currentItem.value.fieldName = $event),
                        placeholder: "主页面数据中存储子列表数据的字段名"
                      }, null, 8, ["modelValue"])
                    ]),
                    _: 1
                  })) : createCommentVNode("", true),
                  currentItem.value.dataSourceFrom == "self" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
                    createVNode(_component_el_form_item, { label: "列表参数" }, {
                      default: withCtx(() => [
                        createVNode(ParamsConfig, {
                          modelValue: currentItem.value.subTableParams,
                          "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => currentItem.value.subTableParams = $event)
                        }, null, 8, ["modelValue"])
                      ]),
                      _: 1
                    }),
                    createVNode(_component_el_form_item, { label: "参数更新重新加载列表" }, {
                      default: withCtx(() => [
                        createVNode(_component_el_switch, {
                          modelValue: currentItem.value.reloadOnParamsChange,
                          "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => currentItem.value.reloadOnParamsChange = $event)
                        }, null, 8, ["modelValue"])
                      ]),
                      _: 1
                    })
                  ], 64)) : createCommentVNode("", true),
                  createVNode(_component_el_form_item, { label: "选择子列表" }, {
                    default: withCtx(() => [
                      createVNode(TemplateSelector, {
                        modelValue: currentItem.value.subTableName,
                        "onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => currentItem.value.subTableName = $event),
                        templateKey: currentItem.value.subTableKey,
                        "onUpdate:templateKey": _cache[8] || (_cache[8] = ($event) => currentItem.value.subTableKey = $event),
                        templateId: currentItem.value.subTableId,
                        "onUpdate:templateId": _cache[9] || (_cache[9] = ($event) => currentItem.value.subTableId = $event),
                        templateType: "table",
                        onConfirm: templateSelectorConfirm
                      }, null, 8, ["modelValue", "templateKey", "templateId"])
                    ]),
                    _: 1
                  }),
                  currentItem.value.subTableId ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
                    createVNode(_component_el_form_item, { label: "列表模式" }, {
                      default: withCtx(() => [
                        createVNode(_component_el_select, {
                          modelValue: currentItem.value.subTableMode,
                          "onUpdate:modelValue": _cache[10] || (_cache[10] = ($event) => currentItem.value.subTableMode = $event),
                          clearable: ""
                        }, {
                          default: withCtx(() => [
                            (openBlock(true), createElementBlock(Fragment, null, renderList(tableMode.value, (mode) => {
                              return openBlock(), createBlock(_component_el_option, {
                                key: mode.key,
                                label: mode.name,
                                value: mode.key
                              }, null, 8, ["label", "value"]);
                            }), 128))
                          ]),
                          _: 1
                        }, 8, ["modelValue"])
                      ]),
                      _: 1
                    }),
                    createVNode(_component_el_form_item, { label: "列表高度" }, {
                      default: withCtx(() => [
                        createVNode(_component_el_radio_group, {
                          modelValue: currentItem.value.subTableHeightType,
                          "onUpdate:modelValue": _cache[11] || (_cache[11] = ($event) => currentItem.value.subTableHeightType = $event),
                          size: "small"
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_el_radio_button, { value: "auto" }, {
                              default: withCtx(() => _cache[22] || (_cache[22] = [
                                createTextVNode("自适应")
                              ])),
                              _: 1
                            }),
                            createVNode(_component_el_radio_button, { value: "max" }, {
                              default: withCtx(() => _cache[23] || (_cache[23] = [
                                createTextVNode("最大高度")
                              ])),
                              _: 1
                            }),
                            createVNode(_component_el_radio_button, { value: "fixed" }, {
                              default: withCtx(() => _cache[24] || (_cache[24] = [
                                createTextVNode("固定高度")
                              ])),
                              _: 1
                            })
                          ]),
                          _: 1
                        }, 8, ["modelValue"])
                      ]),
                      _: 1
                    }),
                    currentItem.value.subTableHeightType == "max" ? (openBlock(), createBlock(_component_el_form_item, {
                      key: 0,
                      label: "最大高度"
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_el_input_number, {
                          modelValue: currentItem.value.subTableMaxHeight,
                          "onUpdate:modelValue": _cache[12] || (_cache[12] = ($event) => currentItem.value.subTableMaxHeight = $event),
                          min: 100,
                          "controls-position": "right",
                          controls: false,
                          style: { "width": "100%" }
                        }, {
                          suffix: withCtx(() => _cache[25] || (_cache[25] = [
                            createTextVNode("px")
                          ])),
                          _: 1
                        }, 8, ["modelValue"])
                      ]),
                      _: 1
                    })) : createCommentVNode("", true),
                    currentItem.value.subTableHeightType == "fixed" ? (openBlock(), createBlock(_component_el_form_item, {
                      key: 1,
                      label: "固定高度"
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_el_input_number, {
                          modelValue: currentItem.value.subTableHeight,
                          "onUpdate:modelValue": _cache[13] || (_cache[13] = ($event) => currentItem.value.subTableHeight = $event),
                          min: 100,
                          "controls-position": "right",
                          controls: false,
                          style: { "width": "100%" }
                        }, {
                          suffix: withCtx(() => _cache[26] || (_cache[26] = [
                            createTextVNode("px")
                          ])),
                          _: 1
                        }, 8, ["modelValue"])
                      ]),
                      _: 1
                    })) : createCommentVNode("", true),
                    createVNode(_component_el_form_item, { label: "是否翻页" }, {
                      default: withCtx(() => [
                        createVNode(_component_el_switch, {
                          modelValue: currentItem.value.isSubTablePagination,
                          "onUpdate:modelValue": _cache[14] || (_cache[14] = ($event) => currentItem.value.isSubTablePagination = $event)
                        }, null, 8, ["modelValue"])
                      ]),
                      _: 1
                    }),
                    createVNode(_component_el_form_item, { label: "是否只读" }, {
                      default: withCtx(() => [
                        createVNode(_component_el_switch, {
                          modelValue: currentItem.value.isSubTableReadOnly,
                          "onUpdate:modelValue": _cache[15] || (_cache[15] = ($event) => currentItem.value.isSubTableReadOnly = $event)
                        }, null, 8, ["modelValue"])
                      ]),
                      _: 1
                    }),
                    createVNode(_component_el_form_item, { label: "列表按钮回调事件" }, {
                      default: withCtx(() => [
                        createElementVNode("div", _hoisted_1, [
                          currentItem.value.btnRollback && currentItem.value.btnRollback.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_2, [
                            _cache[27] || (_cache[27] = createElementVNode("div", { class: "buttons-header" }, [
                              createElementVNode("div", { class: "buttons-cell name-header" }, "按钮"),
                              createElementVNode("div", { class: "buttons-cell action-header" }, "回调事件")
                            ], -1)),
                            createElementVNode("div", _hoisted_3, [
                              (openBlock(true), createElementBlock(Fragment, null, renderList(currentItem.value.btnRollback, (button, index) => {
                                return openBlock(), createElementBlock("div", {
                                  key: button.id,
                                  class: "buttons-row"
                                }, [
                                  createElementVNode("div", _hoisted_4, [
                                    createElementVNode("span", null, toDisplayString(button.label), 1)
                                  ]),
                                  createElementVNode("div", _hoisted_5, [
                                    createVNode(OnlyFLowConfigButton, {
                                      size: "small",
                                      config: button.callbackEventConfig,
                                      onConfirm: (data) => {
                                        handleOnlyFlowConfirm(button, data);
                                      }
                                    }, null, 8, ["config", "onConfirm"]),
                                    createVNode(_component_el_button, {
                                      type: "danger",
                                      size: "small",
                                      onClick: ($event) => removeButton(index),
                                      icon: "Delete",
                                      text: "",
                                      style: { "padding": "0", "background": "transparent" }
                                    }, null, 8, ["onClick"])
                                  ])
                                ]);
                              }), 128))
                            ])
                          ])) : createCommentVNode("", true),
                          createElementVNode("div", _hoisted_6, [
                            createVNode(_component_el_dropdown, {
                              onCommand: handleButtonSelect,
                              trigger: "click",
                              size: "small"
                            }, {
                              dropdown: withCtx(() => [
                                createVNode(_component_el_dropdown_menu, null, {
                                  default: withCtx(() => [
                                    (openBlock(true), createElementBlock(Fragment, null, renderList(subTableBtns.value, (button) => {
                                      return openBlock(), createBlock(_component_el_dropdown_item, {
                                        key: button.id,
                                        command: button,
                                        class: "button-dropdown-item"
                                      }, {
                                        default: withCtx(() => [
                                          createElementVNode("div", _hoisted_7, [
                                            createElementVNode("span", _hoisted_8, toDisplayString(button.label), 1),
                                            createElementVNode("span", _hoisted_9, toDisplayString(button.type === "optBtn" ? "行级" : "自定义"), 1)
                                          ])
                                        ]),
                                        _: 2
                                      }, 1032, ["command"]);
                                    }), 128))
                                  ]),
                                  _: 1
                                })
                              ]),
                              default: withCtx(() => [
                                createVNode(_component_el_button, {
                                  type: "primary",
                                  size: "small",
                                  icon: "Plus",
                                  link: ""
                                }, {
                                  default: withCtx(() => _cache[28] || (_cache[28] = [
                                    createTextVNode(" 新增按钮 ")
                                  ])),
                                  _: 1
                                })
                              ]),
                              _: 1
                            })
                          ])
                        ])
                      ]),
                      _: 1
                    })
                  ], 64)) : createCommentVNode("", true)
                ]),
                _: 1
              }, 8, ["model"]))
            ]),
            _: 1
          })
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
};
const subTable = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-f81c0a82"]]);
export {
  subTable as default
};
