
import { useI18n } from 'vue-i18n'

export const useInputRules = () => {

  const { t } = useI18n()
  const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z]{2,})+$/

  return {
    inputRules: {
      require: (val: string) => !!val?.trim() || t('input_rules__require'),
      email: (val: string) => EMAIL_REGEX.test(val) || t('input_rules__incorrect_email'),
      password: (val: string) => val.length >= 8 || t('input_rules__password_require'),
      middleText: (val: string) => !val || val.length <= 60 || t('input_rules__middle_text'),
      longText: (val: string) => !val || val.length <= 250 || t('input_rules__long_text'),
      editorText: (val: string) => !val || val.length <= 7800 || t('input_rules__editor_text'),
      editorPlainText: (val: string) => !val || val.length <= 3800 || t('input_rules__editor_text'),
      isEquil: (target: string | undefined, text: string) => (val: string) => val !== target || t(text)
    }
  }
}
