declare var navigator: any

export const hasGoodNetwork = (): boolean => {
  const connection =
    navigator.connection ||
    navigator.mozConnection ||
    navigator.webkitConnection

  if (connection) {
    if (connection.effectiveType) {
      const goodNetworks: string[] = ['3g', '4g']
      return goodNetworks.includes(connection.effectiveType)
    } else {
      const highBandwidth: boolean =
        connection.metered && (connection.bandwidth || 0) > 2
      return highBandwidth
    }
  }

  return true
}
