import { BtnListType } from '@/common/components/btnList/interface';
import { ErmcpLoginUserEx } from "@/services/go/ermcp/account/interface";
import { reactive, ref, Ref } from "vue";

/**
 * 获取账户状态
 * @param type
 * @returns
 */
export function getAccountStatus(type: number) {
    let result = '--'
    switch (type) {
        case 1:
            result = '正常'
            break;
        case 2:
            result = '待审核'
            break;
        case 3:
            result = '待复审'
            break;
        case 4:
            result = '正常'
            break;
        case 5:
            result = '审核拒绝'
            break;
        case 6:
            result = '停用'
            break;
        case 7:
            result = '注销'
            break;
    }
    return result
}

/**
 * 获取期货账户状态
 * @param type
 * @returns
 */
export function getTaAccountStatus(type: number) {
    let result = '--'
    switch (type) {
        case 1:
            result = '正常'
            break;
        case 2:
            result = '受限'
            break;
        case 3:
            result = '冻结（停用）'
            break;
        case 4:
            result = '禁止建仓（人工受限）'
            break;
        case 5:
            result = '禁止交易（人工冻结）'
            break;
        case 6:
            result = '待激活'
            break;
        case 7:
            result = '已删除（注销）'
            break;
    }
    return result
}

/**
 * 获取角色状态
 * @param type
 * @returns
 */
export function getRoleTypeName(type: number) {
    let result = '--'
    switch (type) {
        case 1:
            result = '正常'
            break;
        case 2:
            result = '停用'
            break;
    }
    return result
}

export function handleModalData<T extends object>() {
    // 弹窗选中的数据
    const selectedData = reactive({}) as T
    // 处理弹窗传递数据
    function openAction(item: T) {
        Object.assign(selectedData, item)
    }
    return { selectedData, openAction }
}

export function _handleTableList(fn: Function, tableList: Ref<ErmcpLoginUserEx[]>, btnList: BtnListType[]) {
    fn().then(() => {
        tableList.value.forEach((el) => {
            // 过滤无效
            const arr = el.userlist.filter((item) => item.loginstatus !== 3);
            arr.forEach((item) => {
                const { loginstatus } = item;
                let result = [...btnList];
                if (loginstatus === 1) {
                    // 正常
                    result = btnList.filter((e) => e.lable !== '解锁');
                } else if (loginstatus === 2) {
                    // 冻结
                    result = btnList.filter((e) => e.lable === '解锁' || e.lable === '详情');
                }
                Object.assign(item, { btnList: result });
            });
            Object.assign(el, { userlist: arr });
        });
    });
}

export function handleTableList(fn: Function, tableList: Ref<ErmcpLoginUserEx[]>, btnList: BtnListType[]) {
    fn().then(() => {
        tableList.value.forEach((el) => {
            // 过滤无效
            const arr = el.userlist.filter((item) => item.loginstatus !== 3);
            arr.forEach((item) => {
                const { loginstatus } = item;
                let result = [...btnList];
                if (loginstatus === 1) {
                    // 正常
                    result = btnList.filter((e) => e.lable !== '解锁');
                } else if (loginstatus === 2) {
                    // 冻结
                    result = btnList.filter((e) => e.lable === '解锁' || e.lable === '详情');
                }
                Object.assign(item, { btnList: result });
            });
            Object.assign(el, { userlist: arr });
        });
    });
}

export function handleBtnClickData() {
    const firstBtnData = ref<any>(null)
    const secondBtnData = ref<any>(null)
    const thirdBtnDat = ref<any>(null)
    function btnClick(...rest: any[]) {
        firstBtnData.value = rest[0];
        secondBtnData.value = rest[1];
        thirdBtnDat.value = rest[0];
    }
    return { firstBtnData, secondBtnData, thirdBtnDat, btnClick }
}