import Vue from 'vue'
import _ from 'lodash'
import config from '../config'
import Config from '../config'
const { tableFileds } = Config
const filedObj = tableFileds.reduce((prev, item) => {
  const name = item.name.toLocaleLowerCase()
  if ('cmp' in item) {
    prev[name] = item.cmp
  } else {
    prev[name] = item
  }
  return prev
}, {})

export default Vue.extend({
  props: {
    type: String,
    props: Object,
    text: undefined
  },
  render: function(h) {
    const self = this
    let cmp = 'span'
    if (self.type) cmp = filedObj[self.type.toLocaleLowerCase()]
    return h(cmp, {
      props: self.props,
      domProps: {
        innerHTML: _.isNil(self.text) ? config.tableEmptyFill : self.text
      },
      on: {
        input: function(val) {
          console.log(val)
          self.$emit('input', val)
        }
      }
    })
  }
})
