import type { ActionOptions } from "@/components/DropDownButtons/type";
import { Delete, Odometer } from "@element-plus/icons-vue";
import { BaseFeesetAction } from "@/type/BaseFeesetAction";
import { VxeGridInstance } from "@/components/VxeTable";
import { unref, Ref } from 'vue';

// 按钮权限
const bindFeeActionOptions: ActionOptions[] = [
    {
        value: BaseFeesetAction.VIEW,
        label: "查看",
        color: "#01aee6",
        icon: Odometer,
        permissions: ['sys:receivableModel:add', 'sys:receivableModel:edit'],
    },
    {
        value: BaseFeesetAction.DELETE,
        label: "删除",
        type: "danger",
        icon: Delete,
        permissions: ['sys:receivableModel:add', 'sys:receivableModel:edit']
    },
]

/**
 * 费用类型键值
 */
const feeFieldsObj = {
    valueField: 'id',
    labelField: 'itemName'
}

/**
 * 费用名称
 * @param tableModelRef 
 * @returns 
 */
// 下拉列表的value与label键
const fieldsObj = {
    valueField: 'key',
    labelField: 'feeSetName'
}

type VxeGridTable = Ref<VxeGridInstance | undefined>

/**
 * 获取VxeGrid表格数据
 * @param tableModelRef 
 * @returns 
 */
const getVxeGridData = async <T extends any>(tableModelRef: VxeGridTable): Promise<T[]> => {
    const tableRef = unref(tableModelRef)
    if (!tableRef) return []
    const data = await tableRef.getData()
    return data || []
}

export {
    bindFeeActionOptions,
    feeFieldsObj,
    fieldsObj,
    getVxeGridData
}