// 按钮代理操作
function proxy(event) {
    let parentName = this.$parent.$options.name

    // 没有代理内容
    if (parentName != 'ElTableRow' || !this.proxyList || !this.proxyList.length) {
        return this.$emit('click', event)
    }

    let text = this.$slots.default && this.$slots.default[0]?.text

    // 当前按钮是否是代理按钮
    let isExists = this.proxyList.find(item => {
        if (typeof item == 'object') {
            return item.name == text
        }
        if (typeof item == 'string') {
            return item == text
        }
    })
    if (!isExists) {
        return this.$emit('click', event)
    }

    // 当前按钮是否提供了代理
    let isExistsProxy = proxyList.find(item => item.name == text)
    // 将自定义代理列表数据进行转换
    if (typeof isExists == 'string') {
        isExists = {
            name: isExists
        }
    }
    // 合并配置项
    let options = Object.assign({}, isExistsProxy, { parentName }, isExists)


    if (!options.action) {
        console.log(new Error('请实现该按钮代理方法'))
        return this.$emit('click', event)
    }
    // 启用默认代理
    options.action.call(this, options, event).then(() => {
        return this.$emit('click', event)
    })

}

var proxyList = [
    {
        name: '删除',
        message: '确认要删除吗, 是否继续?',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        action(options, event) {
            let { message, type, confirmButtonText, cancelButtonText, parentName } = options
            return new Promise(resolve => {
                this.$confirm && this.$confirm(message, '提示', {
                    confirmButtonText: confirmButtonText,
                    cancelButtonText: cancelButtonText,
                    type: type
                }).then(() => {
                    resolve()
                }).catch(() => {});
            })
        }
    }
]



export default proxy