"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-tab-pane.css.js");
;/* empty css                                                              */
;/* empty css                                                                  */
;/* empty css                                                               */
;/* empty css                                                               */
;/* empty css                                                             */
const Vue = require("vue");
const index$4 = ;/* empty css                      */
const defaultProcessData = require("../eventFlow/defaultProcessData.js");
const common = require("../utils/common.js");
;/* 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/container/index.js");
const index$2 = require("../../../../node_modules/element-plus/es/components/icon/index.js");
const index$3 = require("../../../../node_modules/element-plus/es/components/tabs/index.js");
const index$5 = require("../../../../node_modules/element-plus/es/components/button/index.js");
const index$6 = require("../../../../node_modules/element-plus/es/components/message/index.js");
const _hoisted_1 = ["onClick"];
const _hoisted_2 = { class: "event-title" };
const _hoisted_3 = { class: "event-method" };
const _hoisted_4 = { class: "event-label" };
const _hoisted_5 = { class: "tab-content" };
const _hoisted_6 = { class: "dialog-footer" };
const _sfc_main = {
  __name: "pageEvent",
  props: {
    "modelValue": { required: true },
    "modelModifiers": {}
  },
  emits: ["update:modelValue"],
  setup(__props) {
    const dialogVisible = Vue.useModel(__props, "modelValue");
    const editConfigData = Vue.computed(() => {
      return common.getEditConfigData();
    });
    const createEventFlow = () => JSON.parse(JSON.stringify(defaultProcessData.default));
    const pageEvents = Vue.ref([
      {
        name: "onCreated",
        description: "页面加载时触发",
        eventFlow: createEventFlow()
      },
      {
        name: "onUnmounted",
        description: "页面卸载后触发",
        eventFlow: createEventFlow()
      }
    ]);
    const activeEventIndex = Vue.ref(0);
    const activeTab = Vue.ref("eventFlow");
    const eventFlowRefs = Vue.ref({});
    const validationErrors = Vue.ref({});
    Vue.watch(dialogVisible, (val) => {
      if (val) {
        pageEvents.value = common.cloneDeep(
          editConfigData.value.pageEventConfig || pageEvents.value
        );
        if (pageEvents.value.length > 0) {
          activeEventIndex.value = 0;
        }
      }
    });
    const setEventFlowRef = (el, index2) => {
      if (el) {
        eventFlowRefs.value[index2] = el;
      }
    };
    const validateAllEventFlows = async () => {
      var _a;
      validationErrors.value = {};
      const errors = [];
      for (const [index2, ref] of Object.entries(eventFlowRefs.value)) {
        try {
          if (ref == null ? void 0 : ref.validate) {
            await ref.validate();
          }
        } catch (error) {
          validationErrors.value[index2] = true;
          errors.push({
            event: (_a = pageEvents.value[index2]) == null ? void 0 : _a.name,
            errors: error
          });
        }
      }
      if (errors.length > 0) {
        throw errors;
      }
    };
    const handleRemoveEvent = (index2) => {
      pageEvents.value[index2].eventFlow = createEventFlow();
    };
    const onConfirm = async () => {
      try {
        if (activeTab.value === "eventFlow") {
          await validateAllEventFlows();
        }
        editConfigData.value.pageEventConfig = common.cloneDeep(pageEvents.value);
        dialogVisible.value = false;
      } catch (errors) {
        console.error("事件流校验失败:", errors);
        const eventNames = errors.map((e) => e.event).join("、");
        index$6.ElMessage.error(`请完善 ${eventNames} 的事件配置`);
      }
    };
    return (_ctx, _cache) => {
      const _component_el_header = index$1.ElHeader;
      const _component_Delete = Vue.resolveComponent("Delete");
      const _component_el_icon = index$2.ElIcon;
      const _component_el_main = index$1.ElMain;
      const _component_el_container = index$1.ElContainer;
      const _component_el_aside = index$1.ElAside;
      const _component_el_tab_pane = index$3.ElTabPane;
      const _component_el_tabs = index$3.ElTabs;
      const _component_el_button = index$5.ElButton;
      const _component_el_dialog = index.ElDialog;
      return Vue.openBlock(), Vue.createBlock(_component_el_dialog, {
        modelValue: dialogVisible.value,
        "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => dialogVisible.value = $event),
        width: "70%",
        title: "页面事件配置",
        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[1] || (_cache[1] = ($event) => dialogVisible.value = false)
            }, {
              default: Vue.withCtx(() => _cache[6] || (_cache[6] = [
                Vue.createTextVNode("取消")
              ])),
              _: 1
            }),
            Vue.createVNode(_component_el_button, {
              type: "primary",
              onClick: onConfirm
            }, {
              default: Vue.withCtx(() => _cache[7] || (_cache[7] = [
                Vue.createTextVNode(" 确定 ")
              ])),
              _: 1
            })
          ])
        ]),
        default: Vue.withCtx(() => [
          Vue.createVNode(_component_el_container, { style: { "border": "1px solid #ebeef5", "border-radius": "4px" } }, {
            default: Vue.withCtx(() => [
              Vue.createVNode(_component_el_aside, { width: "300px" }, {
                default: Vue.withCtx(() => [
                  Vue.createVNode(_component_el_container, { style: { "height": "600px" } }, {
                    default: Vue.withCtx(() => [
                      Vue.createVNode(_component_el_header, {
                        height: "40px",
                        style: { "background-color": "#f2f2f2" }
                      }, {
                        default: Vue.withCtx(() => _cache[3] || (_cache[3] = [
                          Vue.createElementVNode("span", { class: "dev-header-title" }, "页面生命周期", -1)
                        ])),
                        _: 1
                      }),
                      Vue.createVNode(_component_el_main, { style: { "padding": "10px" } }, {
                        default: Vue.withCtx(() => [
                          (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(pageEvents.value, (event, index2) => {
                            return Vue.openBlock(), Vue.createElementBlock("div", {
                              key: index2,
                              class: Vue.normalizeClass([
                                "event-menu-item",
                                {
                                  "is-active": activeEventIndex.value === index2,
                                  "is-error": validationErrors.value[index2]
                                }
                              ]),
                              onClick: ($event) => activeEventIndex.value = index2
                            }, [
                              Vue.createElementVNode("div", _hoisted_2, [
                                Vue.createElementVNode("div", _hoisted_3, [
                                  Vue.createElementVNode("span", null, [
                                    _cache[4] || (_cache[4] = Vue.createTextVNode("function ")),
                                    Vue.createElementVNode("span", null, Vue.toDisplayString(event.name), 1)
                                  ]),
                                  Vue.createElementVNode("span", _hoisted_4, Vue.toDisplayString(event.description), 1)
                                ]),
                                Vue.createVNode(_component_el_icon, {
                                  class: "delete-icon",
                                  onClick: ($event) => handleRemoveEvent(index2)
                                }, {
                                  default: Vue.withCtx(() => [
                                    Vue.createVNode(_component_Delete)
                                  ]),
                                  _: 2
                                }, 1032, ["onClick"])
                              ])
                            ], 10, _hoisted_1);
                          }), 128))
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }),
              Vue.createVNode(_component_el_main, { style: { "border-left": "1px solid #ebeef5", "padding": "0" } }, {
                default: Vue.withCtx(() => [
                  activeEventIndex.value !== -1 ? (Vue.openBlock(), Vue.createBlock(_component_el_tabs, {
                    key: 0,
                    modelValue: activeTab.value,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => activeTab.value = $event),
                    class: "event-tabs"
                  }, {
                    default: Vue.withCtx(() => [
                      Vue.createVNode(_component_el_tab_pane, {
                        label: "事件流",
                        name: "eventFlow"
                      }, {
                        default: Vue.withCtx(() => [
                          Vue.createElementVNode("div", _hoisted_5, [
                            (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(pageEvents.value, (event, index2) => {
                              return Vue.openBlock(), Vue.createBlock(index$4.default, {
                                key: index2,
                                ref_for: true,
                                ref: (el) => setEventFlowRef(el, index2),
                                process: event.eventFlow,
                                style: Vue.normalizeStyle({
                                  display: activeEventIndex.value === index2 ? "block" : "none"
                                })
                              }, null, 8, ["process", "style"]);
                            }), 128))
                          ])
                        ]),
                        _: 1
                      }),
                      Vue.createVNode(_component_el_tab_pane, {
                        label: "自定义",
                        name: "custom"
                      }, {
                        default: Vue.withCtx(() => _cache[5] || (_cache[5] = [
                          Vue.createElementVNode("div", { class: "tab-content" }, [
                            Vue.createElementVNode("div", { class: "custom-code-area" }, " 自定义 ")
                          ], -1)
                        ])),
                        _: 1
                      })
                    ]),
                    _: 1
                  }, 8, ["modelValue"])) : Vue.createCommentVNode("", true)
                ]),
                _: 1
              })
            ]),
            _: 1
          })
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
};
const PageEvent = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-824c7c40"]]);
exports.default = PageEvent;
