import { t } from 'i18next';
import { VALID_SLUG_REGEX } from '../../constants/regex.js';
import * as yup from 'yup';

var slugValidator = function slugValidator(label) {
  return yup.string().test({
    name: "slug",
    test: function test(value, ctx) {
      if (!value) {
        return ctx.createError({
          message: t("neetoCommons.validators.isRequired", {
            what: label
          })
        });
      }
      if (VALID_SLUG_REGEX.test(value)) return true;
      if (/[A-Z]/.test(value)) {
        return ctx.createError({
          message: t("neetoCommons.validators.mustNotContainCapitalLetters", {
            what: label
          })
        });
      }
      if (value !== null && value !== void 0 && value.includes(" ")) {
        return ctx.createError({
          message: t("neetoCommons.validators.mustNotContainSpaces", {
            what: label
          })
        });
      }
      if (!/^[a-z0-9-]+$/.test(value)) {
        return ctx.createError({
          message: t("neetoCommons.validators.mustNotContainSpecialCharactersExceptHyphen", {
            what: label
          })
        });
      }
      if (/^[-]|[-]$/.test(value)) {
        return ctx.createError({
          message: t("neetoCommons.validators.mustNotStartOrEndWithSpecialCharacters", {
            what: label
          })
        });
      }
      return true;
    }
  });
};

export { slugValidator };
//# sourceMappingURL=slug.js.map
