<script>
import ItemMixin from './mixin/ItemMixin'
export default {
  name: 'CustomRender',
  mixins: [ItemMixin],
  props: {
    expand: {
      type: Boolean,
      default: false
    },
    header: {
      type: Boolean,
      default: false
    },
    customRender: Function, // eslint-disable-line
    row: Object, // eslint-disable-line
    column: Object, // eslint-disable-line
    content: [String, Number, Object, Boolean], // eslint-disable-line
    rIndex: Number, // eslint-disable-line
    cIndex: Number, // eslint-disable-line
    uniqueKey: String, // eslint-disable-line
    horizontal: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      event: 'CustomRow'
    }
  },
  render: function(h) {
    let params
    if (this.expand) {
      params = {
        row: this.row,
        $index: this.rIndex
      }
    } else if (this.header) {
      params = {
        column: this.column,
        $index: this.cIndex
      }
    } else {
      params = {
        row: this.row,
        column: this.column,
        content: this.content,
        $rowIndex: this.rIndex,
        $columnIndex: this.cIndex
      }
    }
    if (!this.customRender) return

    const result = this.customRender(h, params)
    if (!result) {
      return null
    }
    if (Array.isArray(result)) {
      return result.length === 1 ? result[0] : h('div', result)
    }
    return result
  }
}
</script>
