import type { FormRules } from 'element-plus'
export const rules = (clientForm: any): FormRules => {
    return {
        //手续费模板
        feeTemplate: [
            { required: true, message: '请选择手续费模板', trigger: ['blur'] },
        ],
        //风控模板
        riskTemplate: [
            { required: true, message: '请选择风控模板', trigger: ['blur'] },
        ],
        //所属上级
        agentUsername: [
            { required: true, message: '请选择所属上级', trigger: ['blur'] },
        ],
        //手机号
        phone: [
            {
                validator: (rule, value, callback) => {
                    // 验证国家码必填
                    if (!clientForm.mobile_area) {
                        return callback(new Error('请选择国家/地区码'));
                    }
                    // 验证手机号必填
                    if (!value) {
                        return callback(new Error('请输入手机号码'));
                    }
                    // 中国大陆手机号格式验证（仅+86时生效）
                    if (clientForm.mobile_area === '+86' && !/^1[3-9]\d{9}$/.test(value)) {
                        return callback(new Error('请输入正确的中国大陆手机号'));
                    }
                    callback();
                },
                trigger: ['blur', 'change']
            }
        ],
        //邮箱
        email: [
            { required: true, message: '请输入邮箱地址', trigger: ['blur'] },
            { type: 'email', message: '请输入正确的邮箱格式', trigger: ['blur'] }
        ],
        //是否升级为代理
        isUpgrade: [
            { required: true, message: '请选择是否升级为代理', trigger: ['blur'] },
        ],
        //选择状态
        status: [
            { required: true, message: '请选择状态', trigger: ['blur'] },
        ],
        //客户名称
        changeName: [
            { required: true, message: '请输入客户名称', trigger: ['blur'] },
        ],
    }
}
