"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _chinaIdCard = _interopRequireDefault(require("china-id-card"));

var _passwordValidator = _interopRequireDefault(require("password-validator"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var baseSchema = function baseSchema(item) {
  return item.is().min(8).is().max(20).has().not().spaces();
};

var passwordSchemas = [baseSchema(new _passwordValidator.default()).has().digits().has().symbols(), baseSchema(new _passwordValidator.default()).has().symbols().has().letters(), baseSchema(new _passwordValidator.default()).has().digits().has().letters(), baseSchema(new _passwordValidator.default()).has().digits().has().letters().has().symbols()];
var _default = {
  idCard: function idCard(rule, value) {
    return value ? (value === null || value === void 0 ? void 0 : value.length) === 18 && (0, _chinaIdCard.default)(value.toUpperCase()).isVerified ? Promise.resolve() : Promise.reject(new Error(rule.message || '请输入正确的身份证号码')) : rule.required ? Promise.reject(new Error('请输入身份证号码')) : Promise.resolve();
  },
  phone: function phone(rule, value) {
    return value ? /^1[3-9][0-9]{9}$/.test(value) ? Promise.resolve() : Promise.reject(new Error(rule.message || '请输入正确的手机号')) : rule.required ? Promise.reject(new Error('请输入手机号码')) : Promise.resolve();
  },
  password: function password(rule, value) {
    return value ? passwordSchemas.some(function (schema) {
      return schema.validate(value);
    }) ? Promise.resolve() : Promise.reject(new Error(rule.message || '请设置8-20位密码，至少包含数字、字母、特殊符号中2种，不能有空格')) : rule.required ? Promise.reject(new Error('请输入密码')) : Promise.resolve();
  }
};
exports.default = _default;