import { getAccountTypeList, getCanUseMoney } from "@/services/bus/account";
import { UnwrapRef } from "vue";

// 交易账号
export function useTaAccount<T extends { accountid: undefined | number }>(formState: UnwrapRef<T>) {
    // 资金账号
    const accountList = getAccountTypeList([2]);
    if (accountList.length) {
        formState.accountid = accountList[0].accountid;
    }
    // 资金账号
    function getSelectedAccount() {
        return accountList.find((e) => e.accountid === formState.accountid);
    }
    // 可用资金
    function canUseMoney() {
        return getCanUseMoney(getSelectedAccount()!)
    }
    // 处理内部资金账号
    function handleSelectedAccount() {
        const item = getSelectedAccount()!;
        const list = getAccountTypeList([2]);
        return item.taaccounttype === 2 ? item : list[0];
    }
    return { handleSelectedAccount, canUseMoney, getSelectedAccount, accountList };
}