import { ref, inject, computed, onMounted, createElementBlock, openBlock, Fragment, createCommentVNode, createElementVNode, createBlock, unref, resolveDynamicComponent } from "vue";
import { SubTitle } from "../../forms/subTitle/index.mjs";
import { H2 } from "../../forms/h2/index.mjs";
import { getCurrentVueInstance } from "../../../utils/getInstance.mjs";
import { loadComponentByPath } from "../../../utils/common.mjs";
const _hoisted_1 = {
  key: 0,
  style: { "height": "60px", "position": "relative" }
};
const _hoisted_2 = { class: "document-content" };
const path = "/tech/file/components/DocElement";
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "Document",
  props: {
    config: {
      type: Object,
      required: true
    },
    localConfig: {
      type: Object,
      required: true
    },
    formMode: {
      type: String,
      default: ""
    }
  },
  setup(__props, { expose: __expose }) {
    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 accept = computed(() => {
      const acceptArr = [];
      const acceptType = props.config.acceptType;
      if (acceptType.includes("image")) {
        acceptArr.push("image/*");
      }
      if (acceptType.includes("video")) {
        acceptArr.push("video/*");
      }
      if (acceptType.includes("audio")) {
        acceptArr.push("audio/*");
      }
      if (acceptType.includes("text")) {
        acceptArr.push("text/plain");
      }
      if (acceptType.includes("doc")) {
        acceptArr.push(".doc");
        acceptArr.push(".docx");
      }
      if (acceptType.includes("xls")) {
        acceptArr.push(".xls");
        acceptArr.push(".xlsx");
      }
      if (acceptType.includes("ppt")) {
        acceptArr.push(".ppt");
        acceptArr.push(".pptx");
      }
      if (acceptType.includes("pdf")) {
        acceptArr.push("application/pdf");
      }
      if (acceptType.includes("zip")) {
        acceptArr.push("application/zip");
        acceptArr.push("application/x-rar-compressed");
      }
      let accept2 = "";
      if (acceptArr.length < 13) {
        accept2 = acceptArr.join(",");
      }
      return accept2;
    });
    const paramList = computed(() => {
      return props.config.essentialParams.map((item) => {
        const modeNo = item.scenario;
        const businessObj = item.businessKey;
        const fieldId = businessObj.value;
        const field = [...fieldsData, ...hiddenFields].find(
          (fieldItem) => fieldItem.id == fieldId
        );
        let busNo = "";
        if (field) {
          busNo = formData.value[field.fieldName];
        }
        return {
          modeNo,
          busNo
        };
      });
    });
    const currentComponent = ref(null);
    onMounted(() => {
      loadComponentByPath(path, ctx.$router, currentComponent);
    });
    function loaded(dom) {
      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 = dom.offsetHeight + titleHeight;
        setFormItemHeight(props.config.id, true, dom.offsetHeight + titleHeight);
      }
    }
    const docRef = ref();
    function validate() {
      var _a;
      if (currentComponent.value) {
        return (_a = docRef.value) == null ? void 0 : _a.validateFile();
      } else {
        return Promise.resolve();
      }
    }
    __expose({
      validate
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock(Fragment, null, [
        __props.config.titleMode != "none" ? (openBlock(), createElementBlock("div", _hoisted_1, [
          __props.config.titleMode == "label" ? (openBlock(), createBlock(unref(H2), {
            key: 0,
            config: __props.config
          }, null, 8, ["config"])) : __props.config.titleMode == "subLabel" ? (openBlock(), createBlock(unref(SubTitle), {
            key: 1,
            config: __props.config
          }, null, 8, ["config"])) : createCommentVNode("", true)
        ])) : createCommentVNode("", true),
        createElementVNode("div", _hoisted_2, [
          (openBlock(), createBlock(resolveDynamicComponent(unref(currentComponent)), {
            ref_key: "docRef",
            ref: docRef,
            isEdit: __props.formMode != "query",
            isSupplement: __props.config.isSupplement,
            multiple: __props.config.multiple,
            download: __props.config.download,
            accept: unref(accept),
            paramList: unref(paramList),
            onLoaded: loaded
          }, null, 40, ["isEdit", "isSupplement", "multiple", "download", "accept", "paramList"]))
        ])
      ], 64);
    };
  }
});
export {
  _sfc_main as default
};
