import { BtnListType } from "@/common/components/btnList/interface";
import { AgreementType } from "@/common/constants/enumCommon";
import { getAgreementTypeName } from "@/common/constants/enumsName";
import { QhjAgreementConfig } from "@/services/go/ermcp/qhj/interface";
import { UnwrapRef } from "@vue/reactivity";
import { FormState } from "./compoments/add/interface";

export function handleArgreementType(formState?: UnwrapRef<FormState>) {
    // 获取协议类型列表
    function getAgreementTypeList() {
        return [
            { value: AgreementType.register, lable: getAgreementTypeName(AgreementType.register) },
            { value: AgreementType.login, lable: getAgreementTypeName(AgreementType.login) },
            { value: AgreementType.trade, lable: getAgreementTypeName(AgreementType.trade) },
        ]
    }
    // 签署频率
    function getRate() {
        // 协议类型为登录时，签署频率为每次；
        // 协议类型为其它类型时，签署频率为首次；
        return formState?.agreementtype === AgreementType.login ? '每次' : '首次';
    }

    // 获取 签署频率 名
    function getRateEnumName(type: number) {
        //  agreementfrequency	:number;//协议频率 - 1:首次 2:每次 [登录为2， 其它为1]
        let result = '--'
        switch (type) {
            case 1:
                result = '首次'
                break;
            case 2:
                result = '每次'
                break;
        }
        return result;
    }

    return { getAgreementTypeList, getRate, getRateEnumName }
}

// 处理权限按钮
export function handlePermissionBtn(btnList: BtnListType[], item: QhjAgreementConfig) {
    if (item) {
        const { isvalid } = item
        const arr: string[] = []
        if (isvalid === 1) { // 正常
            arr.push('platinum_agreement_resume')
        } else if (isvalid === 2) { // 停用
            arr.push('platinum_agreement_stop')
        }
        return btnList.filter(e => !arr.includes(e.code))
    } else {
        return []
    }

}