"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                                                                     */
require("../../../../../../node_modules/element-plus/theme-chalk/el-tooltip.css.js");
;/* empty css                                                                   */
const Vue = require("vue");
const debounce = require("../form/debounce.js");
const index$3 = require("../subTitle/index.js");
const index$2 = require("../h2/index.js");
const index$4 = require("../subForm/index.js");
const index$5 = require("../subTable/index.js");
const index$6 = require("../../bus/approvalHistory/index.js");
const index$7 = require("../../bus/document/index.js");
const index$8 = require("../../bus/contract/index.js");
const index$1 = require("../index.js");
const index = require("../../bus/index.js");
;/* empty css               */
const _pluginVue_exportHelper = require("../../../../../../_virtual/_plugin-vue_export-helper.js");
const index$9 = require("../../../../../../node_modules/element-plus/es/components/form/index.js");
const index$a = require("../../../../../../node_modules/element-plus/es/components/link/index.js");
const index$b = require("../../../../../../node_modules/element-plus/es/components/tooltip/index.js");
const _hoisted_1 = {
  key: 0,
  class: "iconfont icon-iconZheng credit-icon"
};
const _hoisted_2 = {
  key: 1,
  class: "iconfont icon-iconJian regulation-icon"
};
const _hoisted_3 = { key: 3 };
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "FormItem",
  props: {
    config: {
      type: Object,
      required: true
    },
    localConfig: {
      type: Object,
      required: true
    },
    modelValue: {
      type: [String, Number, Boolean, Array, Object],
      default: ""
    },
    error: {
      type: String,
      default: ""
    },
    formRef: {
      type: Object,
      default: null
    },
    formMode: {
      type: String,
      default: ""
    }
  },
  emits: ["update:modelValue", "change", "labelLink"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    function handleChange(config, val) {
      emit("change", config, val);
    }
    const componentType = Vue.computed(() => {
      const key = props.config.fieldType.charAt(0).toUpperCase() + props.config.fieldType.slice(1);
      return { ...index$1, ...index }[key];
    });
    const componentProps = Vue.computed(() => {
      const fieldProps = { ...props.config };
      if (fieldProps.fieldType !== "subTitle" && fieldProps.fieldType !== "h2") {
        fieldProps.placeholder = fieldProps.placeholder || "";
        fieldProps.disabled = fieldProps.disabled || false;
        fieldProps.readonly = fieldProps.readOnly || false;
      }
      if (fieldProps.fieldType === "subTitle") {
        fieldProps.content = fieldProps.label;
      }
      if (fieldProps.fieldType === "h2") {
        fieldProps.text = fieldProps.label;
      }
      delete fieldProps.id;
      return fieldProps;
    });
    const debouncedValidate = debounce.debounce((fieldName) => {
      if (!props.formRef || !fieldName) return;
      props.formRef.validateField(fieldName, (errorMessage) => {
        if (!errorMessage) {
          console.log(`字段 ${fieldName} 校验通过，错误已清除`);
        }
      });
    }, 300);
    const innerComponentRef = Vue.ref(null);
    const compValue = Vue.computed({
      get: () => props.modelValue,
      set: (val) => {
        emit("update:modelValue", val);
        if (props.error && props.config.fieldName && props.formRef) {
          debouncedValidate(props.config.fieldName);
        }
      }
    });
    function handleLabelLink() {
      emit("labelLink", props.config);
    }
    const getInnerComponentRef = () => {
      return innerComponentRef.value;
    };
    __expose({
      config: props.config,
      getInnerComponentRef
    });
    return (_ctx, _cache) => {
      const _component_el_link = index$a.ElLink;
      const _component_el_tooltip = index$b.ElTooltip;
      const _component_el_form_item = index$9.ElFormItem;
      return __props.config.fieldType == "h2" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$2.H2), {
        key: 0,
        config: __props.config
      }, null, 8, ["config"])) : __props.config.fieldType == "subTitle" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$3.SubTitle), {
        key: 1,
        config: __props.config
      }, null, 8, ["config"])) : __props.config.fieldType == "subForm" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$4.SubForm), {
        key: 2,
        ref_key: "innerComponentRef",
        ref: innerComponentRef,
        config: __props.config,
        localConfig: __props.localConfig,
        formMode: __props.formMode
      }, null, 8, ["config", "localConfig", "formMode"])) : __props.config.fieldType == "subTable" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$5.SubTable), {
        key: 3,
        ref_key: "innerComponentRef",
        ref: innerComponentRef,
        config: __props.config,
        localConfig: __props.localConfig,
        formMode: __props.formMode
      }, null, 8, ["config", "localConfig", "formMode"])) : __props.config.fieldType == "approvalHistory" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$6.ApprovalHistory), {
        key: 4,
        ref_key: "innerComponentRef",
        ref: innerComponentRef,
        config: __props.config,
        localConfig: __props.localConfig,
        formMode: __props.formMode
      }, null, 8, ["config", "localConfig", "formMode"])) : __props.config.fieldType == "document" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$7.Document), {
        key: 5,
        ref_key: "innerComponentRef",
        ref: innerComponentRef,
        config: __props.config,
        localConfig: __props.localConfig,
        formMode: __props.formMode
      }, null, 8, ["config", "localConfig", "formMode"])) : __props.config.fieldType == "contract" ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$8.Contract), {
        key: 6,
        ref_key: "innerComponentRef",
        ref: innerComponentRef,
        config: __props.config,
        localConfig: __props.localConfig,
        formMode: __props.formMode
      }, null, 8, ["config", "localConfig", "formMode"])) : __props.config.fieldType == "blank" || __props.config.fieldType == "divider" ? (Vue.openBlock(), Vue.createElementBlock("div", {
        key: 7,
        class: Vue.normalizeClass(__props.config.fieldType)
      }, null, 2)) : (Vue.openBlock(), Vue.createBlock(_component_el_form_item, {
        key: 8,
        prop: __props.config.fieldName,
        required: __props.config.required,
        error: __props.error,
        "label-width": 160,
        id: `comp_${__props.config.id}`
      }, Vue.createSlots({
        default: Vue.withCtx(() => [
          __props.config.labelMode != "label" ? (Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(componentType.value), Vue.mergeProps({
            key: 0,
            ref_key: "innerComponentRef",
            ref: innerComponentRef,
            modelValue: compValue.value,
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => compValue.value = $event)
          }, componentProps.value, {
            config: __props.config,
            formMode: __props.formMode,
            onChange: _cache[1] || (_cache[1] = (value) => {
              handleChange(__props.config, value);
            })
          }), null, 16, ["modelValue", "config", "formMode"])) : Vue.createCommentVNode("", true)
        ]),
        _: 2
      }, [
        __props.config.labelMode != "input" ? {
          name: "label",
          fn: Vue.withCtx(() => {
            var _a;
            return [
              __props.config.credit ? (Vue.openBlock(), Vue.createElementBlock("i", _hoisted_1)) : Vue.createCommentVNode("", true),
              __props.config.regulation ? (Vue.openBlock(), Vue.createElementBlock("i", _hoisted_2)) : Vue.createCommentVNode("", true),
              __props.config.labelLink ? (Vue.openBlock(), Vue.createBlock(_component_el_link, {
                key: 2,
                type: "primary",
                style: { "pointer-events": "all" },
                onClick: Vue.withModifiers(handleLabelLink, ["prevent"])
              }, {
                default: Vue.withCtx(() => [
                  Vue.createTextVNode(Vue.toDisplayString(__props.config.label), 1)
                ]),
                _: 1
              })) : (Vue.openBlock(), Vue.createElementBlock("span", _hoisted_3, Vue.toDisplayString(__props.config.label), 1)),
              ((_a = __props.config.tooltip) == null ? void 0 : _a.trim()) ? (Vue.openBlock(), Vue.createBlock(_component_el_tooltip, {
                key: 4,
                content: __props.config.tooltip,
                placement: "top"
              }, {
                default: Vue.withCtx(() => _cache[2] || (_cache[2] = [
                  Vue.createElementVNode("i", { class: "iconfont icon-tooltip info-icon" }, null, -1)
                ])),
                _: 1
              }, 8, ["content"])) : Vue.createCommentVNode("", true)
            ];
          }),
          key: "0"
        } : void 0
      ]), 1032, ["prop", "required", "error", "id"]));
    };
  }
});
const _FormItem = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-ebc3ff2b"]]);
exports.default = _FormItem;
