"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const index$1 = require("../../forms/subTitle/index.js");
const index = require("../../forms/h2/index.js");
const getInstance = require("../../../utils/getInstance.js");
const common = require("../../../utils/common.js");
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 = getInstance.getCurrentVueInstance();
    Vue.ref("");
    const formData = Vue.inject("formData");
    Vue.inject("rowHeight");
    Vue.inject("gridLayout");
    Vue.inject("gridLayoutFieldsData");
    const setFormItemHeight = Vue.inject("setFormItemHeight");
    const fieldsData = props.localConfig.fieldsData.map((item) => {
      return item.component;
    });
    const hiddenFields = props.localConfig.hiddenFields;
    const accept = Vue.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 = Vue.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 = Vue.ref(null);
    Vue.onMounted(() => {
      common.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 = Vue.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 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
          }, null, 8, ["config"])) : __props.config.titleMode == "subLabel" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$1.SubTitle), {
            key: 1,
            config: __props.config
          }, null, 8, ["config"])) : Vue.createCommentVNode("", true)
        ])) : Vue.createCommentVNode("", true),
        Vue.createElementVNode("div", _hoisted_2, [
          (Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(Vue.unref(currentComponent)), {
            ref_key: "docRef",
            ref: docRef,
            isEdit: __props.formMode != "query",
            isSupplement: __props.config.isSupplement,
            multiple: __props.config.multiple,
            download: __props.config.download,
            accept: Vue.unref(accept),
            paramList: Vue.unref(paramList),
            onLoaded: loaded
          }, null, 40, ["isEdit", "isSupplement", "multiple", "download", "accept", "paramList"]))
        ])
      ], 64);
    };
  }
});
exports.default = _sfc_main;
