"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                                                          */
require("../../../node_modules/element-plus/theme-chalk/el-config-provider.css.js");
const Vue = require("vue");
const zhCn = require("../../../node_modules/element-plus/es/locale/lang/zh-cn.js");
const index$7 = ;/* empty css                 */
const index$6 = ;/* empty css                  */
const index$8 = ;/* empty css                    */
const index$3 = ;/* empty css                           */
const index$2 = ;/* empty css                          */
const index$1 = require("../store/index.js");
const common = require("../packages/utils/common.js");
const index = require("../api/index.js");
const _default = require("../packages/table/default.js");
const _default$1 = require("../packages/form/default.js");
;/* empty css            */
const _pluginVue_exportHelper = require("../../../_virtual/_plugin-vue_export-helper.js");
const index$4 = require("../../../node_modules/element-plus/es/components/config-provider/index.js");
const index$5 = require("../../../node_modules/element-plus/es/components/container/index.js");
const index$9 = require("../../../node_modules/element-plus/es/components/result/index.js");
const _hoisted_1 = {
  key: 1,
  class: "init-error-container"
};
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const currentInstance = Vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const pkId = getUrlParam("pkId");
    const isInitd = Vue.ref(0);
    const compRef = Vue.ref(null);
    if (!pkId) {
      isInitd.value = -1;
    } else {
      index.default.login4dev(ctx.$http).then((data) => {
        index$1.default.commit("set_token", data.token);
        index$1.default.commit("set_refreshToken", data.refreshToken);
        index.default.getById(ctx.$http, pkId).then((data2) => {
          const templateName = data2.templateName;
          const templateKey = data2.templateKey;
          document.title = templateName || "表单设计器";
          if (data2.type == "table") {
            const tableOptions = Vue.ref({
              pkId,
              templateName,
              templateKey,
              ..._default.defaultTableConfig,
              ...JSON.parse(data2.context)
            });
            common.setEditConfigData(tableOptions.value);
            isInitd.value = 1;
          } else if (data2.type == "form") {
            const formOptions = Vue.ref({
              pkId,
              templateName,
              templateKey,
              ..._default$1.defaultFormConfig,
              ...JSON.parse(data2.context)
            });
            common.setEditConfigData(formOptions.value);
            isInitd.value = 1;
          }
          index$1.default.commit("set_editing_type", data2.type);
        });
      });
    }
    const editingArea = Vue.computed(() => {
      switch (index$1.default.getters.editingType) {
        case "table":
          return index$3.default;
        case "form":
          return index$2.default;
      }
      return null;
    });
    common.setSelectedItem(null);
    common.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 = index$4.ElConfigProvider;
      const _component_el_main = index$5.ElMain;
      const _component_el_container = index$5.ElContainer;
      const _component_el_result = index$9.ElResult;
      return Vue.openBlock(), Vue.createBlock(_component_el_config_provider, { locale: Vue.unref(zhCn.default) }, {
        default: Vue.withCtx(() => [
          isInitd.value == 1 ? (Vue.openBlock(), Vue.createBlock(_component_el_container, {
            key: 0,
            class: "fec-designer-container"
          }, {
            default: Vue.withCtx(() => [
              Vue.createVNode(Vue.unref(index$6.default)),
              Vue.createVNode(_component_el_container, { class: "inner-container" }, {
                default: Vue.withCtx(() => [
                  Vue.createVNode(Vue.unref(index$7.default), { onOnFormDragMove: onFormDragMove }),
                  Vue.createVNode(_component_el_main, { class: "root-main" }, {
                    default: Vue.withCtx(() => [
                      Vue.createVNode(_component_el_config_provider, { locale: Vue.unref(zhCn.default) }, {
                        default: Vue.withCtx(() => [
                          (Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(editingArea.value), {
                            ref_key: "compRef",
                            ref: compRef
                          }, null, 512))
                        ]),
                        _: 1
                      }, 8, ["locale"])
                    ]),
                    _: 1
                  }),
                  Vue.createVNode(Vue.unref(index$8.default))
                ]),
                _: 1
              })
            ]),
            _: 1
          })) : isInitd.value == -1 ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
            Vue.createVNode(_component_el_result, {
              icon: "warning",
              title: "缺少模板ID",
              "sub-title": "请提供有效的模板ID(pkId)参数"
            })
          ])) : Vue.createCommentVNode("", true)
        ]),
        _: 1
      }, 8, ["locale"]);
    };
  }
};
const layout = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-ae1b4337"]]);
exports.default = layout;
