import { defineComponent, reactive, ref, nextTick, createBlock, unref, openBlock, resolveDynamicComponent, mergeProps } from 'vue';
import { omit, has } from 'lodash-es';
import '../config/index.mjs';
import { checkedType } from '../config/components.mjs';
import { formComponentEmits, formComponentProps } from '../config/form-component.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "form-component",
  props: formComponentProps,
  emits: formComponentEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const formData = reactive(props.formData);
    const componentRef = ref();
    const getBindValue = (item) => {
      const obj = { ...item };
      return omit(obj, ["label", "onChange", "change", "blur", "onBlur", "class"]);
    };
    const handleChange = (...arg) => {
      const item = props.item;
      if (has(item, "change")) {
        item.change(...arg);
      }
      if (has(item, "onChange")) {
        item.onChange(...arg);
      }
      emits("changeField", item);
    };
    const handleBlur = (...arg) => {
      const item = props.item;
      if (has(item, "blur")) {
        item.blur(...arg);
      }
      if (has(item, "onBlur")) {
        item.onBlur(...arg);
      }
      emits("blurField", item);
    };
    const focus = async () => {
      await nextTick();
      componentRef.value?.focus();
    };
    const getItem = () => {
      return props.item;
    };
    __expose({
      focus,
      getItem
    });
    return (_ctx, _cache) => {
      return unref(checkedType).includes(_ctx.item.type) ? (openBlock(), createBlock(resolveDynamicComponent(`ll-${_ctx.item.type}`), mergeProps({
        key: 0,
        ref_key: "componentRef",
        ref: componentRef,
        checked: formData[_ctx.item.key],
        "onUpdate:checked": _cache[0] || (_cache[0] = ($event) => formData[_ctx.item.key] = $event)
      }, getBindValue(_ctx.item), {
        onChange: handleChange,
        onBlur: handleBlur
      }), null, 16, ["checked"])) : (openBlock(), createBlock(resolveDynamicComponent(`ll-${_ctx.item.type}`), mergeProps({
        key: 1,
        ref_key: "componentRef",
        ref: componentRef,
        value: formData[_ctx.item.key],
        "onUpdate:value": _cache[1] || (_cache[1] = ($event) => formData[_ctx.item.key] = $event)
      }, getBindValue(_ctx.item), {
        onChange: handleChange,
        onBlur: handleBlur
      }), null, 16, ["value"]));
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=form-component.vue2.mjs.map
