import { ref, watch, unref } from 'vue';
import { getBillRateversionListApi } from "@/api/billrate/billrate"
import { BaseTableProps } from "@/components/Table/src/types"
import { useReturnData } from "@/utils/useReturnData"
// TODO 处理：根据版本id获取汇率列表
/**
 * 
 * @param tableData register注册表格的内容
 * @returns 汇率版本列表
 */
export function useRateVersionList(tableData: BaseTableProps, rateversionId) {
    // ref Dom信息
    const popoverVersionRef = ref()
    const buttonRoteVersionRef = ref()
    const { resData } = useReturnData()

    // 获取汇率版本列表
    const getRateVersionList = async (rateVersionId) => {
        // 汇率版本
        const res = await getBillRateversionListApi({ rateVersionId })
        const data = resData(res)
        tableData.dataSource = data
    }

    // 点击显示汇率版本列表
    const onClickRateList = () => {
        unref(popoverVersionRef).popperRef?.delayHide?.()
    }

    // 根号版本id查询对应汇率列表
    watch(rateversionId, () => {
        tableData.dataSource = []
        const id = unref(rateversionId)
        if (id > 0) {
            getRateVersionList(id)
        }
    })

    return {
        onClickRateList,
        popoverVersionRef,
        buttonRoteVersionRef
    }
}