import CryptoJS from 'crypto-js'

export function encryptPasswordFields(payload, fields, key) {
  const next = { ...payload }
  fields.forEach((field) => {
    if (next[field]) {
      next[field] = CryptoJS.AES.encrypt(next[field], CryptoJS.enc.Utf8.parse(key), {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
      }).toString()
    }
  })
  return next
}
