import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
/* empty css                                                                 */
import { getCurrentInstance, ref, watch, computed, createElementBlock, openBlock, createBlock, resolveDynamicComponent, mergeProps } from "vue";
import { cloneDeep } from "../../utils/common.mjs";
import { useOptions } from "../../../utils/optionLoader.mjs";
/* empty css                         */
import _export_sfc from "../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElInput } from "../../../../../node_modules/element-plus/es/components/input/index.mjs";
const _hoisted_1 = { class: "default-value-editor" };
const _sfc_main = {
  __name: "DefaultValueEditor",
  props: {
    config: {
      type: Object,
      required: true
    },
    modelValue: {
      type: [String, Number, Boolean, Array, Object],
      default: ""
    }
  },
  emits: ["update:modelValue", "change"],
  setup(__props, { emit: __emit }) {
    const currentInstance = getCurrentInstance();
    const ctx = currentInstance.proxy;
    const props = __props;
    const emit = __emit;
    const instance = getCurrentInstance();
    const localValue = ref(props.modelValue);
    watch(
      () => props.modelValue,
      (newValue) => {
        localValue.value = newValue;
      }
    );
    watch(
      () => localValue.value,
      (newValue) => {
        emit("update:modelValue", newValue);
        emit("change", newValue);
      }
    );
    const componentType = computed(() => {
      var _a, _b;
      if (!props.config.fieldType) return null;
      const key = props.config.fieldType.charAt(0).toUpperCase() + props.config.fieldType.slice(1);
      const component = (_b = (_a = instance == null ? void 0 : instance.appContext) == null ? void 0 : _a.components) == null ? void 0 : _b[`Fec${key}`];
      if (!component) {
        console.warn(`未找到对应的组件: Fec${key}，将使用 el-input 代替`);
        return null;
      }
      return component;
    });
    const { options: optionData } = useOptions(ctx, props.config);
    const componentProps = computed(() => {
      const fieldProps = cloneDeep(props.config);
      fieldProps.disabled = false;
      fieldProps.readonly = false;
      fieldProps.suffixButton = "none";
      if (fieldProps.optionConfig) {
        fieldProps.optionConfig.options = optionData.value;
      }
      delete fieldProps.id;
      return fieldProps;
    });
    return (_ctx, _cache) => {
      const _component_el_input = ElInput;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        __props.config.fieldType && __props.config.fieldType !== "userSelect" && __props.config.fieldType !== "roleSelect" && __props.config.fieldType !== "orgSelect" ? (openBlock(), createBlock(resolveDynamicComponent(componentType.value), mergeProps({
          key: 0,
          modelValue: localValue.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => localValue.value = $event)
        }, componentProps.value, {
          config: __props.config,
          formMode: "edit",
          placeholder: "默认值"
        }), null, 16, ["modelValue", "config"])) : (openBlock(), createBlock(_component_el_input, {
          key: 1,
          modelValue: localValue.value,
          "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => localValue.value = $event),
          placeholder: "请默认值"
        }, null, 8, ["modelValue"]))
      ]);
    };
  }
};
const DefaultValueEditor = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-7742453a"]]);
export {
  DefaultValueEditor as default
};
