'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var lodashEs = require('lodash-es');
require('../config/index.js');
var components = require('../config/components.js');
var formComponent = require('../config/form-component.js');

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

exports.default = _sfc_main;
//# sourceMappingURL=form-component.vue2.js.map
