import type { AxiosResponse } from 'axios';
import { default as Axios } from 'axios'
import { GlobalConfig, PayloadMessageTypes } from '../common'

import { helpers } from '@vuelidate/validators'
import { tools } from '@tools'
const { withAsync } = helpers

// const SITE_URL = GlobalConfig.uri.site
const VALIDATE_USER_URL = import.meta.env.VITE_MONGODB_HOST + '/email/ck'

export const registeredemail = withAsync(_registeredemail)

export function _registeredemail(email: string) {

  let onSuccess = (res: AxiosResponse) => {
    return res.status !== PayloadMessageTypes.statusfound
  }

  return Axios.post(VALIDATE_USER_URL, { idapp: tools.getEnv('VITE_APP_ID'), email, key: import.meta.env.VITE_PAO_APP_ID })
    .then(onSuccess)
    .catch((err) => {
      return true
    })

}
