import "../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                       */
/* empty css                                                            */
/* empty css                                                           */
/* empty css                                                               */
/* empty css                                                            */
/* empty css                                                            */
/* empty css                                                          */
import "../../../node_modules/element-plus/theme-chalk/el-config-provider.css.mjs";
import { getCurrentInstance, ref, computed, createBlock, openBlock, unref, withCtx, createElementBlock, createCommentVNode, createVNode, resolveDynamicComponent } from "vue";
import zh_cn_default from "../../../node_modules/element-plus/es/locale/lang/zh-cn.mjs";
import LayoutAside from "./aside/index.vue.mjs";
import _sfc_main$1 from "./header/index.vue.mjs";
import LayoutProperty from "./property/index.vue.mjs";
import tableWorkArea from "../packages/table/index.vue.mjs";
import formWorkArea from "../packages/form/index.vue.mjs";
import store from "../store/index.mjs";
import { setEditConfigData, setSelectedItem, setHoverItem } from "../packages/utils/common.mjs";
import api from "../api/index.mjs";
import { defaultTableConfig } from "../packages/table/default.mjs";
import { defaultFormConfig } from "../packages/form/default.mjs";
/* empty css            */
import _export_sfc from "../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElConfigProvider } from "../../../node_modules/element-plus/es/components/config-provider/index.mjs";
import { ElContainer, ElMain } from "../../../node_modules/element-plus/es/components/container/index.mjs";
import { ElResult } from "../../../node_modules/element-plus/es/components/result/index.mjs";
const _hoisted_1 = {
  key: 1,
  class: "init-error-container"
};
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const currentInstance = getCurrentInstance();
    const ctx = currentInstance.proxy;
    const pkId = getUrlParam("pkId");
    const isInitd = ref(0);
    const compRef = ref(null);
    if (!pkId) {
      isInitd.value = -1;
    } else {
      api.login4dev(ctx.$http).then((data) => {
        store.commit("set_token", data.token);
        store.commit("set_refreshToken", data.refreshToken);
        api.getById(ctx.$http, pkId).then((data2) => {
          const templateName = data2.templateName;
          const templateKey = data2.templateKey;
          document.title = templateName || "表单设计器";
          if (data2.type == "table") {
            const tableOptions = ref({
              pkId,
              templateName,
              templateKey,
              ...defaultTableConfig,
              ...JSON.parse(data2.context)
            });
            setEditConfigData(tableOptions.value);
            isInitd.value = 1;
          } else if (data2.type == "form") {
            const formOptions = ref({
              pkId,
              templateName,
              templateKey,
              ...defaultFormConfig,
              ...JSON.parse(data2.context)
            });
            setEditConfigData(formOptions.value);
            isInitd.value = 1;
          }
          store.commit("set_editing_type", data2.type);
        });
      });
    }
    const editingArea = computed(() => {
      switch (store.getters.editingType) {
        case "table":
          return tableWorkArea;
        case "form":
          return formWorkArea;
      }
      return null;
    });
    setSelectedItem(null);
    setHoverItem(null);
    function onFormDragMove(event) {
      var _a;
      (_a = compRef.value) == null ? void 0 : _a.onFormDragMove(event);
    }
    function getUrlParam(key) {
      const targetUrl = window.location.href;
      const searchStr = targetUrl.split("?")[1] || "";
      if (!searchStr) return null;
      const params = new URLSearchParams(searchStr);
      const values = params.getAll(key);
      if (values.length === 0) return null;
      return values.length === 1 ? values[0] : values;
    }
    return (_ctx, _cache) => {
      const _component_el_config_provider = ElConfigProvider;
      const _component_el_main = ElMain;
      const _component_el_container = ElContainer;
      const _component_el_result = ElResult;
      return openBlock(), createBlock(_component_el_config_provider, { locale: unref(zh_cn_default) }, {
        default: withCtx(() => [
          isInitd.value == 1 ? (openBlock(), createBlock(_component_el_container, {
            key: 0,
            class: "fec-designer-container"
          }, {
            default: withCtx(() => [
              createVNode(unref(_sfc_main$1)),
              createVNode(_component_el_container, { class: "inner-container" }, {
                default: withCtx(() => [
                  createVNode(unref(LayoutAside), { onOnFormDragMove: onFormDragMove }),
                  createVNode(_component_el_main, { class: "root-main" }, {
                    default: withCtx(() => [
                      createVNode(_component_el_config_provider, { locale: unref(zh_cn_default) }, {
                        default: withCtx(() => [
                          (openBlock(), createBlock(resolveDynamicComponent(editingArea.value), {
                            ref_key: "compRef",
                            ref: compRef
                          }, null, 512))
                        ]),
                        _: 1
                      }, 8, ["locale"])
                    ]),
                    _: 1
                  }),
                  createVNode(unref(LayoutProperty))
                ]),
                _: 1
              })
            ]),
            _: 1
          })) : isInitd.value == -1 ? (openBlock(), createElementBlock("div", _hoisted_1, [
            createVNode(_component_el_result, {
              icon: "warning",
              title: "缺少模板ID",
              "sub-title": "请提供有效的模板ID(pkId)参数"
            })
          ])) : createCommentVNode("", true)
        ]),
        _: 1
      }, 8, ["locale"]);
    };
  }
};
const layout = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ae1b4337"]]);
export {
  layout as default
};
