<template>
  <component :is="getComponent(item.type)" v-bind="getBindData(item)" v-model="obverseValue"
    v-on="resolveListeners(item.ons)" :_config="item" />
</template>

<script>

export default {
  name: 'Proxy',
  inject: ['getComponent', 'getBindData', "getFormData", 'parent'],
  props: {
    value: {},
    item: Object
  },
  computed: {
    obverseValue: {
      get() {
        return this.value
      },
      set(value) {
        this.$emit("update:value", value)
      }
    }
  },
  methods: {
    resolveListeners(callbacks) {
      if (!callbacks) return;

      const result = {};

      for (const key in callbacks) {
        result[key] = (...args) => callbacks[key](...args, this.getFormData(), this.parent)
      }

      return result
    },
  }
}
</script>
