import { ref, inject, computed, onMounted, createElementBlock, openBlock, createBlock, resolveDynamicComponent, unref } from "vue";
import "../../forms/h2/index.mjs";
import { getCurrentVueInstance } from "../../../utils/getInstance.mjs";
import { parseRouteParams, parseSingleParamValue } from "../../../utils/parseRouteParams.mjs";
import { loadComponentByPath } from "../../../utils/common.mjs";
import emitter from "../../../utils/eventBus.mjs";
const _hoisted_1 = { class: "contract-content" };
const path = "/tech/ctr/components/DocCtrInfoComponent";
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "Contract",
  props: {
    config: {
      type: Object,
      required: true
    },
    localConfig: {
      type: Object,
      required: true
    },
    formMode: {
      type: String,
      default: ""
    }
  },
  setup(__props) {
    const props = __props;
    const ctx = getCurrentVueInstance();
    ref("");
    const formData = inject("formData");
    inject("rowHeight");
    inject("gridLayout");
    inject("gridLayoutFieldsData");
    const setFormItemHeight = inject("setFormItemHeight");
    const fieldsData = props.localConfig.fieldsData.map((item) => {
      return item.component;
    });
    const hiddenFields = props.localConfig.hiddenFields;
    const parsedParams = parseRouteParams(props.config.params, formData.value, [
      ...fieldsData,
      ...hiddenFields
    ]);
    const busNo = parseSingleParamValue(props.config.busNo, formData.value, [
      ...fieldsData,
      ...hiddenFields
    ]);
    const contNo = parseSingleParamValue(props.config.contNo, formData.value, [
      ...fieldsData,
      ...hiddenFields
    ]);
    const mode = computed(() => {
      if (props.formMode == "query") {
        return "view";
      }
      return props.config.mode;
    });
    const currentComponent = ref(null);
    onMounted(() => {
      loadComponentByPath(path, ctx.$router, currentComponent);
    });
    function loaded(dom, visibleData) {
      const foundItem = props.localConfig.fieldsData.find(
        (item) => item.id == props.config.id
      );
      const titleHeight = 0;
      if (foundItem) {
        foundItem.fixedH = true;
        foundItem.h = dom.offsetHeight + titleHeight;
        setFormItemHeight(props.config.id, true, dom.offsetHeight + titleHeight);
      }
      emitter.emit("onSubTableDataLoaded", {
        subTableConfig: props.config,
        visibleData
      });
    }
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        (openBlock(), createBlock(resolveDynamicComponent(unref(currentComponent)), {
          id: `comp_${__props.config.id}`,
          mode: unref(mode),
          busNo: unref(busNo),
          contNo: unref(contNo),
          modeNo: __props.config.busSubject,
          genType: __props.config.genType,
          parmList: unref(parsedParams),
          onLoaded: loaded
        }, null, 40, ["id", "mode", "busNo", "contNo", "modeNo", "genType", "parmList"]))
      ]);
    };
  }
});
export {
  _sfc_main as default
};
