import i18n from '@/lang'
const t = i18n.global.t
export const validateName = (rule, value, callback) => {
	var str = ""
	if (!value) {
		str = t('Login.pleaseInputName')
	} else if (value.length < 2 || value.length > 20) {
		str = t('Login.nameLengthError', { min: 2, max: 20 })
	}
	callback(str ? new Error(str) : undefined)
}
export const validateEmail = (rule, value, callback) => {
	const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$/
	var str = ''
	if (!value) {
		str = t('Login.pleaseInputEmail')
	} else if (!emailRegex.test(value)) {
		str = t('Login.emailFormatError')
	}
	callback(str ? new Error(str) : undefined)
}
// 检查长度
export const validateLength = (v, min = 6, max = 20) => (v.length < 6 || v.length > 20);
//检查特殊字符
export const validateSpecial = (v) => (!/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(v));
//检查字母和数字
export const validateCase = (v) => (!/[A-z]/.test(v) || !/\d/.test(v));
// 检查密码
export const validatePass = (rule, value, callback) => {
	var str = ''
	if (validateLength(value)) {
		str = t('Login.passwordLengthError', { min: 6, max: 20 })
		// } else if (validateSpecial(value)) {
		// 	str = t('Login.passwordSpecial')
	} else if (validateCase(value)) {
		str = t('Login.passwordCase')
	}
	callback(str ? new Error(str) : undefined)
}
// 检查密码长度
export const validatePassLength = (rule, value, callback) => {
	var str = ''
	if (validateLength(value)) {
		str = t('Login.passwordLengthError', { min: 6, max: 20 })
	}
	callback(str ? new Error(str) : undefined)
}
export const validatePrivacy = (rule, value, callback) => {
	if (!value) {
		callback(new Error(t('Login.pleaseTermsPolicy')))
	} else {
		callback()
	}
}