import type { Ref } from "vue"
import type { VxeGridInstance, VxeTableInstance } from "vxe-table"

/**
 * vxe-table中的事件
 * @param VxeGridRef 
 */
function useVxeGridHanleHooks(VxeGridRef: Ref<VxeGridInstance | VxeTableInstance | undefined>) {
    // 判断是否编辑状态
    const isActiveStatus = (row) => {
        const $table = VxeGridRef.value
        if ($table) {
            return $table.isEditByRow(row)
        }
    }
    // 取消编辑状态
    const cancelRowEvent = async (row) => {
        const $table = VxeGridRef.value
        if ($table) {
            await $table.clearEdit()
            // 还原数据
            // await $table.revertData(row)
        }
    }
    // 更新当前单元格状态 
    const updateStatus = async (row) => {
        const $table = VxeGridRef.value
        if ($table) {
            // $table.clearValidate()
            await $table.updateStatus(row)
        }
    }

    return {
        isActiveStatus,
        cancelRowEvent,
        updateStatus,
    }
}

export {
    useVxeGridHanleHooks
}