"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.signinpasswordField = exports.signinemailField = exports.signinApiHeaders = exports.returnValidatorForName = exports.returnValidatorFor = exports.passwordvalid = exports.passwordField = exports.namevalid = exports.emailValid = exports.emailField = void 0;

require("core-js/modules/es.regexp.constructor.js");

require("core-js/modules/es.regexp.exec.js");

require("core-js/modules/es.regexp.to-string.js");

require("core-js/modules/es.string.match.js");

require("core-js/modules/es.promise.js");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const passwordvalid = new RegExp("^(?=.*[A-Za-z])(?=.*[@$!%*#?&])[A-Za-z0-9@$!%*#?&]{6,}$");
exports.passwordvalid = passwordvalid;
const namevalid = new RegExp("^[a-zA-Z]+$");
exports.namevalid = namevalid;
const emailValid = new RegExp(/^([\w]+[_\.\-]?[\w]+[@]{1}[a-z]+[\-]?[a-z]+[\.]{1}[a-z]{2,}?)$/gm);
exports.emailValid = emailValid;
const signinApiHeaders = {
  Accept: "*/*",
  "Content-Type": "application/json",
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Headers": "content-type",
  "Access-Control-Allow-Methods": "POST"
};
exports.signinApiHeaders = signinApiHeaders;
const emailField = "email";
exports.emailField = emailField;
const passwordField = "password";
exports.passwordField = passwordField;
const signinemailField = "signinemail";
exports.signinemailField = signinemailField;
const signinpasswordField = "signinpassword";
exports.signinpasswordField = signinpasswordField;
const fields = {
  [emailField]: {
    regex: emailValid,
    errorMessage: "Please enter a valid Email"
  },
  [passwordField]: {
    regex: passwordvalid,
    errorMessage: "Password should be atleast 6 characters long and should contain a special symbol!"
  },
  [signinemailField]: {
    regex: emailValid,
    errorMessage: "Invalid Email"
  },
  [signinpasswordField]: {
    regex: passwordvalid,
    errorMessage: "Invalid Password!"
  }
};

const returnValidatorFor = (fieldName, setValidationStatus, validationStatus) => _ref => {
  let {
    getFieldValue
  } = _ref;
  return {
    validator(_, value) {
      var _getFieldValue;

      if (value && getFieldValue(fieldName).match(fields[fieldName].regex)) {
        setValidationStatus(_objectSpread(_objectSpread({}, validationStatus), {}, {
          [fieldName]: "success"
        }));
        return Promise.resolve();
      } else if (getFieldValue(fieldName) === undefined || ((_getFieldValue = getFieldValue(fieldName)) === null || _getFieldValue === void 0 ? void 0 : _getFieldValue.length) === 0) {
        setValidationStatus(_objectSpread(_objectSpread({}, validationStatus), {}, {
          [fieldName]: ""
        }));
        return Promise.resolve();
      }

      setValidationStatus(_objectSpread(_objectSpread({}, validationStatus), {}, {
        [fieldName]: "error"
      }));
      return Promise.reject(new Error(fields[fieldName].errorMessage));
    }

  };
};

exports.returnValidatorFor = returnValidatorFor;

const returnValidatorForName = (fieldName, setValidationStatus, validationStatus) => _ref2 => {
  let {
    getFieldValue
  } = _ref2;
  return {
    validator(_, value) {
      var _getFieldValue2, _getFieldValue3;

      if (getFieldValue(fieldName) === undefined || ((_getFieldValue2 = getFieldValue(fieldName)) === null || _getFieldValue2 === void 0 ? void 0 : _getFieldValue2.length) === 0) {
        setValidationStatus(_objectSpread(_objectSpread({}, validationStatus), {}, {
          [fieldName]: ""
        }));
        return Promise.resolve();
      } else if (getFieldValue(fieldName).match(namevalid) === null) {
        setValidationStatus(_objectSpread(_objectSpread({}, validationStatus), {}, {
          [fieldName]: "error"
        }));
        return Promise.reject(new Error("only aphabets are allowed"));
      } else if ((value === null || value === void 0 ? void 0 : value.length) !== 0 && ((_getFieldValue3 = getFieldValue(fieldName)) === null || _getFieldValue3 === void 0 ? void 0 : _getFieldValue3.length) !== 0) {
        setValidationStatus(_objectSpread(_objectSpread({}, validationStatus), {}, {
          [fieldName]: "success"
        }));
        return Promise.resolve();
      }
    }

  };
};

exports.returnValidatorForName = returnValidatorForName;