function setBtnName(name,row){
  if(!name){
    return false
  }
  if(typeof name == 'function'){
    return name(row)
  }else if (typeof name == 'string'){
    return name
  }
}

export default {
  methods: {
    operationBtn(opt = {}) {
      var roleItems = this.$route.meta.roleItems
      return (...p) => {
        if (!roleItems || !roleItems.length) {
          return null
        }
        return (
          <div class="operation-btns">
            {Object.keys(opt)
              .filter(key => (opt[key]?.click ? true : false))
              .map(key => {
                return (h, { row, index, column }) => {
                  var role = roleItems?.find(item => item.code === key)
                  if (opt[key]?.prompt) {
                    return role && (opt[key]?.conditions ? opt[key]?.conditions({ row, index, column }) : true) ? (
                      <el-popconfirm
                        title={opt[key]?.prompt}
                        onConfirm={() => {
                          opt[key]?.click({ row, index, column })
                        }}
                      >
                        <el-button size="mini" type={opt[key]?.btnType || 'primary'} slot="reference">
                          {setBtnName(opt[key]?.name,{ row, index, column }) || role.moduleName}
                        </el-button>
                      </el-popconfirm>
                    ) : null
                  } else {
                    return role && (opt[key]?.conditions ? opt[key]?.conditions({ row, index, column }) : true) ? (
                      <el-button
                        size="mini"
                        type={opt[key]?.btnType || 'primary'}
                        onClick={() => {
                          opt[key]?.click({ row, index, column })
                        }}
                      >
                        {setBtnName(opt[key]?.name,{ row, index, column }) || role.moduleName}
                      </el-button>
                    ) : null
                  }
                }
              })
              .map(fun => fun(...p))}
          </div>
        )
      }
    }
  }
}
