"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../../../node_modules/element-plus/es/index.js");
;/* empty css                                                                */
;/* empty css                                                                     */
const Vue = require("vue");
const index$2 = require("../subTitle/index.js");
const index = require("../h2/index.js");
const parseRouteParams = require("../../../utils/parseRouteParams.js");
const parseFilterConfig = require("../../../utils/parseFilterConfig.js");
const index$1 = require("../../../../../../node_modules/element-plus/es/components/button/index.js");
const _hoisted_1 = {
  key: 0,
  style: { "height": "60px", "position": "relative" }
};
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "SubTable",
  props: {
    config: {
      type: Object,
      required: true
    },
    localConfig: {
      type: Object,
      required: true
    },
    formMode: {
      type: String,
      default: ""
    }
  },
  setup(__props, { expose: __expose }) {
    const props = __props;
    const getFormData = Vue.inject("getFormData");
    const formData = Vue.ref(getFormData());
    Vue.inject("rowHeight");
    Vue.inject("gridLayout");
    const setFormItemHeight = Vue.inject("setFormItemHeight");
    const handleEvent = Vue.inject("handleEvent");
    const heightMode = Vue.computed(() => {
      return props.config.subTableHeightType || "auto";
    });
    const btnRollbackEvent = Vue.computed(() => {
      const btnRollback = props.config.btnRollback || [];
      const data = {};
      for (const item of btnRollback) {
        const handleFunc = () => {
          handleEvent.value(
            formData.value,
            {},
            { eventFlow: item.callbackEventConfig }
          );
        };
        data[item.id] = handleFunc;
      }
      return data;
    });
    const subTableData = Vue.computed(() => {
      if (props.config.dataSourceFrom == "main") {
        return formData.value[props.config.fieldName];
      }
      return [];
    });
    const fieldList = Vue.computed(() => {
      return [
        ...props.localConfig.fieldsData.map((item) => item.component),
        ...props.localConfig.hiddenFields
      ];
    });
    const initHiddenData = Vue.computed(() => {
      if (props.config.dataSourceFrom == "self") {
        const params = parseRouteParams.parseRouteParams(
          props.config.subTableParams,
          formData.value,
          fieldList.value
        );
        return params;
      }
      return {};
    });
    const subTableOption = Vue.ref({});
    const subTableFieldsData = Vue.computed(() => {
      var _a, _b;
      return [
        ...((_a = subTableOption.value) == null ? void 0 : _a.fieldsData) || [],
        ...((_b = subTableOption.value) == null ? void 0 : _b.hiddenFields) || []
      ];
    });
    const leftButtons = Vue.computed(() => {
      var _a, _b;
      return (((_b = (_a = subTableOption.value) == null ? void 0 : _a.customBtns) == null ? void 0 : _b.left) || []).filter((item) => {
        if (!item.showCondition) return true;
        return parseFilterConfig.checkFilterMatch(
          item.showCondition,
          initHiddenData.value,
          subTableFieldsData.value
        );
      });
    });
    const rightButtons = Vue.computed(() => {
      var _a, _b;
      return (((_b = (_a = subTableOption.value) == null ? void 0 : _a.customBtns) == null ? void 0 : _b.right) || []).filter((item) => {
        if (!item.showCondition) return true;
        return parseFilterConfig.checkFilterMatch(
          item.showCondition,
          initHiddenData.value,
          subTableFieldsData.value
        );
      });
    });
    function subTableLoaded(subOption, tableHeight) {
      subTableOption.value = subOption;
      const foundItem = props.localConfig.fieldsData.find(
        (item) => item.id == props.config.id
      );
      const titleHeight = props.config.titleMode != "none" ? 60 : 0;
      if (foundItem) {
        foundItem.fixedH = true;
        foundItem.h = tableHeight + titleHeight;
        setFormItemHeight(props.config.id, true, foundItem.h);
      }
    }
    const tableRef = Vue.ref();
    const handleClick = (btn, event) => {
      var _a;
      (_a = tableRef.value) == null ? void 0 : _a.handleCustomBtnClick({
        btn,
        event,
        type: "custom"
      });
    };
    __expose({
      subTableRef: tableRef
    });
    return (_ctx, _cache) => {
      const _component_el_button = index$1.ElButton;
      const _component_fec_table = Vue.resolveComponent("fec-table");
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
        __props.config.titleMode != "none" ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
          __props.config.titleMode == "label" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index.H2), {
            key: 0,
            config: __props.config
          }, Vue.createSlots({
            default: Vue.withCtx(() => [
              __props.formMode != "query" ? (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, { key: 0 }, Vue.renderList(Vue.unref(rightButtons), (btn) => {
                return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
                  btn.btnType == "custom" ? (Vue.openBlock(), Vue.createBlock(_component_el_button, {
                    key: btn.id,
                    link: "",
                    type: "primary",
                    onClick: ($event) => handleClick(btn, $event)
                  }, {
                    default: Vue.withCtx(() => [
                      Vue.createTextVNode(Vue.toDisplayString(btn.label), 1)
                    ]),
                    _: 2
                  }, 1032, ["onClick"])) : Vue.createCommentVNode("", true)
                ], 64);
              }), 256)) : Vue.createCommentVNode("", true)
            ]),
            _: 2
          }, [
            Vue.unref(leftButtons) ? {
              name: "left",
              fn: Vue.withCtx(() => [
                __props.formMode != "query" ? (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, { key: 0 }, Vue.renderList(Vue.unref(leftButtons), (btn) => {
                  return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
                    btn.btnType == "custom" ? (Vue.openBlock(), Vue.createBlock(_component_el_button, {
                      key: btn.id,
                      link: "",
                      type: "primary",
                      onClick: ($event) => handleClick(btn, $event)
                    }, {
                      default: Vue.withCtx(() => [
                        Vue.createTextVNode(Vue.toDisplayString(btn.label), 1)
                      ]),
                      _: 2
                    }, 1032, ["onClick"])) : Vue.createCommentVNode("", true)
                  ], 64);
                }), 256)) : Vue.createCommentVNode("", true)
              ]),
              key: "0"
            } : void 0
          ]), 1032, ["config"])) : __props.config.titleMode == "subLabel" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$2.SubTitle), {
            key: 1,
            config: __props.config
          }, null, 8, ["config"])) : Vue.createCommentVNode("", true)
        ])) : Vue.createCommentVNode("", true),
        Vue.createVNode(_component_fec_table, {
          ref_key: "tableRef",
          ref: tableRef,
          templateKey: __props.config.subTableKey,
          isSubTable: "",
          onHeightLoaded: subTableLoaded,
          mode: __props.config.subTableMode,
          titleMode: __props.config.titleMode,
          hasPagination: __props.config.isSubTablePagination,
          heightMode: Vue.unref(heightMode),
          height: __props.config.subTableHeight,
          maxHeight: __props.config.subTableMaxHeight,
          tableData: Vue.unref(subTableData),
          initHiddenData: Vue.unref(initHiddenData),
          canLoadBySearchData: __props.config.reloadOnParamsChange,
          readonly: __props.config.isSubTableReadOnly || __props.formMode == "query",
          btnRollbackEvent: Vue.unref(btnRollbackEvent),
          subTableConfig: __props.config
        }, null, 8, ["templateKey", "mode", "titleMode", "hasPagination", "heightMode", "height", "maxHeight", "tableData", "initHiddenData", "canLoadBySearchData", "readonly", "btnRollbackEvent", "subTableConfig"])
      ], 64);
    };
  }
});
exports.default = _sfc_main;
