import size from 'lodash/size'

export const isValidName = (value: string) => (/^[A-Za-z .,'-]{0,500}$/.test(value))

export const isValidAddress = (value: string) => (/^[A-Za-z0-9 #!.,'-_]{0,500}$/.test(value))

type fieldsType = {
  address: string,
  city: string,
  country: string,
  name: string,
  state: string,
}

export const validateFields = (fields: fieldsType) => {
  if (!fields.name) return 'error_empty_name'
  if (!fields.country) return 'error_empty_country'
  if (!fields.state && fields.country === 'United States of America') return 'error_empty_state'
  if (size(fields.city) < 3) return 'error_empty_city'
  if (size(fields.address) < 10) return 'error_empty_address'
  return false
}
