// src/utils/emailValidation.ts
var validateEmail = (email) => {
  return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(email);
};

// src/localization/LanguageProvider.tsx
import { createContext, useContext, useEffect, useMemo, useState as useState2 } from "react";

// src/hooks/useLocalStorage.ts
import { useCallback, useState } from "react";

// src/localization/util.ts
var languages = ["en", "de"];
var languagesLocalNames = {
  en: "English",
  de: "Deutsch"
};
var DEFAULT_LANGUAGE = "en";
var LanguageUtil = {
  languages,
  DEFAULT_LANGUAGE,
  languagesLocalNames
};

// src/localization/LanguageProvider.tsx
import { jsx } from "react/jsx-runtime";
var LanguageContext = createContext({
  language: LanguageUtil.DEFAULT_LANGUAGE,
  setLanguage: (v) => v
});
var useLanguage = () => {
  const context = useContext(LanguageContext);
  if (!context) {
    throw new Error("useLanguage must be used within LanguageContext. Try adding a LanguageProvider around your app.");
  }
  return context;
};

// src/localization/useTranslation.ts
var TranslationPluralCount = {
  zero: 0,
  one: 1,
  two: 2,
  few: 3,
  many: 11,
  other: -1
};
var useTranslation = (translations, overwriteTranslation = {}) => {
  const { language: languageProp, translation: overwrite } = overwriteTranslation;
  const { language: inferredLanguage } = useLanguage();
  const usedLanguage = languageProp ?? inferredLanguage;
  const usedTranslations = [...translations];
  if (overwrite) {
    usedTranslations.push(overwrite);
  }
  return (key, options) => {
    const { count, replacements } = { ...{ count: 0, replacements: {} }, ...options };
    try {
      for (let i = translations.length - 1; i >= 0; i--) {
        const translation = translations[i];
        const localizedTranslation = translation[usedLanguage];
        if (!localizedTranslation) {
          continue;
        }
        const value = localizedTranslation[key];
        if (!value) {
          continue;
        }
        let forProcessing;
        if (typeof value !== "string") {
          if (count === TranslationPluralCount.zero && value?.zero) {
            forProcessing = value.zero;
          } else if (count === TranslationPluralCount.one && value?.one) {
            forProcessing = value.one;
          } else if (count === TranslationPluralCount.two && value?.two) {
            forProcessing = value.two;
          } else if (TranslationPluralCount.few <= count && count < TranslationPluralCount.many && value?.few) {
            forProcessing = value.few;
          } else if (count > TranslationPluralCount.many && value?.many) {
            forProcessing = value.many;
          } else {
            forProcessing = value.other;
          }
        } else {
          forProcessing = value;
        }
        forProcessing = forProcessing.replace(/\{\{(\w+)}}/g, (_, placeholder) => {
          return replacements[placeholder] ?? `{{key:${placeholder}}}`;
        });
        return forProcessing;
      }
    } catch (e) {
      console.error(e);
    }
    return `{{${usedLanguage}:${key}}}`;
  };
};

// src/hooks/useValidators.ts
var notEmpty = (value) => {
  if (!value) {
    return "notEmpty";
  }
};
var boundsValidator = (length, bounds) => {
  const [min, max] = bounds;
  if (min !== void 0 && max !== void 0 && (length === void 0 || length < min || length > max)) {
    return "range";
  }
  if (min !== void 0 && (length === void 0 || length < min)) {
    return "lower";
  }
  if (max !== void 0 && length !== void 0 && length > max) {
    return "upper";
  }
  return "none";
};
var lengthValidator = (value, bounds) => {
  const mapping = {
    range: "outOfRangeString",
    lower: "tooShort",
    upper: "tooLong",
    none: void 0
  };
  return mapping[boundsValidator(value?.length, bounds)];
};
var selectionValidator = (value, bounds) => {
  const mapping = {
    range: "outOfRangeSelectionItems",
    lower: "tooFewSelectionItems",
    upper: "tooManySelectionItems",
    none: void 0
  };
  return mapping[boundsValidator(value?.length, bounds)];
};
var emailValidator = (value) => {
  if (!value || !validateEmail(value)) {
    return "invalidEmail";
  }
};
var defaultValidatorTranslation = {
  en: {
    notEmpty: "The field cannot be empty.",
    invalidEmail: "The email is not valid.",
    tooShort: "The value requires at least {{min}} characters.",
    tooLong: "The value requires less than {{max}} characters.",
    outOfRangeString: "The value needs to have between {{min}} and {{max}} characters.",
    outOfRangeNumber: "The value must be between {{min}} and {{max}}.",
    outOfRangeSelectionItems: "Between {{min}} and {{max}} items must be selected.",
    tooFewSelectionItems: "Select at least {{min}} items.",
    tooManySelectionItems: "Select at most {{max}} items."
  },
  de: {
    notEmpty: "Das Feld darf nicht leer sein.",
    invalidEmail: "Die E-Mail ist ung\xFCltig.",
    tooShort: "Der Wert muss mindestens {{min}} Zeichen enthalten.",
    tooLong: "Der Wert darf h\xF6chstens {{max}} Zeichen enthalten.",
    outOfRangeString: "Der Wert muss zwischen {{min}} und {{max}} Zeichen lang sein.",
    outOfRangeNumber: "Der Wert muss zwischen {{min}} und {{max}} liegen.",
    outOfRangeSelectionItems: "Es m\xFCssen zwischen {{min}} und {{max}} Elemente ausgew\xE4hlt werden.",
    tooFewSelectionItems: "Es m\xFCssen mindestens {{min}} Elemente ausgew\xE4hlt werden.",
    tooManySelectionItems: "Es m\xFCssen maximal {{max}} Elemente ausgew\xE4hlt werden."
  }
};
var UseValidators = {
  notEmpty,
  length: lengthValidator,
  email: emailValidator,
  selection: selectionValidator
};
var useTranslatedValidators = () => {
  const translation = useTranslation([defaultValidatorTranslation]);
  return {
    notEmpty: (value) => {
      const result = notEmpty(value);
      if (result) {
        return translation(result);
      }
    },
    length: (value, length) => {
      const [min, max] = length;
      const result = lengthValidator(value, length);
      if (result) {
        return translation(result, { replacements: { min: min.toString(), max: max.toString() } });
      }
    },
    email: (value) => {
      const result = emailValidator(value);
      if (result) {
        return translation(result);
      }
    },
    selection: (value, length) => {
      const [min, max] = length;
      const result = selectionValidator(value, length);
      if (result) {
        return translation(result, { replacements: { min: min.toString(), max: max.toString() } });
      }
    }
  };
};
export {
  UseValidators,
  defaultValidatorTranslation,
  useTranslatedValidators
};
//# sourceMappingURL=useValidators.mjs.map