/**
 * @Author: lb
 * @CreateDate: 2022.8.8
 * @Modifier: 
 * @ModifiedDate: 
 * 表格里的操作组件
 * 一般用途：展示添加删除按钮
 */
export default {
  name: 'TableOperations',
  props: {
    injectData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      btnTypes: {
        add: 'primary',
        delete: 'danger',
        detail: 'info'
        // add more...
      },
      colors: {
        delete: '#FF5454',
        // add more...
      },
      text: {
        // TODO: i18n
        edit: '编辑',
        detail: '详情',
        delete: '删除',
        viewAttr: '查看属性'
        // add more...
      }
    }
  },
  methods: {
    // 发射事件
    emit(eventType) {
      this.$emit('emit-data', { type: eventType, data: this.injectData.head?.emitFullData ? this.injectData : this.injectData.id })
    }
  },
  render: function (h) {
    let btns = []
    for (const optionStr of this.injectData.head?.options) {
      // btns.push(h('el-button', { props: { type: this.btnTypes[optionStr] } }, optionStr))
      btns.push(h('el-button', { props: { type: 'text' }, style: { color: this.colors[optionStr] || '#409EFF' }, on: { click: this.emit.bind(null, optionStr) } }, this.text[optionStr]))
    }
    return h('span', null, btns)
  }
}