"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const formRule = require("../../../utils/formRule.js");
const _sfc_main = {
  __name: "FormItem",
  props: {
    fieldType: {
      type: String,
      default: "text"
    },
    disabled: {
      type: Boolean,
      default: false
    },
    readonly: {
      type: Boolean,
      default: false
    },
    placeholder: String
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const formItem = Vue.computed(() => {
      switch (props.fieldType) {
        case "text":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../field/index.js")));
        case "picker":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldPicker/index.js")));
        case "cascader":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldCascaderPicker/index.js")));
        case "calendar":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldCalendarPicker/index.js")));
        case "date":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldDatePicker/index.js")));
        case "dateTime":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldDateTimePicker/index.js")));
        case "time":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldTimePicker/index.js")));
        case "radio":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldRadio/index.js")));
        case "checkbox":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldCheckbox/index.js")));
        case "upload":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldUploader/index.js")));
        case "area":
          return Vue.defineAsyncComponent(() => Promise.resolve().then(() => require("../fieldArea/index.js")));
      }
    });
    const formData = Vue.inject("formData");
    const formDisabled = Vue.inject("formDisabled");
    const formReadonly = Vue.inject("formReadonly");
    const dicListMap = Vue.inject("dicListMap");
    const formItemDisabled = Vue.computed(() => {
      if (formDisabled == null ? void 0 : formDisabled.value) {
        return formDisabled.value;
      }
      return props.disabled;
    });
    const formItemReadonly = Vue.computed(() => {
      if (formReadonly == null ? void 0 : formReadonly.value) {
        return formReadonly.value;
      }
      return props.readonly;
    });
    const attrs = Vue.useAttrs();
    const emit = __emit;
    const compValue = Vue.computed({
      get: () => {
        var _a;
        if (formData) {
          return (_a = formData.value) == null ? void 0 : _a[attrs.name];
        }
        return props.modelValue;
      },
      set: (val) => {
        if (formData) {
          formData.value[attrs.name] = val;
        } else {
          emit("update:modelValue", val);
        }
      }
    });
    const rules = Vue.computed(() => {
      return formRule.parseRule(props.fieldType, attrs);
    });
    return (_ctx, _cache) => {
      var _a;
      return Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(Vue.unref(formItem)), Vue.mergeProps(_ctx.$attrs, {
        modelValue: Vue.unref(compValue),
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => Vue.isRef(compValue) ? compValue.value = $event : null),
        fieldType: __props.fieldType,
        rules: Vue.unref(rules),
        required: Vue.unref(formItemReadonly) ? false : "auto",
        disabled: Vue.unref(formItemDisabled),
        readonly: Vue.unref(formItemReadonly),
        placeholder: Vue.unref(formItemReadonly) ? "" : __props.placeholder,
        dicList: (_a = Vue.unref(dicListMap)) == null ? void 0 : _a[Vue.unref(attrs).dicKey]
      }), null, 16, ["modelValue", "fieldType", "rules", "required", "disabled", "readonly", "placeholder", "dicList"]);
    };
  }
};
exports.default = _sfc_main;
