import { defineRule, configure } from 'vee-validate'
import AllRules from '@vee-validate/rules'
import AdditionalRules from './additional'
import { localize } from '@vee-validate/i18n'

import en from './locales/validations_en'
import fr from './locales/validations_fr'
import uk from './locales/validations_uk'

const configureSmartValidation = () => {
  configure({
    validateOnBlur: false, // controls if `blur` events should trigger validation with `handleChange` handler
    validateOnChange: false, // controls if `change` events should trigger validation with `handleChange` handler
    validateOnInput: true, // controls if `input` events should trigger validation with `handleChange` handler
    validateOnModelUpdate: true, // controls if `update:modelValue` events should trigger validation with `handleChange` handler
    generateMessage: localize({
      en,
      fr,
      uk
    }),
  })

  Object.keys(AllRules).forEach(rule => {
    defineRule(rule, AllRules[rule])
  })

  Object.keys(AdditionalRules).forEach(rule => {
    defineRule(rule, AdditionalRules[rule])
  })
}

const Validation = {configureSmartValidation}
export {Validation}
